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_availability_zones.rb
2010-09-09 17:50:38 -07:00

64 lines
2.3 KiB
Ruby

module Fog
module AWS
class Compute
class Real
require 'fog/aws/parsers/compute/describe_availability_zones'
# Describe all or specified availability zones
#
# ==== Params
# * zone_name<~String> - List of availability zones to describe, defaults to all
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'availabilityZoneInfo'<~Array>:
# * 'regionName'<~String> - Name of region
# * 'zoneName'<~String> - Name of zone
# * 'zoneState'<~String> - State of zone
def describe_availability_zones(zone_name = [])
params = AWS.indexed_param('ZoneName', zone_name)
request({
'Action' => 'DescribeAvailabilityZones',
:idempotent => true,
:parser => Fog::Parsers::AWS::Compute::DescribeAvailabilityZones.new
}.merge!(params))
end
end
class Mock
def describe_availability_zones(zone_name = [])
response = Excon::Response.new
zone_name = [*zone_name]
zones = {
'us-east-1a' => {"zoneName"=>"us-east-1a", "regionName"=>"us-east-1", "zoneState"=>"available"},
'us-east-1b' => {"zoneName"=>"us-east-1b", "regionName"=>"us-east-1", "zoneState"=>"available"},
'us-east-1c' => {"zoneName"=>"us-east-1c", "regionName"=>"us-east-1", "zoneState"=>"available"},
'us-east-1d' => {"zoneName"=>"us-east-1d", "regionName"=>"us-east-1", "zoneState"=>"available"}
}
if zone_name != []
availability_zone_info = zones.reject {|key, value| !zone_name.include?(key)}.values
else
availability_zone_info = zones.values
end
if zone_name.length == 0 || zone_name.length == availability_zone_info.length
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'availabilityZoneInfo' => availability_zone_info
}
response
else
raise Fog::AWS::Compute::Error.new("InvalidParameterValue => Invalid availability zone: #{zone_name.inspect}")
end
end
end
end
end
end