Class: Cloud::Appliance::Descriptor::Appliance
- Inherits:
-
Object
- Object
- Cloud::Appliance::Descriptor::Appliance
- Includes:
- Tools::GeneralInit
- Defined in:
- lib/cloud/appliance/descriptor/appliance.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#cpu ⇒ Object
Returns the value of attribute cpu.
-
#description ⇒ Object
Returns the value of attribute description.
-
#disks ⇒ Object
Returns the value of attribute disks.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#os ⇒ Object
Returns the value of attribute os.
-
#title ⇒ Object
Returns the value of attribute title.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #add_attribute(attribute) ⇒ Object
- #add_disk(disk) ⇒ Object
- #add_group(group) ⇒ Object
- #remove_attribute(key) ⇒ Object
- #remove_disk(disk) ⇒ Object
- #remove_group(group) ⇒ Object
- #set_defaults ⇒ Object
- #to_json ⇒ Object
Methods included from Tools::GeneralInit
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def action @action end |
#attributes ⇒ Object
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def attributes @attributes end |
#cpu ⇒ Object
Returns the value of attribute cpu.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def cpu @cpu end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def description @description end |
#disks ⇒ Object
Returns the value of attribute disks.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def disks @disks end |
#groups ⇒ Object
Returns the value of attribute groups.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def groups @groups end |
#identifier ⇒ Object
Returns the value of attribute identifier.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def identifier @identifier end |
#memory ⇒ Object
Returns the value of attribute memory.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def memory @memory end |
#os ⇒ Object
Returns the value of attribute os.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def os @os end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def title @title end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 9 def version @version end |
Class Method Details
.from_hash(hash) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 40 def self.from_hash(hash) hash.each do |key, value| action = key parameters = value os = parameters.delete 'os' disks = parameters.delete 'disks' parameters[:action] = action appliance = Appliance.new parameters if os os = Os.new os appliance.os = os end if disks disks.each do |disk| disk = Disk.new disk appliance.add_disk disk end end return appliance end nil end |
.from_json(string) ⇒ Object
35 36 37 38 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 35 def self.from_json(string) raw = JSON.parse(string) from_hash(raw) end |
Instance Method Details
#add_attribute(attribute) ⇒ Object
76 77 78 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 76 def add_attribute(attribute) attributes.merge! attribute end |
#add_disk(disk) ⇒ Object
72 73 74 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 72 def add_disk(disk) disks << disk end |
#add_group(group) ⇒ Object
68 69 70 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 68 def add_group(group) groups << group end |
#remove_attribute(key) ⇒ Object
88 89 90 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 88 def remove_attribute(key) attributes.delete(key) end |
#remove_disk(disk) ⇒ Object
84 85 86 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 84 def remove_disk(disk) disks.delete(disk) end |
#remove_group(group) ⇒ Object
80 81 82 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 80 def remove_group(group) groups.delete(group) end |
#set_defaults ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 11 def set_defaults @description ||= '' @memory ||= 1024 @cpu ||= 1 @groups ||= [] @os ||= Os.new @disks ||= [] @attributes ||= {} end |
#to_json ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cloud/appliance/descriptor/appliance.rb', line 21 def to_json variables = {} except = [:@action, :@os, :@disks] instance_variables.select { |element| !except.include?(element) }.each do |variable| value = instance_variable_get variable variables[variable.to_s[1..-1]] = value end variables['os'] = os.to_hash variables['disks'] = disks.map(&:to_hash) JSON.pretty_generate(action => variables) end |