Class: Deltacloud::Instance

Inherits:
BaseModel show all
Includes:
TestPoller
Defined in:
lib/deltacloud/api.rb,
lib/deltacloud/models/instance.rb

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#description

Instance Method Summary collapse

Methods included from TestPoller

#wait_for!

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

#actionsObject

Returns the value of attribute actions.



25
26
27
# File 'lib/deltacloud/models/instance.rb', line 25

def actions
  @actions
end

#authn_errorObject

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_imageObject

Returns the value of attribute create_image.



34
35
36
# File 'lib/deltacloud/models/instance.rb', line 34

def create_image
  @create_image
end

#firewallsObject

Returns the value of attribute firewalls.



35
36
37
# File 'lib/deltacloud/models/instance.rb', line 35

def firewalls
  @firewalls
end

#image_idObject

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_profileObject

Returns the value of attribute instance_profile.



28
29
30
# File 'lib/deltacloud/models/instance.rb', line 28

def instance_profile
  @instance_profile
end

#keynameObject

Returns the value of attribute keyname.



30
31
32
# File 'lib/deltacloud/models/instance.rb', line 30

def keyname
  @keyname
end

#launch_timeObject

Returns the value of attribute launch_time.



29
30
31
# File 'lib/deltacloud/models/instance.rb', line 29

def launch_time
  @launch_time
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/deltacloud/models/instance.rb', line 22

def name
  @name
end

#owner_idObject

Returns the value of attribute owner_id.



20
21
22
# File 'lib/deltacloud/models/instance.rb', line 20

def owner_id
  @owner_id
end

#passwordObject

Returns the value of attribute password.



33
34
35
# File 'lib/deltacloud/models/instance.rb', line 33

def password
  @password
end

#private_addressesObject

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_addressesObject

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_idObject

Returns the value of attribute realm_id.



23
24
25
# File 'lib/deltacloud/models/instance.rb', line 23

def realm_id
  @realm_id
end

#stateObject

Returns the value of attribute state.



24
25
26
# File 'lib/deltacloud/models/instance.rb', line 24

def state
  @state
end

#storage_volumesObject

Returns the value of attribute storage_volumes.



36
37
38
# File 'lib/deltacloud/models/instance.rb', line 36

def storage_volumes
  @storage_volumes
end

#usernameObject

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

Returns:

  • (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

Returns:

  • (Boolean)


90
91
92
# File 'lib/deltacloud/models/instance.rb', line 90

def can_create_image?
  self.create_image
end

#hardware_profileObject



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