Class: Nephophobia::Resource::Compute
- Inherits:
-
Object
- Object
- Nephophobia::Resource::Compute
- Defined in:
- lib/nephophobia/resource/compute.rb
Instance Method Summary collapse
-
#all(filter = {}) ⇒ Object
Returns information about instances that @client owns.
-
#allocate_address ⇒ Object
Acquires an elastic IP address.
-
#associate_address(instance_id, floating_ip) ⇒ Object
Associates an elastic IP address with an instance.
-
#create(image_id, params = {}) ⇒ Object
Create a compute instance with the given ‘image_id’.
- #describe_addresses ⇒ Object
-
#destroy(instance_id) ⇒ Object
Removes the given ‘instance_id’.
-
#disassociate_address(floating_ip) ⇒ Object
Disassociates the specified elastic IP address from the instance to which it is assigned.
-
#find(instance_id) ⇒ Object
Returns information about the given ‘instance_id’.
-
#initialize(client) ⇒ Compute
constructor
A new instance of Compute.
-
#reboot(instance_id) ⇒ Object
Reboot the given ‘instance_id’.
-
#release_address(floating_ip) ⇒ Object
Releases an elastic IP address.
-
#start(instance_id) ⇒ Object
Starts the given ‘instance_id’.
-
#stop(instance_id) ⇒ Object
Stops the given ‘instance_id’ Returns instances current and previous state.
-
#vnc_url(instance_id) ⇒ Object
Returns the VNC browser URL.
Constructor Details
#initialize(client) ⇒ Compute
Returns a new instance of Compute.
4 5 6 |
# File 'lib/nephophobia/resource/compute.rb', line 4 def initialize client @client = client end |
Instance Method Details
#all(filter = {}) ⇒ Object
Returns information about instances that @client owns.
filter
: An optional Hash, intended for filtering.
See the API Reference for further details.
{
"Filter.1.Name" => "instance-type",
"Filter.1.Value.1" => "m1.small"
}
18 19 20 21 22 23 24 25 |
# File 'lib/nephophobia/resource/compute.rb', line 18 def all filter = {} response = @client.action "DescribeInstances", filter item = response.body['DescribeInstancesResponse']['reservationSet']['item'] Nephophobia::Util.coerce(item).collect do |data| Response::Compute.new data end end |
#allocate_address ⇒ Object
Acquires an elastic IP address. Returns an elastic IP.
144 145 146 147 148 |
# File 'lib/nephophobia/resource/compute.rb', line 144 def allocate_address response = @client.action "AllocateAddress", {} Response::Address.new response.body['AllocateAddressResponse'] end |
#associate_address(instance_id, floating_ip) ⇒ Object
Associates an elastic IP address with an instance.
instance_id
: A String representing the ID of the instance. floating_ip
: A String representing a floating IP address.
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/nephophobia/resource/compute.rb', line 171 def associate_address instance_id, floating_ip params = { "InstanceId" => instance_id, "PublicIp" => floating_ip } response = @client.action "AssociateAddress", params Response::Address.new response.body['AssociateAddressResponse']['associateResponse'] end |
#create(image_id, params = {}) ⇒ Object
Create a compute instance with the given ‘image_id’. Returns information about the new instance.
image_id
: A String representing the ID of the image. params
: An optional Hash.
See the API Reference for further details.
{
"DisplayName" => "testserver1",
"DisplayDescription" => "test description"
}
39 40 41 42 43 |
# File 'lib/nephophobia/resource/compute.rb', line 39 def create image_id, params = {} response = @client.action "RunInstances", { "ImageId" => image_id }.merge(params) Response::Compute.new response.body['RunInstancesResponse'] end |
#describe_addresses ⇒ Object
199 200 201 202 203 204 205 206 |
# File 'lib/nephophobia/resource/compute.rb', line 199 def describe_addresses response = @client.action "DescribeAddresses", {} item = response.body['DescribeAddressesResponse']['addressesSet']['item'] Nephophobia::Util.coerce(item).collect do |data| Response::Address.new data end end |
#destroy(instance_id) ⇒ Object
Removes the given ‘instance_id’. Returns instances response to a state change.
instance_id
: A String representing the ID of the instance.
51 52 53 54 55 56 57 58 59 |
# File 'lib/nephophobia/resource/compute.rb', line 51 def destroy instance_id params = { "InstanceId.1" => instance_id } response = @client.action "TerminateInstances", params Response::Return.new response.body['TerminateInstancesResponse'] end |
#disassociate_address(floating_ip) ⇒ Object
Disassociates the specified elastic IP address from the instance to which it is assigned.
instance_id
: A String representing the ID of the instance. floating_ip
: A String representing a floating IP address.
189 190 191 192 193 194 195 196 197 |
# File 'lib/nephophobia/resource/compute.rb', line 189 def disassociate_address floating_ip params = { "PublicIp" => floating_ip } response = @client.action "DisassociateAddress", params Response::Address.new response.body['DisassociateAddressResponse']['disassociateResponse'] end |
#find(instance_id) ⇒ Object
Returns information about the given ‘instance_id’.
instance_id
: A String representing the ID of the instance.
66 67 68 69 70 71 72 73 74 |
# File 'lib/nephophobia/resource/compute.rb', line 66 def find instance_id params = { "InstanceId.1" => instance_id } response = @client.action "DescribeInstances", params Response::Compute.new response.body['DescribeInstancesResponse']['reservationSet']['item'] end |
#reboot(instance_id) ⇒ Object
Reboot the given ‘instance_id’. Returns instances response to a state change.
instance_id
: A String representing the ID of the instance.
82 83 84 85 86 87 88 89 90 |
# File 'lib/nephophobia/resource/compute.rb', line 82 def reboot instance_id params = { "InstanceId.1" => instance_id } response = @client.action "RebootInstances", params Response::Return.new response.body['RebootInstancesResponse'] end |
#release_address(floating_ip) ⇒ Object
Releases an elastic IP address.
floating_ip
: A String representing a floating IP address.
155 156 157 158 159 160 161 162 163 |
# File 'lib/nephophobia/resource/compute.rb', line 155 def release_address floating_ip params = { "PublicIp" => floating_ip } response = @client.action "ReleaseAddress", params Response::Address.new response.body['ReleaseAddressResponse']['releaseResponse'] end |
#start(instance_id) ⇒ Object
Starts the given ‘instance_id’. Returns instances current and previous state.
instance_id
: A String representing the ID of the instance.
98 99 100 101 102 103 104 105 106 |
# File 'lib/nephophobia/resource/compute.rb', line 98 def start instance_id params = { "InstanceId.1" => instance_id } response = @client.action "StopInstances", params Response::Return.new response.body end |
#stop(instance_id) ⇒ Object
Stops the given ‘instance_id’ Returns instances current and previous state.
instance_id
: A String representing the ID of the instance.
114 115 116 117 118 119 120 121 122 |
# File 'lib/nephophobia/resource/compute.rb', line 114 def stop instance_id params = { "InstanceId.1" => instance_id } response = @client.action "StartInstances", params Response::Return.new response.body end |
#vnc_url(instance_id) ⇒ Object
Returns the VNC browser URL. Used by the Portal. __Must__ execute as a user with the admin
role.
instance_id
: A String representing the ID of the instance.
130 131 132 133 134 135 136 137 138 |
# File 'lib/nephophobia/resource/compute.rb', line 130 def vnc_url instance_id params = { "InstanceId" => instance_id } response = @client.action "GetVncConsole", params Response::Vnc.new response.body['GetVncConsoleResponse'] end |