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:
parent
24f0e6c104
commit
cb307c1d02
4 changed files with 79 additions and 1 deletions
|
@ -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"
|
||||
|
|
32
lib/fog/aws/parsers/ec2/describe_regions.rb
Normal file
32
lib/fog/aws/parsers/ec2/describe_regions.rb
Normal 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
|
26
lib/fog/aws/requests/ec2/describe_regions.rb
Normal file
26
lib/fog/aws/requests/ec2/describe_regions.rb
Normal 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
|
19
spec/aws/ec2/describe_regions_spec.rb
Normal file
19
spec/aws/ec2/describe_regions_spec.rb
Normal 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
|
Loading…
Reference in a new issue