deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 2/3] EC2: list subnets as realms
Date Tue, 28 Aug 2012 23:35:34 GMT
From: David Lutterkort <lutter@redhat.com>

Subnets (from VPC's) are listed as realms.

Note that this patch monkey patches the aws gem; the corresponding patch
has been sent upstream, it is included here to make testing the patch easier.
---
 .../deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb |  294 ++++++++++++++++++++
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |   29 ++-
 server/tests/drivers/ec2/common.rb                 |   30 ++
 .../drivers/ec2/fixtures/create_resources.yml      |   79 ++++++
 .../drivers/ec2/fixtures/destroy_resources.yml     |   67 +++++
 .../test_0002_must_return_list_of_realms.yml       |   92 ++++++-
 .../test_0005_must_list_VPC_subnets_as_realms.yml  |  109 ++++++++
 server/tests/drivers/ec2/realms_test.rb            |    5 +
 8 files changed, 696 insertions(+), 9 deletions(-)
 create mode 100644 server/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb
 create mode 100644 server/tests/drivers/ec2/fixtures/create_resources.yml
 create mode 100644 server/tests/drivers/ec2/fixtures/destroy_resources.yml
 create mode 100644 server/tests/drivers/ec2/fixtures/test_0005_must_list_VPC_subnets_as_realms.yml

diff --git a/server/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb b/server/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb
new file mode 100644
index 0000000..3f1d491
--- /dev/null
+++ b/server/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb
@@ -0,0 +1,294 @@
+# This is a copy of code that has been submitted upstream
+# https://github.com/appoxy/aws/pull/116
+#
+# If you make changes here, make sure they go upstream, too
+
+unless Aws::Ec2::method_defined?(:create_vpc)
+  class Aws::Ec2
+    #-----------------------------------------------------------------
+    #      VPC related
+    #-----------------------------------------------------------------
+
+    # Create VPC
+    # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVpc.html
+    #
+    # ec2.create_vpc("10.0.0.0/16")
+    # FIXME: EVen though the EC2 docs describe the parameter instanceTenancy,
+    # I could not get it to recognize that
+    def create_vpc(cidr_block = "10.0.0.0/16")
+      params = { "CidrBlock" => cidr_block }
+      link = generate_request("CreateVpc", params)
+      request_info(link, QEc2VpcsParser.new("vpc", :logger => @logger))
+    rescue Exception
+      on_exception
+    end
+
+
+    # Describe  VPC's
+    # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVpcs.html
+    #
+    # ec2.describe_vpcs
+    # ec2.describe_vpcs(vpcId1, vpcId2, 'Filter.1.Name' => 'state', 'Filter.1.Value' =
> 'pending', ...)
+    def describe_vpcs(*args)
+      if args.last.is_a?(Hash)
+        params = args.pop.dup
+      else
+        params = {}
+      end
+      1.upto(args.size) { |i| params["VpcId.#{i}"] = args[i-1] }
+      link = generate_request("DescribeVpcs", params)
+      request_info(link, QEc2VpcsParser.new("item", :logger => @logger))
+    rescue Exception
+      on_exception
+    end
+
+    # Delete VPC
+    # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteVpc.html
+    #
+    # ec2.delete_vpc(vpc_id)
+    def delete_vpc(vpc_id)
+      params = { "VpcId" => vpc_id }
+      link = generate_request("DeleteVpc", params)
+      request_info(link, RightBoolResponseParser.new(:logger => @logger))
+    rescue Exception
+      on_exception
+    end
+
+    # Create subnet in a VPC
+    # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSubnet.html
+    #
+    # ec2.create_subnet(vpc_id, cidr_block)
+    # ec2.create_subnet(vpc_id, cidr_block, availability_zone))
+    def create_subnet(vpc_id, cidr_block, availability_zone = nil)
+      params = { "VpcId" => vpc_id, "CidrBlock" => cidr_block }
+      params["AvailabilityZone"] = availability_zone if availability_zone
+      link = generate_request("CreateSubnet", params)
+      request_info(link, QEc2SubnetsParser.new("subnet", :logger => @logger))
+    rescue Exception
+      on_exception
+    end
+
+    # Describe subnets
+    # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html
+    #
+    # ec2.describe_subnets
+    # ecs.describe_subnets(subnetId1, SubnetId2, ...,
+    #                      'Filter.1.Name' => 'state',
+    #                      'Filter.1.Value.1' => 'pending',
+    #                      'Filter.2.Name' => ...)
+    def describe_subnets(*args)
+      if args.last.is_a?(Hash)
+        params = args.pop.dup
+      else
+        params = {}
+      end
+      1.upto(args.size) { |i| params["SubnetId.#{i}"] = args[i-1] }
+      link = generate_request("DescribeSubnets", params)
+      request_info(link, QEc2SubnetsParser.new("item", :logger => @logger))
+    rescue Exception
+      on_exception
+    end
+
+    # Delete Subnet
+    # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteSubnet.html
+    #
+    # ec2.delete_subnet(subnet_id)
+    def delete_subnet(subnet_id)
+      params = { "SubnetId" => subnet_id }
+      link = generate_request("DeleteSubnet", params)
+      request_info(link, RightBoolResponseParser.new(:logger => @logger))
+    rescue Exception
+      on_exception
+    end
+
+    # The only change in this class compared to upstream is
+    # that we parse out subnetId and vpcId
+    class QEc2DescribeInstancesParser < Aws::AwsParser #:nodoc:
+      def tagstart(name, attributes)
+        # DescribeInstances property
+        if (name == 'item' && @xmlpath == 'DescribeInstancesResponse/reservationSet')
||
+            # RunInstances property
+        (name == 'RunInstancesResponse')
+          @reservation = {:aws_groups    => [],
+                          :instances_set => []}
+
+        elsif (name == 'item') &&
+            # DescribeInstances property
+        (@xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet' ||
+            # RunInstances property
+        @xmlpath=='RunInstancesResponse/instancesSet')
+          # the optional params (sometimes are missing and we dont want them to be nil)
+          @instance = {:aws_reason        => '',
+                       :dns_name          => '',
+                       :private_dns_name  => '',
+                       :ami_launch_index  => '',
+                       :ssh_key_name      => '',
+                       :aws_state         => '',
+                       :root_device_type  => '',
+                       :root_device_name  => '',
+                       :architecture      => '',
+                       :subnet_id         => '',
+                       :vpc_id            => '',
+                       :block_device_mappings => [],
+                       :aws_product_codes => [],
+                       :tags              => {}}
+        end
+      end
+
+      def tagend(name)
+        case name
+          when  'rootDeviceType' then
+            @instance[:root_device_type] = @text
+          when 'architecture' then
+            @instance[:architecture] = @text
+          when 'rootDeviceName' then
+            @instance[:root_device_name] = @text
+          # reservation
+          when 'reservationId' then
+            @reservation[:aws_reservation_id] = @text
+          when 'ownerId' then
+            @reservation[:aws_owner] = @text
+          when 'groupId' then
+            @reservation[:aws_groups] << @text
+          # instance
+          when 'instanceId' then
+            @instance[:aws_instance_id] = @text
+          when 'imageId' then
+            @instance[:aws_image_id] = @text
+          when 'dnsName' then
+            @instance[:dns_name] = @text
+          when 'privateDnsName' then
+            @instance[:private_dns_name] = @text
+          when 'reason' then
+            @instance[:aws_reason] = @text
+          when 'keyName' then
+            @instance[:ssh_key_name] = @text
+          when 'amiLaunchIndex' then
+            @instance[:ami_launch_index] = @text
+          when 'code' then
+            @instance[:aws_state_code] = @text
+          when 'name' then
+            @instance[:aws_state] = @text
+          when 'productCode' then
+            @instance[:aws_product_codes] << @text
+          when 'instanceType' then
+            @instance[:aws_instance_type] = @text
+          when 'launchTime' then
+            @instance[:aws_launch_time] = @text
+          when 'kernelId' then
+            @instance[:aws_kernel_id] = @text
+          when 'ramdiskId' then
+            @instance[:aws_ramdisk_id] = @text
+          when 'platform' then
+            @instance[:aws_platform] = @text
+          when 'availabilityZone' then
+            @instance[:aws_availability_zone] = @text
+          when 'privateIpAddress' then
+            @instance[:aws_private_ip_address] = @text
+          when 'subnetId' then
+            @instance[:subnet_id] = @text
+          when 'vpcId' then
+            @instance[:vpc_id] = @text
+          when 'key' then
+            @tag_key = @text
+          when 'value' then
+            @tag_value = @text
+          when 'deviceName' then
+            @device_name = @text
+          when 'volumeId' then
+            @volume_id = @text
+          when 'state'
+            if @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet/item/monitoring'
|| # DescribeInstances property
+            @xmlpath == 'RunInstancesResponse/instancesSet/item/monitoring' # RunInstances
property
+              @instance[:monitoring_state] = @text
+            end
+          when 'item'
+            if @xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet/item/tagSet'
# Tags
+              @instance[:tags][@tag_key] = @tag_value
+            elsif @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet/item/blockDeviceMapping'
# Block device mappings
+              @instance[:block_device_mappings] << { @device_name => @volume_id
}
+            elsif @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet'
|| # DescribeInstances property
+            @xmlpath == 'RunInstancesResponse/instancesSet' # RunInstances property
+              @reservation[:instances_set] << @instance
+            elsif @xmlpath=='DescribeInstancesResponse/reservationSet' # DescribeInstances
property
+              @result << @reservation
+            end
+          when 'RunInstancesResponse' then
+            @result << @reservation # RunInstances property
+        end
+      end
+
+      def reset
+        @result = []
+      end
+    end
+
+    #-----------------------------------------------------------------
+    #      PARSERS: Vpc
+    #-----------------------------------------------------------------
+
+    class QEc2VpcsParser < Aws::AwsParser #:nodoc:
+      def initialize(wrapper, opts = {})
+        super(opts)
+        @wrapper = wrapper
+      end
+
+      def tagstart(name, attribute)
+        @vpc = {} if name == @wrapper
+      end
+
+      def tagend(name)
+        case name
+        when 'vpcId' then
+          @vpc[:vpc_id] = @text
+        when 'state' then
+          @vpc[:state] = @text
+        when 'cidrBlock' then
+          @vpc[:cidr_block] = @text
+        when 'dhcpOptionsId' then
+          @vpc[:dhcp_options_id] = @text
+        when @wrapper
+          @result << @vpc
+        end
+      end
+
+      def reset
+        @result = []
+      end
+    end
+
+    class QEc2SubnetsParser < Aws::AwsParser #:nodoc
+      def initialize(wrapper, opts = {})
+        super(opts)
+        @wrapper = wrapper
+      end
+
+      def tagstart(name, attribute)
+        @subnet = {} if name == @wrapper
+      end
+
+      def tagend(name)
+        case name
+        when 'subnetId' then
+          @subnet[:subnet_id] = @text
+        when 'state' then
+          @subnet[:state] = @text
+        when 'vpcId' then
+          @subnet[:vpc_id] = @text
+        when 'cidrBlock' then
+          @subnet[:cidr_block] = @text
+        when 'availableIpAddressCount' then
+          @subnet[:available_ip_address_count] = @text
+        when 'availabilityZone' then
+          @subnet[:availability_zone] = @text
+        when @wrapper
+          @result << @subnet
+        end
+      end
+
+      def reset
+        @result = []
+      end
+    end
+  end
+end
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 8847034..31fcfa5 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -15,6 +15,8 @@
 #
 
 require 'aws'
