class Deltacloud::Instance

Attributes

actions[RW]
authn_error[RW]
create_image[RW]
firewalls[RW]
image_id[RW]
instance_profile[RW]
keyname[RW]
launch_time[RW]
name[RW]
owner_id[RW]
password[RW]
private_addresses[RW]
public_addresses[RW]
realm_id[RW]
state[RW]
storage_volumes[RW]
username[RW]

Public Class Methods

new(init=nil) click to toggle source
Calls superclass method Deltacloud::BaseModel.new
# 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

Public Instance Methods

authn_feature_failed?() click to toggle source
# File lib/deltacloud/models/instance.rb, line 117
def authn_feature_failed?
  return true unless authn_error.nil?
end
can_create_image?() click to toggle source
# File lib/deltacloud/models/instance.rb, line 90
def can_create_image?
  self.create_image
end
hardware_profile() click to toggle source
# File lib/deltacloud/models/instance.rb, line 94
def hardware_profile
  instance_profile
end
hardware_profile=(profile) click to toggle source
# File lib/deltacloud/models/instance.rb, line 98
def hardware_profile=(profile)
  @instance_profile = profile
end
method_missing(name, *args) click to toggle source
# 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
to_hash(context) click to toggle source
# 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