Class: Cloudkeeper::Entities::Appliance
- Inherits:
-
Object
- Object
- Cloudkeeper::Entities::Appliance
- Defined in:
- lib/cloudkeeper/entities/appliance.rb
Constant Summary collapse
- REJECTED_ATTRIBUTES =
%i[vo image_list_identifier].freeze
Instance Attribute Summary collapse
-
#architecture ⇒ Object
Returns the value of attribute architecture.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#core ⇒ Object
Returns the value of attribute core.
-
#description ⇒ Object
Returns the value of attribute description.
-
#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
- .construct_appliance(appliance_hash) ⇒ Object
- .construct_os_name!(appliance, appliance_hash) ⇒ Object
- .from_hash(appliance_hash) ⇒ Object
- .populate_appliance(appliance_hash) ⇒ Object
- .populate_attributes!(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 = '', operating_system = '', image = nil, attributes = {}) ⇒ 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 = '', operating_system = '', image = nil, attributes = {}) ⇒ Appliance
Returns a new instance of Appliance.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 9 def initialize(identifier, mpuri, vo, expiration_date, image_list_identifier, title = '', description = '', group = '', ram = 1024, core = 1, version = '', architecture = '', = '', image = nil, attributes = {}) 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 @attributes = attributes @vo = vo @expiration_date = expiration_date @image_list_identifier = image_list_identifier end |
Instance Attribute Details
#architecture ⇒ Object
Returns the value of attribute architecture.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def architecture @architecture end |
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 5 def attributes @attributes end |
#core ⇒ Object
Returns the value of attribute core.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def core @core end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def description @description end |
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
5 6 7 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 5 def expiration_date @expiration_date end |
#group ⇒ Object
Returns the value of attribute group.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def group @group end |
#identifier ⇒ Object
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def identifier @identifier end |
#image ⇒ Object
Returns the value of attribute image.
5 6 7 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 5 def image @image end |
#image_list_identifier ⇒ Object
Returns the value of attribute image_list_identifier.
5 6 7 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 5 def image_list_identifier @image_list_identifier end |
#mpuri ⇒ Object
Returns the value of attribute mpuri.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def mpuri @mpuri end |
#operating_system ⇒ Object
Returns the value of attribute operating_system.
5 6 7 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 5 def @operating_system end |
#ram ⇒ Object
Returns the value of attribute ram.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def ram @ram end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def title @title end |
#version ⇒ Object
Returns the value of attribute version.
4 5 6 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 4 def version @version end |
#vo ⇒ Object
Returns the value of attribute vo.
5 6 7 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 5 def vo @vo end |
Class Method Details
.construct_appliance(appliance_hash) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 63 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'] end |
.construct_os_name!(appliance, appliance_hash) ⇒ Object
78 79 80 81 82 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 78 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
42 43 44 45 46 47 48 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 42 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
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 50 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) populate_attributes!(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 |
.populate_attributes!(appliance, appliance_hash) ⇒ Object
84 85 86 87 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 84 def populate_attributes!(appliance, appliance_hash) appliance_hash.reject! { |k, _v| REJECTED_ATTRIBUTES.include? k } appliance.attributes = appliance_hash.map { |k, v| [k.to_s, v.to_s] }.to_h end |
Instance Method Details
#expired? ⇒ Boolean
37 38 39 |
# File 'lib/cloudkeeper/entities/appliance.rb', line 37 def expired? expiration_date < Time.now end |