1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

describe regions implementation

This commit is contained in:
Wesley Beary 2009-07-23 22:52:17 -07:00
parent 24f0e6c104
commit cb307c1d02
4 changed files with 79 additions and 1 deletions

View file

@ -19,6 +19,7 @@ require "#{parsers_directory}/describe_availability_zones"
require "#{parsers_directory}/describe_images"
require "#{parsers_directory}/describe_instances"
require "#{parsers_directory}/describe_key_pairs"
require "#{parsers_directory}/describe_regions"
require "#{parsers_directory}/describe_security_groups"
require "#{parsers_directory}/describe_snapshots"
require "#{parsers_directory}/describe_volumes"
@ -49,7 +50,7 @@ require "#{requests_directory}/describe_availability_zones"
require "#{requests_directory}/describe_images"
require "#{requests_directory}/describe_instances"
require "#{requests_directory}/describe_key_pairs"
# TODO: require "#{requests_directory}/describe_regions"
require "#{requests_directory}/describe_regions"
# TODO: require "#{requests_directory}/describe_reserved_instances"
# TODO: require "#{requests_directory}/describe_reserved_instances_offerings"
require "#{requests_directory}/describe_security_groups"

View file

@ -0,0 +1,32 @@
module Fog
module Parsers
module AWS
module EC2
class DescribeRegions < Fog::Parsers::Base
def reset
@region = {}
@response = { :region_info => [] }
end
def end_element(name)
case name
when 'item'
@response[:region_info] << @region
@region = {}
when 'regionEndpoint'
@region[:region_endpoint] = @value
when 'regionName'
@region[:region_name] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,26 @@
module Fog
module AWS
class EC2
# Describe all or specified regions
#
# ==== Params
# * region_name<~String> - List of regions to describe, defaults to all
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :request_id<~String> - Id of request
# * :region_info<~Array>:
# * :region_name<~String> - Name of region
# * :region_endpoint<~String> - Service endpoint for region
def describe_regions(region_name = [])
params = indexed_params('RegionName', region_name)
request({
'Action' => 'DescribeRegions'
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeRegions.new)
end
end
end
end

View file

@ -0,0 +1,19 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.describe_availability_zones' do
it "should return proper attributes with no params" do
actual = ec2.describe_regions
zone = actual.body[:region_info].first
zone[:region_endpoint].should be_a(String)
zone[:region_name].should be_a(String)
end
it "should return proper attribute with params" do
actual = ec2.describe_regions(['us-east-1'])
zone = actual.body[:region_info].first
zone[:region_endpoint].should be_a(String)
zone[:region_name].should be_a(String)
end
end