2010-03-16 18:46:21 -04:00
module Fog
module AWS
2010-09-08 17:40:02 -04:00
class Compute
2010-03-16 18:46:21 -04:00
class Real
2009-08-14 13:35:16 -04:00
2011-01-07 19:52:09 -05:00
require 'fog/compute/parsers/aws/allocate_address'
2010-06-12 18:31:17 -04:00
2009-08-14 13:35:16 -04:00
# Acquire an elastic IP address.
#
# ==== Returns
2009-11-02 21:48:49 -05:00
# * response<~Excon::Response>:
2009-08-14 13:35:16 -04:00
# * body<~Hash>:
# * 'publicIp'<~String> - The acquired address
# * 'requestId'<~String> - Id of the request
def allocate_address
2010-03-16 01:15:33 -04:00
request (
'Action' = > 'AllocateAddress' ,
2010-09-08 17:40:02 -04:00
:parser = > Fog :: Parsers :: AWS :: Compute :: AllocateAddress . new
2010-03-16 01:15:33 -04:00
)
2009-08-14 13:35:16 -04:00
end
2009-07-13 22:14:59 -04:00
end
2010-03-16 18:46:21 -04:00
class Mock
2009-08-14 13:35:16 -04:00
def allocate_address
2009-11-20 14:08:08 -05:00
response = Excon :: Response . new
2010-04-09 13:59:56 -04:00
if describe_addresses . body [ 'addressesSet' ] . size < @data [ :limits ] [ :addresses ]
response . status = 200
public_ip = Fog :: AWS :: Mock . ip_address
data = {
2010-05-05 17:22:22 -04:00
'instanceId' = > nil ,
2010-04-09 13:59:56 -04:00
'publicIp' = > public_ip
}
@data [ :addresses ] [ public_ip ] = data
response . body = {
'publicIp' = > public_ip ,
'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
2009-07-13 22:14:59 -04:00
end
end
end