Class: Cloudkeeper::Entities::Appliance

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudkeeper/entities/appliance.rb

Constant Summary collapse

IMAGE_LIST_APPLIANCE_ATTRIBUTES =
%i[dc:identifier ad:mpuri dc:date:expires dc:title dc:description
ad:group hv:ram_minimum hv:core_minimum hv:version sl:arch
ad:base_mpuri ad:appid sl:os sl:osname sl:osversion].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, mpuri, vo, expiration_date, image_list_identifier, title = '', description = '', group = '', ram = 1024, core = 1, version = '', architecture = '', base_mpuri = '', appid = '', digest = '', operating_system = '', image = nil) ⇒ Appliance

Returns a new instance of Appliance.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cloudkeeper/entities/appliance.rb', line 14

def initialize(identifier, mpuri, vo, expiration_date, image_list_identifier, title = '', description = '', group = '',
               ram = 1024, core = 1, version = '', architecture = '', base_mpuri = '', appid = '', digest = '',
               operating_system = '', image = nil)
  if identifier.blank? || \
     mpuri.blank? || \
     vo.blank? || \
     expiration_date.blank? || \
     image_list_identifier.blank?
    raise Cloudkeeper::Errors::ArgumentError, 'identifier, mpuri, vo, expiration_date and image_list_identifier ' \
                                              'cannot be nil nor empty'
  end

  @identifier = identifier
  @description = description
  @mpuri = mpuri
  @title = title
  @group = group
  @ram = ram
  @core = core
  @version = version
  @architecture = architecture
  @operating_system = operating_system
  @image = image
  @vo = vo
  @expiration_date = expiration_date
  @image_list_identifier = image_list_identifier
  @base_mpuri = base_mpuri
  @appid = appid
  @digest = digest
end

Instance Attribute Details

#appidObject

Returns the value of attribute appid.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def appid
  @appid
end

#architectureObject

Returns the value of attribute architecture.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def architecture
  @architecture
end

#base_mpuriObject

Returns the value of attribute base_mpuri.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def base_mpuri
  @base_mpuri
end

#coreObject

Returns the value of attribute core.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def core
  @core
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def description
  @description
end

#digestObject

Returns the value of attribute digest.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def digest
  @digest
end

#expiration_dateObject

Returns the value of attribute expiration_date.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def expiration_date
  @expiration_date
end

#groupObject

Returns the value of attribute group.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def group
  @group
end

#identifierObject

Returns the value of attribute identifier.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def identifier
  @identifier
end

#imageObject

Returns the value of attribute image.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def image
  @image
end

#image_list_identifierObject

Returns the value of attribute image_list_identifier.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def image_list_identifier
  @image_list_identifier
end

#mpuriObject

Returns the value of attribute mpuri.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def mpuri
  @mpuri
end

#operating_systemObject

Returns the value of attribute operating_system.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def operating_system
  @operating_system
end

#ramObject

Returns the value of attribute ram.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def ram
  @ram
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def title
  @title
end

#versionObject

Returns the value of attribute version.



11
12
13
# File 'lib/cloudkeeper/entities/appliance.rb', line 11

def version
  @version
end

#voObject

Returns the value of attribute vo.



12
13
14
# File 'lib/cloudkeeper/entities/appliance.rb', line 12

def vo
  @vo
end

Class Method Details

.compute_digest!(appliance, appliance_hash) ⇒ Object



94
95
96
97
# File 'lib/cloudkeeper/entities/appliance.rb', line 94

def compute_digest!(appliance, appliance_hash)
  digest_hash = appliance_hash.select { |key| IMAGE_LIST_APPLIANCE_ATTRIBUTES.include? key }
  appliance.digest = Digest::SHA512.hexdigest(digest_hash.to_json)
end

.construct_appliance(appliance_hash) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cloudkeeper/entities/appliance.rb', line 71

def construct_appliance(appliance_hash)
  Appliance.new appliance_hash[:'dc:identifier'],
                appliance_hash[:'ad:mpuri'],
                appliance_hash[:vo],
                Cloudkeeper::Utils::Date.parse(appliance_hash[:'dc:date:expires']),
                appliance_hash[:image_list_identifier],
                appliance_hash[:'dc:title'],
                appliance_hash[:'dc:description'],
                appliance_hash[:'ad:group'],
                appliance_hash[:'hv:ram_minimum'],
                appliance_hash[:'hv:core_minimum'],
                appliance_hash[:'hv:version'],
                appliance_hash[:'sl:arch'],
                appliance_hash[:'ad:base_mpuri'],
                appliance_hash[:'ad:appid']
end

.construct_os_name!(appliance, appliance_hash) ⇒ Object



88
89
90
91
92
# File 'lib/cloudkeeper/entities/appliance.rb', line 88

def construct_os_name!(appliance, appliance_hash)
  appliance.operating_system = appliance_hash[:'sl:os'].to_s
  appliance.operating_system = "#{appliance.operating_system} #{appliance_hash[:'sl:osname']}".strip
  appliance.operating_system = "#{appliance.operating_system} #{appliance_hash[:'sl:osversion']}".strip
end

.from_hash(appliance_hash) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/cloudkeeper/entities/appliance.rb', line 50

def from_hash(appliance_hash)
  appliance_hash.deep_symbolize_keys!
  appliance = populate_appliance appliance_hash
  appliance.image = Image.from_hash(appliance_hash)

  appliance
end

.populate_appliance(appliance_hash) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cloudkeeper/entities/appliance.rb', line 58

def populate_appliance(appliance_hash)
  raise Cloudkeeper::Errors::Parsing::InvalidApplianceHashError, 'invalid appliance hash' if appliance_hash.blank?

  appliance = construct_appliance(appliance_hash)
  construct_os_name!(appliance, appliance_hash)
  compute_digest!(appliance, appliance_hash)

  appliance
rescue Cloudkeeper::Errors::ArgumentError => ex
  raise Cloudkeeper::Errors::Parsing::InvalidApplianceHashError, ex, "appliance hash #{appliance_hash.inspect} " \
                                                                     "doesn't contain all the necessary data"
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cloudkeeper/entities/appliance.rb', line 45

def expired?
  expiration_date < Time.now
end