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

67 lines
2.3 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 14:28:57 -04:00
require 'fog/aws/parsers/compute/describe_addresses'
2010-06-12 18:31:17 -04:00
2009-08-14 14:28:57 -04:00
# Describe all or specified IP addresses.
#
# ==== Parameters
# * filters<~Hash> - List of filters to limit results with
2009-08-14 14:28:57 -04:00
#
# ==== 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
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeAddresses.html]
def describe_addresses(filters = {})
unless filters.is_a?(Hash)
Fog::Logger.deprecation("describe_addresses with #{filters.class} param is deprecated, use describe_addresses('public-ip' => []) instead [light_black](#{caller.first})[/]")
filters = {'public-ip' => [*filters]}
end
params = Fog::AWS.indexed_filters(filters)
2009-08-14 14:28:57 -04:00
request({
'Action' => 'DescribeAddresses',
:idempotent => true,
:parser => Fog::Parsers::Compute::AWS::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(filters = {})
unless filters.is_a?(Hash)
Fog::Logger.deprecation("describe_addresses with #{filters.class} param is deprecated, use describe_addresses('public-ip' => []) instead [light_black](#{caller.first})[/]")
filters = {'public-ip' => [*filters]}
2009-08-14 14:28:57 -04:00
end
response = Excon::Response.new
2011-05-19 18:35:33 -04:00
addresses_set = self.data[:addresses].values
aliases = {'public-ip' => 'publicIp', 'instance-id' => 'instanceId'}
for filter_key, filter_value in filters
aliased_key = aliases[filter_key]
addresses_set = addresses_set.reject{|address| ![*filter_value].include?(address[aliased_key])}
2009-08-14 14:28:57 -04:00
end
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'addressesSet' => addresses_set
}
response
2009-08-14 14:28:57 -04:00
end
end
end
end
end