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_availability_zones'
2010-06-12 18:31:17 -04:00
2009-08-27 00:31:53 -04:00
# Describe all or specified availability zones
#
# ==== 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
# * 'availabilityZoneInfo'<~Array>:
# * 'regionName'<~String> - Name of region
# * 'zoneName'<~String> - Name of zone
# * 'zoneState'<~String> - State of zone
2011-05-19 12:31:56 -04:00
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeAvailabilityZones.html]
2010-10-04 18:46:12 -04:00
def describe_availability_zones ( filters = { } )
unless filters . is_a? ( Hash )
2011-10-19 15:49:34 -04:00
Fog :: Logger . deprecation ( " describe_availability_zones with #{ filters . class } param is deprecated, use describe_availability_zones('zone-name' => []) instead [light_black]( #{ caller . first } )[/] " )
2010-10-04 18:46:12 -04:00
filters = { 'public-ip' = > [ * 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' = > 'DescribeAvailabilityZones' ,
:idempotent = > true ,
2011-06-16 19:28:54 -04:00
:parser = > Fog :: Parsers :: Compute :: AWS :: DescribeAvailabilityZones . new
2010-03-16 01:15:33 -04:00
} . merge! ( params ) )
2009-08-27 00:31:53 -04:00
end
2009-07-13 22:14:59 -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_availability_zones ( filters = { } )
unless filters . is_a? ( Hash )
2011-10-19 15:49:34 -04:00
Fog :: Logger . deprecation ( " describe_availability_zones with #{ filters . class } param is deprecated, use describe_availability_zones('zone-name' => []) instead [light_black]( #{ caller . first } )[/] " )
2010-10-04 18:46:12 -04:00
filters = { 'public-ip' = > [ * filters ] }
2009-08-27 00:31:53 -04:00
end
2010-10-04 18:46:12 -04:00
response = Excon :: Response . new
2011-04-26 20:45:05 -04:00
all_zones = [
2010-10-13 20:54:14 -04:00
{ " messageSet " = > [ ] , " regionName " = > " us-east-1 " , " zoneName " = > " us-east-1a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " us-east-1 " , " zoneName " = > " us-east-1b " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " us-east-1 " , " zoneName " = > " us-east-1c " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " us-east-1 " , " zoneName " = > " us-east-1d " , " zoneState " = > " available " } ,
2012-07-02 14:16:18 -04:00
{ " messageSet " = > [ ] , " regionName " = > " us-east-1 " , " zoneName " = > " us-east-1e " , " zoneState " = > " available " } ,
2011-04-26 20:45:05 -04:00
{ " messageSet " = > [ ] , " regionName " = > " us-west-1 " , " zoneName " = > " us-west-1a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " us-west-1 " , " zoneName " = > " us-west-1b " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " us-west-1 " , " zoneName " = > " us-west-1c " , " zoneState " = > " available " } ,
2011-11-09 12:57:48 -05:00
{ " messageSet " = > [ ] , " regionName " = > " us-west-2 " , " zoneName " = > " us-west-2a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " us-west-2 " , " zoneName " = > " us-west-2b " , " zoneState " = > " available " } ,
2011-12-15 07:37:31 -05:00
{ " messageSet " = > [ ] , " regionName " = > " sa-east-1 " , " zoneName " = > " sa-east-1a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " sa-east-1 " , " zoneName " = > " sa-east-1b " , " zoneState " = > " available " } ,
2011-11-09 12:57:48 -05:00
2011-04-26 20:45:05 -04:00
{ " messageSet " = > [ ] , " regionName " = > " eu-west-1 " , " zoneName " = > " eu-west-1a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " eu-west-1 " , " zoneName " = > " eu-west-1b " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " eu-west-1 " , " zoneName " = > " eu-west-1c " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " ap-northeast-1 " , " zoneName " = > " ap-northeast-1a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " ap-northeast-1 " , " zoneName " = > " ap-northeast-1b " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " ap-southeast-1 " , " zoneName " = > " ap-southeast-1a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " ap-southeast-1 " , " zoneName " = > " ap-southeast-1b " , " zoneState " = > " available " } ,
2012-11-13 21:32:07 -05:00
{ " messageSet " = > [ ] , " regionName " = > " ap-southeast-2 " , " zoneName " = > " ap-southeast-2a " , " zoneState " = > " available " } ,
{ " messageSet " = > [ ] , " regionName " = > " ap-southeast-2 " , " zoneName " = > " ap-southeast-2b " , " zoneState " = > " available " } ,
2010-10-04 18:46:12 -04:00
]
2011-04-26 20:45:05 -04:00
availability_zone_info = all_zones . select { | zoneinfo | zoneinfo [ " regionName " ] == @region }
2010-10-04 18:46:12 -04:00
aliases = { 'region-name' = > 'regionName' , 'zone-name' = > 'zoneName' , 'state' = > 'zoneState' }
for filter_key , filter_value in filters
aliased_key = aliases [ filter_key ]
availability_zone_info = availability_zone_info . reject { | availability_zone | ! [ * filter_value ] . include? ( availability_zone [ aliased_key ] ) }
2010-05-24 20:41:01 -04:00
end
2010-10-04 18:46:12 -04:00
response . status = 200
response . body = {
2010-10-13 20:54:14 -04:00
'availabilityZoneInfo' = > availability_zone_info ,
'requestId' = > Fog :: AWS :: Mock . request_id
2010-10-04 18:46:12 -04:00
}
response
2009-08-27 00:31:53 -04:00
end
end
2009-07-13 22:14:59 -04:00
end
end
end