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_subnets.rb

65 lines
2.4 KiB
Ruby
Raw Normal View History

2012-03-08 10:45:33 -05:00
module Fog
module Compute
class AWS
class Real
require 'fog/aws/parsers/compute/describe_subnets'
# Describe all or specified subnets
#
# ==== Parameters
# * filters<~Hash> - List of filters to limit results with
#
# === Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'subnetSet'<~Array>:
# * 'subnetId'<~String> - The Subnet's ID
# * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
# * 'vpcId'<~String> - The ID of the VPC the subnet is in
# * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
# * 'availableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any
# stopped instances are considered unavailable)
# * 'availabilityZone'<~String> - The Availability Zone the subnet is in.
# * 'tagSet'<~Array>: Tags assigned to the resource.
# * 'key'<~String> - Tag's key
# * 'value'<~String> - Tag's value
# * 'instanceTenancy'<~String> - The allowed tenancy of instances launched into the Subnet.
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/index.html?ApiReference-query-DescribeSubnets.html]
def describe_subnets(filters = {})
unless filters.is_a?(Hash)
Fog::Logger.warning("describe_subnets with #{filters.class} param is deprecated, use describe_subnets('subnet-id' => []) instead [light_black](#{caller.first})[/]")
filters = {'subnet-id' => [*filters]}
end
params = Fog::AWS.indexed_filters(filters)
request({
'Action' => 'DescribeSubnets',
:idempotent => true,
:parser => Fog::Parsers::Compute::AWS::DescribeSubnets.new
}.merge!(params))
end
end
2012-03-08 10:45:33 -05:00
class Mock
def describe_subnets(filters = {})
subnets = self.data[:subnets]
if filters['subnet-id']
subnets = subnets.reject {|subnet| subnet['subnetId'] != filters['subnet-id']}
2012-03-08 10:45:33 -05:00
end
Excon::Response.new(
:status => 200,
:body => {
'requestId' => Fog::AWS::Mock.request_id,
'subnetSet' => subnets
}
)
2012-03-08 10:45:33 -05:00
end
end
end
end
end