Class: DeltacloudVM::Client::Instance

Inherits:
Base
  • Object
show all
Includes:
Methods::Common, Methods::HardwareProfile, Methods::Image, Methods::Instance, Methods::LoadBalancer, Methods::Realm
Defined in:
lib/deltacloud_vm/client/models/instance.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#description, #name, #obj_id, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Methods::LoadBalancer

#create_load_balancer, #destroy_load_balancer, #load_balancer, #load_balancers

Methods included from Methods::Image

#destroy_image, #images

Methods included from Methods::HardwareProfile

#hardware_profiles

Methods included from Methods::Realm

#realms

Methods included from Methods::Instance

#create_instance, #destroy_instance, #instance, #instances, #reboot_instance, #start_instance, #stop_instance

Methods included from Methods::Common

#create_resource, #destroy_resource

Methods inherited from Base

#client, #connection, convert, #entrypoint, from_collection, #id, #initialize, #original_body, #to_s, #update_instance_variables!, validate_attrs!

Methods included from Helpers::XmlHelper

#extract_xml_body

Methods included from Methods::Api

#api_uri, #current_driver, #current_provider, #feature?, #features, #must_support!, #path, #support?, #supported_collections, #version

Methods included from Helpers::Model

#error, #from_collection, #from_resource, #model

Constructor Details

This class inherits a constructor from DeltacloudVM::Client::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Helper for is_STATE?

is_running? is_stopped?



101
102
103
104
# File 'lib/deltacloud_vm/client/models/instance.rb', line 101

def method_missing(name, *args)
  return self.state.downcase == $1 if name.to_s =~ /^is_(\w+)\?$/
  super
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



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

def actions
  @actions
end

#hardware_profile_idObject (readonly)

Returns the value of attribute hardware_profile_id.



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

def hardware_profile_id
  @hardware_profile_id
end

#image_idObject (readonly)

Returns the value of attribute image_id.



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

def image_id
  @image_id
end

#owner_idObject (readonly)

Returns the value of attribute owner_id.



27
28
29
# File 'lib/deltacloud_vm/client/models/instance.rb', line 27

def owner_id
  @owner_id
end

#private_addressesObject

Returns the value of attribute private_addresses.



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

def private_addresses
  @private_addresses
end

#public_addressesObject

Returns the value of attribute public_addresses.



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

def public_addresses
  @public_addresses
end

#realm_idObject (readonly)

Returns the value of attribute realm_id.



26
27
28
# File 'lib/deltacloud_vm/client/models/instance.rb', line 26

def realm_id
  @realm_id
end

#stateObject

Returns the value of attribute state.



32
33
34
# File 'lib/deltacloud_vm/client/models/instance.rb', line 32

def state
  @state
end

Class Method Details

.parse(xml_body) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/deltacloud_vm/client/models/instance.rb', line 110

def parse(xml_body)
  {
    :state =>               xml_body.text_at('state'),
    :owner_id =>            xml_body.text_at('owner_id'),
    :realm_id =>            xml_body.attr_at('realm', :id),
    :image_id =>            xml_body.attr_at('image', :id),
    :hardware_profile_id => xml_body.attr_at('hardware_profile', :id),
    :public_addresses => InstanceAddress.convert(
      xml_body.xpath('public_addresses/address')
    ),
    :private_addresses => InstanceAddress.convert(
      xml_body.xpath('private_addresses/address')
    ),
    :actions => xml_body.xpath('actions/link').map { |a| a['rel'].to_sym }
  }
end

Instance Method Details

#can_create_image?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/deltacloud_vm/client/models/instance.rb', line 79

def can_create_image?
  actions.include? :create_image
end

#create_image(create_opts = {}) ⇒ Object



83
84
85
86
# File 'lib/deltacloud_vm/client/models/instance.rb', line 83

def create_image(create_opts={})
  return false unless can_create_image?
  super(_id, create_opts)
end

#destroy!Object

Destroy the current Instance



38
39
40
# File 'lib/deltacloud_vm/client/models/instance.rb', line 38

def destroy!
  destroy_instance(_id)
end

#hardware_profileObject



66
67
68
# File 'lib/deltacloud_vm/client/models/instance.rb', line 66

def hardware_profile
  super(hardware_profile_id)
end

#imageObject



70
71
72
# File 'lib/deltacloud_vm/client/models/instance.rb', line 70

def image
  super(image_id)
end

#realmObject

Retrieve the Realm associated with Instance



62
63
64
# File 'lib/deltacloud_vm/client/models/instance.rb', line 62

def realm
  super(realm_id)
end

#reboot!Object

Execute reboot_instance method on current Instance



56
57
58
# File 'lib/deltacloud_vm/client/models/instance.rb', line 56

def reboot!
  reboot_instance(_id) && reload!
end

#register_instance(load_balancer_id) ⇒ Object



88
89
90
# File 'lib/deltacloud_vm/client/models/instance.rb', line 88

def register_instance(load_balancer_id)
  super(load_balancer_id, _id)
end

#reload!Object

Attempt to reload :public_addresses, :private_addresses and :state of the instance, after the instance is modified by calling method



132
133
134
135
136
137
138
139
# File 'lib/deltacloud_vm/client/models/instance.rb', line 132

def reload!
  new_instance = instance(_id)
  update_instance_variables!(
    :public_addresses => new_instance.public_addresses,
    :private_addresses => new_instance.private_addresses,
    :state => new_instance.state
  )
end

#start!Object

Execute start_instance method on current Instance



50
51
52
# File 'lib/deltacloud_vm/client/models/instance.rb', line 50

def start!
  start_instance(_id) && reload!
end

#stop!Object

Execute stop_instance method on current Instance



44
45
46
# File 'lib/deltacloud_vm/client/models/instance.rb', line 44

def stop!
  stop_instance(_id) && reload!
end

#unregister_instance(load_balancer_id) ⇒ Object



92
93
94
# File 'lib/deltacloud_vm/client/models/instance.rb', line 92

def unregister_instance(load_balancer_id)
  super(load_balancer_id, _id)
end