Class: Deltacloud::Instance
- Includes:
- TestPoller
- Defined in:
- lib/deltacloud/api.rb,
lib/deltacloud/models/instance.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#authn_error ⇒ Object
Returns the value of attribute authn_error.
-
#create_image ⇒ Object
Returns the value of attribute create_image.
-
#firewalls ⇒ Object
Returns the value of attribute firewalls.
-
#image_id ⇒ Object
Returns the value of attribute image_id.
-
#instance_profile ⇒ Object
Returns the value of attribute instance_profile.
-
#keyname ⇒ Object
Returns the value of attribute keyname.
-
#launch_time ⇒ Object
Returns the value of attribute launch_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner_id ⇒ Object
Returns the value of attribute owner_id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#private_addresses ⇒ Object
Returns the value of attribute private_addresses.
-
#public_addresses ⇒ Object
Returns the value of attribute public_addresses.
-
#realm_id ⇒ Object
Returns the value of attribute realm_id.
-
#state ⇒ Object
Returns the value of attribute state.
-
#storage_volumes ⇒ Object
Returns the value of attribute storage_volumes.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from BaseModel
Instance Method Summary collapse
- #authn_feature_failed? ⇒ Boolean
- #can_create_image? ⇒ Boolean
- #hardware_profile ⇒ Object
- #hardware_profile=(profile) ⇒ Object
-
#initialize(init = nil) ⇒ Instance
constructor
A new instance of Instance.
- #method_missing(name, *args) ⇒ Object
- #to_hash(context) ⇒ Object
Methods included from TestPoller
Methods inherited from BaseModel
attr_accessor, attributes, #attributes, #id, #to_entity
Constructor Details
#initialize(init = nil) ⇒ Instance
Returns a new instance of Instance.
102 103 104 105 106 107 |
# File 'lib/deltacloud/models/instance.rb', line 102 def initialize(init=nil) super(init) self.actions = [] if self.actions.nil? self.public_addresses = [] if self.public_addresses.nil? self.private_addresses = [] if self.private_addresses.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/deltacloud/models/instance.rb', line 109 def method_missing(name, *args) if name.to_s =~ /is_(\w+)\?/ self.state.downcase.eql?($1) else raise NoMethodError.new(name.to_s) end end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
25 26 27 |
# File 'lib/deltacloud/models/instance.rb', line 25 def actions @actions end |
#authn_error ⇒ Object
Returns the value of attribute authn_error.
31 32 33 |
# File 'lib/deltacloud/models/instance.rb', line 31 def authn_error @authn_error end |
#create_image ⇒ Object
Returns the value of attribute create_image.
34 35 36 |
# File 'lib/deltacloud/models/instance.rb', line 34 def create_image @create_image end |
#firewalls ⇒ Object
Returns the value of attribute firewalls.
35 36 37 |
# File 'lib/deltacloud/models/instance.rb', line 35 def firewalls @firewalls end |
#image_id ⇒ Object
Returns the value of attribute image_id.
21 22 23 |
# File 'lib/deltacloud/models/instance.rb', line 21 def image_id @image_id end |
#instance_profile ⇒ Object
Returns the value of attribute instance_profile.
28 29 30 |
# File 'lib/deltacloud/models/instance.rb', line 28 def instance_profile @instance_profile end |
#keyname ⇒ Object
Returns the value of attribute keyname.
30 31 32 |
# File 'lib/deltacloud/models/instance.rb', line 30 def keyname @keyname end |
#launch_time ⇒ Object
Returns the value of attribute launch_time.
29 30 31 |
# File 'lib/deltacloud/models/instance.rb', line 29 def launch_time @launch_time end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/deltacloud/models/instance.rb', line 22 def name @name end |
#owner_id ⇒ Object
Returns the value of attribute owner_id.
20 21 22 |
# File 'lib/deltacloud/models/instance.rb', line 20 def owner_id @owner_id end |
#password ⇒ Object
Returns the value of attribute password.
33 34 35 |
# File 'lib/deltacloud/models/instance.rb', line 33 def password @password end |
#private_addresses ⇒ Object
Returns the value of attribute private_addresses.
27 28 29 |
# File 'lib/deltacloud/models/instance.rb', line 27 def private_addresses @private_addresses end |
#public_addresses ⇒ Object
Returns the value of attribute public_addresses.
26 27 28 |
# File 'lib/deltacloud/models/instance.rb', line 26 def public_addresses @public_addresses end |
#realm_id ⇒ Object
Returns the value of attribute realm_id.
23 24 25 |
# File 'lib/deltacloud/models/instance.rb', line 23 def realm_id @realm_id end |
#state ⇒ Object
Returns the value of attribute state.
24 25 26 |
# File 'lib/deltacloud/models/instance.rb', line 24 def state @state end |
#storage_volumes ⇒ Object
Returns the value of attribute storage_volumes.
36 37 38 |
# File 'lib/deltacloud/models/instance.rb', line 36 def storage_volumes @storage_volumes end |
#username ⇒ Object
Returns the value of attribute username.
32 33 34 |
# File 'lib/deltacloud/models/instance.rb', line 32 def username @username end |
Instance Method Details
#authn_feature_failed? ⇒ Boolean
117 118 119 |
# File 'lib/deltacloud/models/instance.rb', line 117 def authn_feature_failed? return true unless authn_error.nil? end |
#can_create_image? ⇒ Boolean
90 91 92 |
# File 'lib/deltacloud/models/instance.rb', line 90 def can_create_image? self.create_image end |
#hardware_profile ⇒ Object
94 95 96 |
# File 'lib/deltacloud/models/instance.rb', line 94 def hardware_profile instance_profile end |
#hardware_profile=(profile) ⇒ Object
98 99 100 |
# File 'lib/deltacloud/models/instance.rb', line 98 def hardware_profile=(profile) @instance_profile = profile end |
#to_hash(context) ⇒ Object
38 39 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/deltacloud/models/instance.rb', line 38 def to_hash(context) r = { :id => self.id, :href => context.instance_url(self.id), :name => name, :state => state, :owner => owner_id, :image => { :href => context.image_url(image_id), :id => image_id, :rel => :image }, :realm => { :href => context.realm_url(realm_id), :id => realm_id, :rel => :realm }, :actions => actions.compact.map { |a| { :href => context.send("#{a}_instance_url", self.id), :rel => "#{a}", :method => context.instance_action_method(a) } }, :hardware_profile => { :id => instance_profile.id, :href => context.hardware_profile_url(instance_profile.id), :rel => :hardware_profile, :properties => instance_profile.overrides }, :public_addresses => public_addresses.map { |addr| addr.to_hash(context) }, :private_addresses => private_addresses.map { |addr| addr.to_hash(context) } } if context.driver.respond_to? :run_on_instance r[:actions] << { :href => "#{context.run_instance_url(self.id)};id=#{self.id}", :rel => 'run', :method => 'post'} end if can_create_image? r[:actions] << { :href => "#{context.create_image_url};instance_id=#{self.id}", :rel => 'create_image', :method => 'post'} end r.merge!(:create_time => launch_time) if launch_time r.merge!(:create_image => create_image) if create_image r.merge!(:firewalls => firewalls.map { |f| { :id => f, :href => context.firewall_url(f), :rel => :firewall }}) if firewalls if storage_volumes r.merge!(:storage_volumes => storage_volumes.map { |v| { :id => v.keys.first, :href => context.storage_volume_url(v.keys.first), :rel => :storage_volume }}) end if context.driver.class.has_feature?(:instances, :authentication_key) r.merge!(:authentication_type => 'key' ) r.merge!(:authentication => { :keyname => keyname }) if keyname end if context.driver.class.has_feature?(:instances, :authentication_password) r[:authentication] && username ? r[:authentication].merge!({ :user => username, :password => password }) : (username ? r.merge!(:authentication => { :user => username, :password => password }) : nil) end r end |