Module: DeltacloudVM::Client::Methods::Instance

Included in:
Connection, Instance, StorageVolume
Defined in:
lib/deltacloud_vm/client/methods/instance.rb

Instance Method Summary collapse

Instance Method Details

#create_instance(image_id, create_opts = {}) ⇒ Object

Create a new instance

  • image_id -> Image to use for instance creation

    (img1, ami-12345, etc...)
    
  • create_opts -> Various options that DC support for the current

    provider.
    

Returns created instance, or list of created instances or all instances.



54
55
56
57
58
59
60
61
# File 'lib/deltacloud_vm/client/methods/instance.rb', line 54

def create_instance(image_id, create_opts={})
  create_opts[:user_data] = Base64::encode64(create_opts[:user_data]) if create_opts[:user_data]
  r = create_resource :instance, create_opts.merge(
    :image_id => image_id,
    :no_convert_model => true
  )
  parse_create_instance(r)
end

#destroy_instance(instance_id) ⇒ Object

Destroy the current Instance Returns ‘true’ if the response was 204 No Content

  • instance_id -> The ‘id’ of the Instance to destroy



68
69
70
# File 'lib/deltacloud_vm/client/methods/instance.rb', line 68

def destroy_instance(instance_id)
  destroy_resource :instance, instance_id
end

#instance(instance_id) ⇒ Object

Retrieve the given instance

  • instance_id -> Instance to retrieve



38
39
40
41
42
43
# File 'lib/deltacloud_vm/client/methods/instance.rb', line 38

def instance(instance_id)
  from_resource(
    :instance,
    connection.get(api_uri("instances/#{instance_id}"))
  )
end

#instances(filter_opts = {}) ⇒ Object

Retrieve list of all instances

  • filter_opts:

    • :id -> Filter instances using their ‘id’

    • :state -> Filter instances by their ‘state’

    • :realm_id -> Filter instances based on their ‘realm_id’



27
28
29
30
31
32
# File 'lib/deltacloud_vm/client/methods/instance.rb', line 27

def instances(filter_opts={})
  from_collection(
    :instances,
    connection.get(api_uri('/instances'), filter_opts)
  )
end

#reboot_instance(instance_id) ⇒ Object

Attempt to reboot the Instance

  • instance_id -> The ‘id’ of the Instance to reboot



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

def reboot_instance(instance_id)
  instance_action :reboot, instance_id
end

#start_instance(instance_id) ⇒ Object

Attempt to change the Instance state to STARTED

  • instance_id -> The ‘id’ of the Instance to start



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

def start_instance(instance_id)
  instance_action :start, instance_id
end

#stop_instance(instance_id) ⇒ Object

Attempt to change the Instance state to STOPPED

  • instance_id -> The ‘id’ of the Instance to stop



76
77
78
# File 'lib/deltacloud_vm/client/methods/instance.rb', line 76

def stop_instance(instance_id)
  instance_action :stop, instance_id
end