Class: Cloudkeeper::Entities::Appliance
- Inherits:
-
Object
- Object
- Cloudkeeper::Entities::Appliance
- 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
-
#appid ⇒ Object
Returns the value of attribute appid.
-
#architecture ⇒ Object
Returns the value of attribute architecture.
-
#base_mpuri ⇒ Object
Returns the value of attribute base_mpuri.
-
#core ⇒ Object
Returns the value of attribute core.
-
#description ⇒ Object
Returns the value of attribute description.
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
-
#group ⇒ Object
Returns the value of attribute group.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#image ⇒ Object
Returns the value of attribute image.
-
#image_list_identifier ⇒ Object
Returns the value of attribute image_list_identifier.
-
#mpuri ⇒ Object
Returns the value of attribute mpuri.
-
#operating_system ⇒ Object
Returns the value of attribute operating_system.
-
#ram ⇒ Object
Returns the value of attribute ram.
-
#title ⇒ Object
Returns the value of attribute title.
-
#version ⇒ Object
Returns the value of attribute version.
-
#vo ⇒ Object
Returns the value of attribute vo.
Class Method Summary collapse
- .compute_digest!(appliance, appliance_hash) ⇒ Object
- .construct_appliance(appliance_hash) ⇒ Object
- .construct_os_name!(appliance, appliance_hash) ⇒ Object
- .from_hash(appliance_hash) ⇒ Object
- .populate_appliance(appliance_hash) ⇒ Object
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#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
constructor
A new instance of Appliance.
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 = '', = '', 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 = @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
#appid ⇒ Object
Returns the value of attribute appid.
12 13 14 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 12 def appid @appid end |
#architecture ⇒ Object
Returns the value of attribute architecture.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def architecture @architecture end |
#base_mpuri ⇒ Object
Returns the value of attribute base_mpuri.
12 13 14 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 12 def base_mpuri @base_mpuri end |
#core ⇒ Object
Returns the value of attribute core.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def core @core end |
#description ⇒ Object
Returns the value of attribute description.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def description @description end |
#digest ⇒ Object
Returns the value of attribute digest.
12 13 14 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 12 def digest @digest end |
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
12 13 14 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 12 def expiration_date @expiration_date end |
#group ⇒ Object
Returns the value of attribute group.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def group @group end |
#identifier ⇒ Object
Returns the value of attribute identifier.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def identifier @identifier end |
#image ⇒ Object
Returns the value of attribute image.
12 13 14 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 12 def image @image end |
#image_list_identifier ⇒ Object
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 |
#mpuri ⇒ Object
Returns the value of attribute mpuri.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def mpuri @mpuri end |
#operating_system ⇒ Object
Returns the value of attribute operating_system.
12 13 14 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 12 def @operating_system end |
#ram ⇒ Object
Returns the value of attribute ram.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def ram @ram end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def title @title end |
#version ⇒ Object
Returns the value of attribute version.
11 12 13 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 11 def version @version end |
#vo ⇒ Object
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. = appliance_hash[:'sl:os'].to_s appliance. = "#{appliance.} #{appliance_hash[:'sl:osname']}".strip appliance. = "#{appliance.} #{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
45 46 47 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 45 def expired? expiration_date < Time.now end |