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/ec2/describe_addresses.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

2010-03-16 18:46:21 -04:00
module Fog
module AWS
module EC2
class Real
2009-08-14 14:28:57 -04:00
# Describe all or specified IP addresses.
#
# ==== Parameters
# * public_ip<~Array> - List of ips to describe, defaults to all
#
# ==== Returns
# * response<~Excon::Response>:
2009-08-14 14:28:57 -04:00
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'addressesSet'<~Array>:
# * 'instanceId'<~String> - instance for ip address
# * 'publicIp'<~String> - ip address for instance
def describe_addresses(public_ip = [])
params = AWS.indexed_param('PublicIp', public_ip)
2009-08-14 14:28:57 -04:00
request({
'Action' => 'DescribeAddresses',
:parser => Fog::Parsers::AWS::EC2::DescribeAddresses.new
}.merge!(params))
2009-08-14 14:28:57 -04:00
end
end
2010-03-16 18:46:21 -04:00
class Mock
2009-08-14 14:28:57 -04:00
def describe_addresses(public_ip = [])
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
public_ip = [*public_ip]
2009-08-14 14:28:57 -04:00
if public_ip != []
2010-03-16 18:46:21 -04:00
addresses_set = @data[:addresses].reject {|key, value| !public_ip.include?(key)}.values
2009-08-14 14:28:57 -04:00
else
2010-03-16 18:46:21 -04:00
addresses_set = @data[:addresses].values
2009-08-14 14:28:57 -04:00
end
if public_ip.length == 0 || public_ip.length == addresses_set.length
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'addressesSet' => addresses_set
}
else
response.status = 400
2009-11-20 14:08:08 -05:00
raise(Excon::Errors.status_error({:expects => 200}, response))
2009-08-14 14:28:57 -04:00
end
response
end
end
end
end
end