1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/lib/fog/aws/requests/compute/describe_regions.rb
Josh Lane d48d376e9c initial import
* take the liberty of correcting Aws naming
2014-12-31 09:17:51 -08:00

64 lines
2.4 KiB
Ruby

module Fog
module Compute
class Aws
class Real
require 'fog/aws/parsers/compute/describe_regions'
# Describe all or specified regions
#
# ==== Params
# * filters<~Hash> - List of filters to limit results with
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'regionInfo'<~Array>:
# * 'regionName'<~String> - Name of region
# * 'regionEndpoint'<~String> - Service endpoint for region
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AwsEC2/latest/APIReference/ApiReference-query-DescribeRegions.html]
def describe_regions(filters = {})
unless filters.is_a?(Hash)
Fog::Logger.deprecation("describe_regions with #{filters.class} param is deprecated, use describe_regions('region-name' => []) instead [light_black](#{caller.first})[/]")
filters = {'region-name' => [*filters]}
end
params = Fog::AWS.indexed_filters(filters)
request({
'Action' => 'DescribeRegions',
:idempotent => true,
:parser => Fog::Parsers::Compute::AWS::DescribeRegions.new
}.merge!(params))
end
end
class Mock
def describe_regions(filters = {})
unless filters.is_a?(Hash)
Fog::Logger.deprecation("describe_regions with #{filters.class} param is deprecated, use describe_regions('region-name' => []) instead [light_black](#{caller.first})[/]")
filters = {'region-name' => [*filters]}
end
response = Excon::Response.new
region_info = [
{"regionName"=>"eu-west-1", "regionEndpoint"=>"eu-west-1.ec2.amazonaws.com"},
{"regionName"=>"us-east-1", "regionEndpoint"=>"us-east-1.ec2.amazonaws.com"}
]
aliases = {'region-name' => 'regionName', 'endpoint' => 'regionEndpoint'}
for filter_key, filter_value in filters
aliased_key = aliases[filter_key]
region_info = region_info.reject{|region| ![*filter_value].include?(region[aliased_key])}
end
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'regionInfo' => region_info
}
response
end
end
end
end
end