+# Delete this once VPC support is merged upstream
+require_relative 'aws_vpc_monkey_patch'
 
 require_relative '../../runner'
 
@@ -164,22 +166,35 @@ module Deltacloud
         end
 
         def realms(credentials, opts={})
+          # We have two different kinds of realms:
+          #  (1) Availability Zones
+          #  (2) Subnets in VPC's (scoped to an AZ)
+          # For the latter, the ID is AZ:SUBNET, and we can tell that we
+          # are looking at such a realm by checking if the id contains a colon
           ec2 = new_client(credentials)
           realms = []
           safely do
             if opts[:id] and !opts[:id].empty?
+              az, sn = opts[:id].split(":")
               begin
-                ec2.describe_availability_zones([opts[:id]]).collect do |realm|
-                  realms << convert_realm(realm) unless realm.empty?
+                if sn
+                  subnet = ec2.describe_subnets(sn).first
+                  realms << convert_realm(subnet) if subnet
+                else
+                  ec2.describe_availability_zones(az).collect do |realm|
+                    realms << convert_realm(realm) unless realm.empty?
+                  end
                 end
               rescue => e
                 raise e unless e.message =~ /Invalid availability zone/
                 realms = []
               end
             else
-              ec2.describe_availability_zones.collect do |realm|
-                realms << convert_realm(realm) unless realm.empty?
+              realms = ec2.describe_availability_zones.collect do |realm|
+                convert_realm(realm) unless realm.empty?
               end
