2010-03-16 18:46:21 -04:00
module Fog
module AWS
2010-09-08 17:40:02 -04:00
class Compute
2010-03-16 18:46:21 -04:00
class Real
2009-08-27 00:31:53 -04:00
2011-01-07 19:52:09 -05:00
require 'fog/compute/parsers/aws/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
2010-10-04 18:46:12 -04:00
def describe_availability_zones ( filters = { } )
unless filters . is_a? ( Hash )
Formatador . display_line ( " [yellow][WARN] describe_availability_zones with #{ filters . class } param is deprecated, use describe_availability_zones('zone-name' => []) instead[/] [light_black]( #{ caller . first } )[/] " )
filters = { 'public-ip' = > [ * filters ] }
end
params = 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 ,
2010-09-08 17:40:02 -04:00
:parser = > Fog :: Parsers :: AWS :: Compute :: 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 )
Formatador . display_line ( " [yellow][WARN] describe_availability_zones with #{ filters . class } param is deprecated, use describe_availability_zones('zone-name' => []) instead[/] [light_black]( #{ caller . first } )[/] " )
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
availability_zone_info = [
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 " } ,
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