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/describe_addresses.rb
2010-09-09 17:50:38 -07:00

56 lines
1.7 KiB
Ruby

module Fog
module AWS
class Compute
class Real
require 'fog/aws/parsers/compute/describe_addresses'
# Describe all or specified IP addresses.
#
# ==== Parameters
# * public_ip<~Array> - List of ips to describe, defaults to all
#
# ==== Returns
# * response<~Excon::Response>:
# * 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)
request({
'Action' => 'DescribeAddresses',
:idempotent => true,
:parser => Fog::Parsers::AWS::Compute::DescribeAddresses.new
}.merge!(params))
end
end
class Mock
def describe_addresses(public_ip = [])
response = Excon::Response.new
public_ip = [*public_ip]
if public_ip != []
addresses_set = @data[:addresses].reject {|key, value| !public_ip.include?(key)}.values
else
addresses_set = @data[:addresses].values
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
}
response
else
raise Fog::AWS::Compute::NotFound.new("Address #{public_ip.inspect} not found.")
end
end
end
end
end
end