+              realms = realms +
+                ec2.describe_subnets.map { |sn| convert_realm(sn) }
             end
           end
           realms
@@ -871,6 +886,12 @@ module Deltacloud
         end
 
         def convert_realm(realm)
+          # We also allow subnets as realms
+          if realm[:subnet_id]
+            realm[:zone_name] =
+              "#{realm[:availability_zone]}:#{realm[:subnet_id]}"
+            realm[:zone_state] = realm[:state]
+          end
           Realm.new(
             :id => realm[:zone_name],
             :name => realm[:zone_name],
diff --git a/server/tests/drivers/ec2/common.rb b/server/tests/drivers/ec2/common.rb
index fa34237..7d63dc9 100644
--- a/server/tests/drivers/ec2/common.rb
+++ b/server/tests/drivers/ec2/common.rb
@@ -4,11 +4,20 @@ require 'right_http_connection'
 require 'vcr'
 
 require_relative '../../test_helper.rb'
+require_relative '../../../lib/deltacloud/drivers/ec2/ec2_driver'
 
 def credentials
   Deltacloud::Test::config.credentials('ec2')
 end
 
+# Monkey patch EC2 driver to return a client
+class Deltacloud::Drivers::Ec2::Ec2Driver
+  def client(credentials)
+    new_client(credentials)
+  end
+end
+
+# Configure VCR
 VCR.configure do |c|
   # NOTE: Empty this directory before re-recording
   c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
@@ -18,3 +27,24 @@ VCR.configure do |c|
   c.register_request_matcher(:ec2_matcher, &matcher)
   c.default_cassette_options = { :record => :none, :match_requests_on => [:method,
:ec2_matcher] }
 end
+
+# Setup resources we need for the tests
+def create_resources
+  VCR.use_cassette "create_resources" do
+    driver = Deltacloud::new(:ec2, credentials)
+    @@ec2 = driver.client
+    @@vpc = @@ec2.create_vpc("172.16.0.0/16").first
+    @@subnet = @@ec2.create_subnet(@@vpc[:vpc_id], "172.16.3.0/24", "us-east-1b").first
+  end
+end
+
+def destroy_resources
+  VCR.use_cassette "destroy_resources" do
+    @@ec2.delete_subnet(@@subnet[:subnet_id]) if @@subnet
+    @@ec2.delete_vpc(@@vpc[:vpc_id]) if @@vpc
+  end
+end
+
+MiniTest::Unit::after_tests { destroy_resources }
+
+create_resources
diff --git a/server/tests/drivers/ec2/fixtures/create_resources.yml b/server/tests/drivers/ec2/fixtures/create_resources.yml
new file mode 100644
index 0000000..fb14d7b
--- /dev/null
+++ b/server/tests/drivers/ec2/fixtures/create_resources.yml
@@ -0,0 +1,79 @@
+--- 
+http_interactions: 
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=CreateVpc&CidrBlock=172.16.0.0/16&Signature=1v+DVE5pE5wAGscby85h5Phi5O5OEl+3WgxOn/BgNaE=&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-08-28T22:36:42.000Z&Version=2010-08-31
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+      Date: 
+      - Tue, 28 Aug 2012 22:36:42 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <CreateVpcResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>12201e58-4637-4663-a0da-a9c3bcf49d5c</requestId>
+            <vpc>
+                <vpcId>vpc-6a952301</vpcId>
+                <state>pending</state>
+                <cidrBlock>172.16.0.0/16</cidrBlock>
+                <dhcpOptionsId>default</dhcpOptionsId>
+            </vpc>
+        </CreateVpcResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 22:36:42 GMT
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=CreateSubnet&AvailabilityZone=us-east-1b&CidrBlock=172.16.3.0/24&Signature=EIzFCEEuL0/0E/GVatWByMC0qybmPTw0+kd2xHnOGuw=&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-08-28T22:36:42.000Z&Version=2010-08-31&VpcId=vpc-6a952301
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+      Date: 
+      - Tue, 28 Aug 2012 22:36:43 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <CreateSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>e3939c15-3c67-4e33-b1d8-88242dd2317c</requestId>
+            <subnet>
+                <subnetId>subnet-62952309</subnetId>
+                <state>pending</state>
+                <vpcId>vpc-6a952301</vpcId>
+                <cidrBlock>172.16.3.0/24</cidrBlock>
+                <availableIpAddressCount>251</availableIpAddressCount>
+                <availabilityZone>us-east-1b</availabilityZone>
+            </subnet>
+        </CreateSubnetResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 22:36:43 GMT
+recorded_with: VCR 2.2.4
diff --git a/server/tests/drivers/ec2/fixtures/destroy_resources.yml b/server/tests/drivers/ec2/fixtures/destroy_resources.yml
new file mode 100644
index 0000000..61020fa
--- /dev/null
+++ b/server/tests/drivers/ec2/fixtures/destroy_resources.yml
@@ -0,0 +1,67 @@
+--- 
+http_interactions: 
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=DeleteSubnet&Signature=kpx0IU+viAUHCJMSNE+VAc/Hl0oqHdr08cFN7jwJW38=&SignatureMethod=HmacSHA256&SignatureVersion=2&SubnetId=subnet-62952309&Timestamp=2012-08-28T22:36:45.000Z&Version=2010-08-31
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+      Date: 
+      - Tue, 28 Aug 2012 22:36:46 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <DeleteSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>342eac4f-3687-4d89-92b7-0484b618947e</requestId>
+            <return>true</return>
+        </DeleteSubnetResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 22:36:46 GMT
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=DeleteVpc&Signature=OzOLWsGU2ZIwhaA46jecA/wwUeV+hFMu9d1XeUysvG0=&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-08-28T22:36:46.000Z&Version=2010-08-31&VpcId=vpc-6a952301
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+      Date: 
+      - Tue, 28 Aug 2012 22:36:46 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <DeleteVpcResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>d3b55d09-5ece-4b07-a81a-5e9ef3b1d750</requestId>
+            <return>true</return>
+        </DeleteVpcResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 22:36:47 GMT
+recorded_with: VCR 2.2.4
diff --git a/server/tests/drivers/ec2/fixtures/test_0002_must_return_list_of_realms.yml b/server/tests/drivers/ec2/fixtures/test_0002_must_return_list_of_realms.yml
index 4929f38..f4ea216 100644
--- a/server/tests/drivers/ec2/fixtures/test_0002_must_return_list_of_realms.yml
+++ b/server/tests/drivers/ec2/fixtures/test_0002_must_return_list_of_realms.yml
@@ -1,5 +1,4 @@
 --- 
-recorded_with: VCR 2.2.4
 http_interactions: 
 - request: 
     method: get
@@ -18,12 +17,12 @@ http_interactions:
     headers: 
       Date: 
       - Mon, 30 Jul 2012 11:05:04 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
       Server: 
       - AmazonEC2
       Transfer-Encoding: 
       - chunked
-      Content-Type: 
-      - text/xml;charset=UTF-8
     body: 
       string: |-
         <?xml version="1.0" encoding="UTF-8"?>
@@ -81,12 +80,12 @@ http_interactions:
     headers: 
       Date: 
       - Mon, 30 Jul 2012 11:05:05 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
       Server: 
       - AmazonEC2
       Transfer-Encoding: 
       - chunked
-      Content-Type: 
-      - text/xml;charset=UTF-8
     body: 
       string: |-
         <?xml version="1.0" encoding="UTF-8"?>
@@ -127,3 +126,86 @@ http_interactions:
         </DescribeAvailabilityZonesResponse>
     http_version: 
   recorded_at: Mon, 30 Jul 2012 11:05:00 GMT
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=DescribeSubnets&Signature=P2fvw5n27dvw0TkOwhu7KiUgKkMR2eCPabzIrNMPLuc=&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-08-28T19:12:03.000Z&Version=2010-08-31
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Content-Type: 
+      - text/xml;charset=UTF-8
+      Date: 
+      - Tue, 28 Aug 2012 19:12:04 GMT
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <DescribeSubnetsResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>f2d1c818-096a-4746-afee-7862d0a58cfc</requestId>
+            <subnetSet>
+                <item>
+                    <subnetId>subnet-dd5bfcb6</subnetId>
+                    <state>available</state>
+                    <vpcId>vpc-0b40e760</vpcId>
+                    <cidrBlock>10.1.0.0/24</cidrBlock>
+                    <availableIpAddressCount>251</availableIpAddressCount>
+                    <availabilityZone>us-east-1a</availabilityZone>
+                </item>
+            </subnetSet>
+        </DescribeSubnetsResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 19:12:04 GMT
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=DescribeSubnets&Signature=LDiqi0eL5WZCJtyoNdoSjhcVxGsFyowDT2/1jVlx/cM=&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-08-28T19:12:04.000Z&Version=2010-08-31
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Content-Type: 
+      - text/xml;charset=UTF-8
+      Date: 
+      - Tue, 28 Aug 2012 19:12:04 GMT
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <DescribeSubnetsResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>e3fce148-6be5-4b2f-99b1-66cc9297ab08</requestId>
+            <subnetSet>
+                <item>
+                    <subnetId>subnet-dd5bfcb6</subnetId>
+                    <state>available</state>
+                    <vpcId>vpc-0b40e760</vpcId>
+                    <cidrBlock>10.1.0.0/24</cidrBlock>
+                    <availableIpAddressCount>251</availableIpAddressCount>
+                    <availabilityZone>us-east-1a</availabilityZone>
+                </item>
+            </subnetSet>
+        </DescribeSubnetsResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 19:12:05 GMT
+recorded_with: VCR 2.2.4
diff --git a/server/tests/drivers/ec2/fixtures/test_0005_must_list_VPC_subnets_as_realms.yml
b/server/tests/drivers/ec2/fixtures/test_0005_must_list_VPC_subnets_as_realms.yml
new file mode 100644
index 0000000..fdce4eb
--- /dev/null
+++ b/server/tests/drivers/ec2/fixtures/test_0005_must_list_VPC_subnets_as_realms.yml
@@ -0,0 +1,109 @@
+--- 
+http_interactions: 
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=DescribeAvailabilityZones&Signature=v93MQI1cGoYMFByjuzOvr9DZAbE50n6cNkgTf4g8rJs=&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-08-28T22:36:44.000Z&Version=2010-08-31
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+      Date: 
+      - Tue, 28 Aug 2012 22:36:45 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>aa77686e-b8b2-4870-8f1e-6232077dbade</requestId>
+            <availabilityZoneInfo>
+                <item>
+                    <zoneName>us-east-1a</zoneName>
+                    <zoneState>available</zoneState>
+                    <regionName>us-east-1</regionName>
+                    <messageSet/>
+                </item>
+                <item>
+                    <zoneName>us-east-1b</zoneName>
+                    <zoneState>available</zoneState>
+                    <regionName>us-east-1</regionName>
+                    <messageSet/>
+                </item>
+                <item>
+                    <zoneName>us-east-1c</zoneName>
+                    <zoneState>available</zoneState>
+                    <regionName>us-east-1</regionName>
+                    <messageSet/>
+                </item>
+                <item>
+                    <zoneName>us-east-1d</zoneName>
+                    <zoneState>available</zoneState>
+                    <regionName>us-east-1</regionName>
+                    <messageSet/>
+                </item>
+            </availabilityZoneInfo>
+        </DescribeAvailabilityZonesResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 22:36:45 GMT
+- request: 
+    method: get
+    uri: https://ec2.us-east-1.amazonaws.com/?AWSAccessKeyId=AKIAJHMN5TTUKVLK5WCQ&Action=DescribeSubnets&Signature=r2v7oE4F8OoTHhXc1NYAdJTr6giszS8MSsQ7prKHM4g=&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-08-28T22:36:45.000Z&Version=2010-08-31
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+      User-Agent: 
+      - ""
+  response: 
+    status: 
+      code: 200
+      message: OK
+    headers: 
+      Server: 
+      - AmazonEC2
+      Transfer-Encoding: 
+      - chunked
+      Date: 
+      - Tue, 28 Aug 2012 22:36:45 GMT
+      Content-Type: 
+      - text/xml;charset=UTF-8
+    body: 
+      string: |-
+        <?xml version="1.0" encoding="UTF-8"?>
+        <DescribeSubnetsResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+            <requestId>c95921ad-17a4-4262-b877-2d357f6873f6</requestId>
+            <subnetSet>
+                <item>
+                    <subnetId>subnet-dd5bfcb6</subnetId>
+                    <state>available</state>
+                    <vpcId>vpc-0b40e760</vpcId>
+                    <cidrBlock>10.1.0.0/24</cidrBlock>
+                    <availableIpAddressCount>251</availableIpAddressCount>
+                    <availabilityZone>us-east-1a</availabilityZone>
+                </item>
+                <item>
+                    <subnetId>subnet-62952309</subnetId>
+                    <state>available</state>
+                    <vpcId>vpc-6a952301</vpcId>
+                    <cidrBlock>172.16.3.0/24</cidrBlock>
+                    <availableIpAddressCount>251</availableIpAddressCount>
+                    <availabilityZone>us-east-1b</availabilityZone>
+                </item>
+            </subnetSet>
+        </DescribeSubnetsResponse>
+    http_version: 
+  recorded_at: Tue, 28 Aug 2012 22:36:45 GMT
+recorded_with: VCR 2.2.4
diff --git a/server/tests/drivers/ec2/realms_test.rb b/server/tests/drivers/ec2/realms_test.rb
index 5129fe2..0f0b7d2 100644
--- a/server/tests/drivers/ec2/realms_test.rb
+++ b/server/tests/drivers/ec2/realms_test.rb
@@ -40,4 +40,9 @@ describe 'Ec2Driver Realms' do
     @driver.realm(:id => 'unknown').must_be_nil
   end
 
+  it 'must list VPC subnets as realms' do
+    id = "#{@@subnet[:availability_zone]}:#{@@subnet[:subnet_id]}"
+    @driver.realms.find { |r| r.id == id }.wont_be_nil
+  end
+
 end
-- 
1.7.7.6


Mime
View raw message