lib/nephophobia/compute.rb in nephophobia-0.2.0 vs lib/nephophobia/compute.rb in nephophobia-0.3.0

- old
+ new

@@ -26,17 +26,26 @@ @instance_type = item['instanceType'] end end class VncData - attr_reader :url + attr_reader :attributes, :url def initialize attributes @url = attributes['url'] end end + class AddressData + attr_reader :attributes, :floating_ip, :status + + def initialize attributes + @floating_ip = attributes['publicIp'] + @status = attributes['item'] + end + end + class Compute def initialize client @client = client end @@ -156,11 +165,11 @@ ResponseData.new response.body end ## # Returns the VNC browser URL. Used by the Portal. - # __Must__ have an +admin+ role to use. + # __Must__ execute as a user with the +admin+ role. # # +instance_id+: A String representing the ID of the instance. def vnc_url instance_id params = { @@ -168,8 +177,67 @@ } response = @client.action "GetVncConsole", params VncData.new response.body['GetVncConsoleResponse'] + end + + ## + # Acquires an elastic IP address. + # Returns an elastic IP. + + def allocate_address + response = @client.action "AllocateAddress", {} + + AddressData.new response.body['AllocateAddressResponse'] + end + + ## + # Releases an elastic IP address. + # + # +floating_ip+: A String representing a floating IP address. + + def release_address floating_ip + params = { + "PublicIp" => floating_ip + } + + response = @client.action "ReleaseAddress", params + + AddressData.new response.body['ReleaseAddressResponse']['releaseResponse'] + end + + ## + # 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. + + def associate_address instance_id, floating_ip + params = { + "InstanceId" => instance_id, + "PublicIp" => floating_ip + } + + response = @client.action "AssociateAddress", params + + AddressData.new response.body['AssociateAddressResponse']['associateResponse'] + end + + ## + # 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. + + def disassociate_address floating_ip + params = { + "PublicIp" => floating_ip + } + + response = @client.action "DisassociateAddress", params + + AddressData.new response.body['DisassociateAddressResponse']['disassociateResponse'] end end end