From 2ee5bf3f2396d9ea48d7ebd0f766733e645bc48b Mon Sep 17 00:00:00 2001 From: Eric Stonfer Date: Mon, 13 Feb 2012 21:14:15 -0500 Subject: [PATCH] make eips useable in a VPC --- lib/fog/aws/models/compute/address.rb | 3 ++- lib/fog/aws/parsers/compute/allocate_address.rb | 2 +- lib/fog/aws/parsers/compute/describe_addresses.rb | 2 +- lib/fog/aws/requests/compute/allocate_address.rb | 9 +++++++-- tests/aws/requests/compute/address_tests.rb | 8 +++++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/fog/aws/models/compute/address.rb b/lib/fog/aws/models/compute/address.rb index 37e1d812cb..8cd2e9619b 100644 --- a/lib/fog/aws/models/compute/address.rb +++ b/lib/fog/aws/models/compute/address.rb @@ -9,6 +9,7 @@ class Address < Fog::Model identity :public_ip, :aliases => 'publicIp' attribute :server_id, :aliases => 'instanceId' + attribute :domain def initialize(attributes = {}) # assign server first to prevent race condition with new_record? @@ -33,7 +34,7 @@ def server=(new_server) def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity - data = connection.allocate_address.body + data = connection.allocate_address(domain).body new_attributes = data.reject {|key,value| key == 'requestId'} merge_attributes(new_attributes) if @server diff --git a/lib/fog/aws/parsers/compute/allocate_address.rb b/lib/fog/aws/parsers/compute/allocate_address.rb index 94c8299811..af690d6ff4 100644 --- a/lib/fog/aws/parsers/compute/allocate_address.rb +++ b/lib/fog/aws/parsers/compute/allocate_address.rb @@ -7,7 +7,7 @@ class AllocateAddress < Fog::Parsers::Base def end_element(name) case name - when 'publicIp', 'requestId' + when 'publicIp', 'requestId', 'domain', 'allocationId' @response[name] = value end end diff --git a/lib/fog/aws/parsers/compute/describe_addresses.rb b/lib/fog/aws/parsers/compute/describe_addresses.rb index b1412ce794..b28ea8e5e2 100644 --- a/lib/fog/aws/parsers/compute/describe_addresses.rb +++ b/lib/fog/aws/parsers/compute/describe_addresses.rb @@ -12,7 +12,7 @@ def reset def end_element(name) case name - when 'instanceId', 'publicIp' + when 'instanceId', 'publicIp', 'domain', 'allocationId' @address[name] = value when 'item' @response['addressesSet'] << @address diff --git a/lib/fog/aws/requests/compute/allocate_address.rb b/lib/fog/aws/requests/compute/allocate_address.rb index c45db22e2c..f472816bb4 100644 --- a/lib/fog/aws/requests/compute/allocate_address.rb +++ b/lib/fog/aws/requests/compute/allocate_address.rb @@ -7,6 +7,8 @@ class Real # Acquire an elastic IP address. # + # ==== Parameters + # * domain<~String> - Type of EIP, either standard or vpc # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: @@ -14,9 +16,11 @@ class Real # * 'requestId'<~String> - Id of the request # # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AllocateAddress.html] - def allocate_address + def allocate_address(domain='standard') + domain = domain == 'vpc' ? 'vpc' : 'standard' request( 'Action' => 'AllocateAddress', + 'Domain' => domain, :parser => Fog::Parsers::Compute::AWS::AllocateAddress.new ) end @@ -25,7 +29,7 @@ def allocate_address class Mock - def allocate_address + def allocate_address(domain = 'standard') response = Excon::Response.new if describe_addresses.body['addressesSet'].size < self.data[:limits][:addresses] response.status = 200 @@ -36,6 +40,7 @@ def allocate_address } self.data[:addresses][public_ip] = data response.body = { + 'domain' => standard, 'publicIp' => public_ip, 'requestId' => Fog::AWS::Mock.request_id } diff --git a/tests/aws/requests/compute/address_tests.rb b/tests/aws/requests/compute/address_tests.rb index f180cd01ff..65bbe7902c 100644 --- a/tests/aws/requests/compute/address_tests.rb +++ b/tests/aws/requests/compute/address_tests.rb @@ -2,8 +2,10 @@ @addresses_format = { 'addressesSet' => [{ - 'instanceId' => NilClass, - 'publicIp' => String + 'allocationId' => Fog::Nullable::String, + 'domain' => String, + 'instanceId' => Fog::Nullable::String, + 'publicIp' => String }], 'requestId' => String } @@ -16,7 +18,7 @@ @public_ip = nil - tests('#allocate_address').formats({'publicIp' => String, 'requestId' => String}) do + tests('#allocate_address').formats({'domain' => String, 'publicIp' => String, 'requestId' => String}) do data = Fog::Compute[:aws].allocate_address.body @public_ip = data['publicIp'] data