1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/requests/compute/allocate_address.rb

60 lines
2.1 KiB
Ruby
Raw Normal View History

2010-03-16 18:46:21 -04:00
module Fog
module Compute
class AWS
2010-03-16 18:46:21 -04:00
class Real
2009-08-14 13:35:16 -04:00
require 'fog/aws/parsers/compute/allocate_address'
2010-06-12 18:31:17 -04:00
2009-08-14 13:35:16 -04:00
# Acquire an elastic IP address.
#
2012-02-13 21:14:15 -05:00
# ==== Parameters
# * domain<~String> - Type of EIP, either standard or vpc
2009-08-14 13:35:16 -04:00
# ==== Returns
# * response<~Excon::Response>:
2009-08-14 13:35:16 -04:00
# * 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]
2012-02-13 21:14:15 -05:00
def allocate_address(domain='standard')
domain = domain == 'vpc' ? 'vpc' : 'standard'
request(
'Action' => 'AllocateAddress',
2012-02-13 21:14:15 -05:00
'Domain' => domain,
:parser => Fog::Parsers::Compute::AWS::AllocateAddress.new
)
2009-08-14 13:35:16 -04:00
end
end
2010-03-16 18:46:21 -04:00
class Mock
2009-08-14 13:35:16 -04:00
2012-02-13 21:14:15 -05:00
def allocate_address(domain = 'standard')
domain = domain == 'vpc' ? 'vpc' : 'standard'
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
2011-05-19 18:35:33 -04:00
if describe_addresses.body['addressesSet'].size < self.data[:limits][:addresses]
response.status = 200
public_ip = Fog::AWS::Mock.ip_address
data = {
'instanceId' => nil,
'publicIp' => public_ip,
'domain' => domain
}
if domain == 'vpc'
data['allocationId'] = "eipalloc-#{Fog::Mock.random_hex(8)}"
end
2011-05-19 18:35:33 -04:00
self.data[:addresses][public_ip] = data
response.body = data.reject {|k, v| k == 'instanceId' }.merge('requestId' => Fog::AWS::Mock.request_id)
response
else
response.status = 400
response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>AddressLimitExceeded</Code><Message>Too many addresses allocated</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestID></Response>"
raise(Excon::Errors.status_error({:expects => 200}, response))
end
2009-08-14 13:35:16 -04:00
end
end
end
end
end