Skip to content

Commit

Permalink
make eips useable in a VPC
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Stonfer committed Feb 14, 2012
1 parent ffbb2b0 commit 2ee5bf3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/fog/aws/models/compute/address.rb
Expand Up @@ -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?
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/compute/allocate_address.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/compute/describe_addresses.rb
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/fog/aws/requests/compute/allocate_address.rb
Expand Up @@ -7,16 +7,20 @@ class Real

# Acquire an elastic IP address.
#
# ==== Parameters
# * domain<~String> - Type of EIP, either standard or vpc
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'publicIp'<~String> - The acquired address
# * '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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions tests/aws/requests/compute/address_tests.rb
Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 2ee5bf3

Please sign in to comment.