2010-03-16 18:46:21 -04:00
module Fog
2011-06-16 19:28:54 -04:00
module Compute
class AWS
2010-03-16 18:46:21 -04:00
class Real
2009-08-27 00:31:53 -04:00
2011-08-24 21:37:00 -04:00
require 'fog/aws/parsers/compute/describe_regions'
2010-06-12 18:31:17 -04:00
2009-08-27 00:31:53 -04:00
# Describe all or specified regions
#
# ==== Params
2010-10-04 18:46:12 -04:00
# * filters<~Hash> - List of filters to limit results with
2009-08-27 00:31:53 -04:00
#
# ==== Returns
2009-11-02 21:48:49 -05:00
# * response<~Excon::Response>:
2009-08-27 00:31:53 -04:00
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'regionInfo'<~Array>:
# * 'regionName'<~String> - Name of region
# * 'regionEndpoint'<~String> - Service endpoint for region
2011-05-19 12:31:56 -04:00
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeRegions.html]
2010-10-04 18:46:12 -04:00
def describe_regions ( filters = { } )
unless filters . is_a? ( Hash )
2011-10-19 15:49:34 -04:00
Fog :: Logger . deprecation ( " describe_regions with #{ filters . class } param is deprecated, use describe_regions('region-name' => []) instead [light_black]( #{ caller . first } )[/] " )
2010-10-04 18:46:12 -04:00
filters = { 'region-name' = > [ * filters ] }
end
2011-06-20 16:49:37 -04:00
params = Fog :: AWS . indexed_filters ( filters )
2009-08-27 00:31:53 -04:00
request ( {
2010-05-24 17:22:35 -04:00
'Action' = > 'DescribeRegions' ,
:idempotent = > true ,
2011-06-16 19:28:54 -04:00
:parser = > Fog :: Parsers :: Compute :: AWS :: DescribeRegions . new
2010-03-16 01:15:33 -04:00
} . merge! ( params ) )
2009-08-27 00:31:53 -04:00
end
2009-07-24 01:52:17 -04:00
end
2009-08-27 00:31:53 -04:00
2010-03-16 18:46:21 -04:00
class Mock
2009-08-27 00:31:53 -04:00
2010-10-04 18:46:12 -04:00
def describe_regions ( filters = { } )
unless filters . is_a? ( Hash )
2011-10-19 15:49:34 -04:00
Fog :: Logger . deprecation ( " describe_regions with #{ filters . class } param is deprecated, use describe_regions('region-name' => []) instead [light_black]( #{ caller . first } )[/] " )
2010-10-04 18:46:12 -04:00
filters = { 'region-name' = > [ * filters ] }
2009-08-27 00:31:53 -04:00
end
2010-10-04 18:46:12 -04:00
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 ] ) }
2010-05-24 20:41:01 -04:00
end
2010-10-04 18:46:12 -04:00
response . status = 200
response . body = {
'requestId' = > Fog :: AWS :: Mock . request_id ,
'regionInfo' = > region_info
}
response
2009-08-27 00:31:53 -04:00
end
end
2009-07-24 01:52:17 -04:00
end
end
end