Francisco Souza has proposed merging lp:~franciscosouza/txaws/txaws-vpc into 
lp:txaws.

Requested reviews:
  txAWS Committers (txaws-dev)

For more details, see:
https://code.launchpad.net/~franciscosouza/txaws/txaws-vpc/+merge/133250

ec2/client: added support for VPC

This change adds supports for running instances in VPC subnets.

For that, it was necessary to update the EC2 API version,
I picked the last version.

https://codereview.appspot.com/6826065/

-- 
https://code.launchpad.net/~franciscosouza/txaws/txaws-vpc/+merge/133250
Your team txAWS Committers is requested to review the proposed merge of 
lp:~franciscosouza/txaws/txaws-vpc into lp:txaws.
=== modified file 'txaws/client/discover/tests/test_command.py'
--- txaws/client/discover/tests/test_command.py	2012-01-27 02:10:24 +0000
+++ txaws/client/discover/tests/test_command.py	2012-11-07 13:59:28 +0000
@@ -74,9 +74,9 @@
             url = (
                 "http://endpoint?AWSAccessKeyId=key&";
                 "Action=DescribeRegions&"
-                "Signature=3%2BHSkQQosF1Sr9AL3kdY31tEfTWQ2whjJOUSc3kvc2c%3D&"
+                "Signature=7fyxNidMkL%2B85udGOxqm%2BgM2o1gLyeLG2a0UOmfBOXQ%3D&"
                 "SignatureMethod=HmacSHA256&SignatureVersion=2&"
-                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2009-11-30")
+                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2012-08-15")
             self.assertEqual("GET", self.method)
             self.assertEqual(url, self.url)
             self.assertEqual("URL: %s\n"
@@ -99,9 +99,9 @@
             url = (
                 "http://endpoint?AWSAccessKeyId=key&";
                 "Action=DescribeRegions&RegionName.0=us-west-1&"
-                "Signature=6D8aCgSPQOYixowRHy26aRFzK2Vwgixl9uwegYX9nLA%3D&"
+                "Signature=FL4JjDKbWdg531q1KKUPild%2BvyqspA5wxSmOeWXWsJI%3D&"
                 "SignatureMethod=HmacSHA256&SignatureVersion=2&"
-                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2009-11-30")
+                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2012-08-15")
             self.assertEqual("GET", self.method)
             self.assertEqual(url, self.url)
             self.assertEqual("URL: %s\n"
@@ -128,9 +128,9 @@
             url = (
                 "http://endpoint?AWSAccessKeyId=key&";
                 "Action=DescribeRegions&RegionName.0=us-west-1&"
-                "Signature=6D8aCgSPQOYixowRHy26aRFzK2Vwgixl9uwegYX9nLA%3D&"
+                "Signature=FL4JjDKbWdg531q1KKUPild%2BvyqspA5wxSmOeWXWsJI%3D&"
                 "SignatureMethod=HmacSHA256&SignatureVersion=2&"
-                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2009-11-30")
+                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2012-08-15")
             self.assertEqual("GET", self.method)
             self.assertEqual(url, self.url)
             self.assertEqual("URL: %s\n"
@@ -185,9 +185,9 @@
             url = (
                 "http://endpoint?AWSAccessKeyId=key&";
                 "Action=DescribeRegions&RegionName.0=us-west-1&"
-                "Signature=6D8aCgSPQOYixowRHy26aRFzK2Vwgixl9uwegYX9nLA%3D&"
+                "Signature=FL4JjDKbWdg531q1KKUPild%2BvyqspA5wxSmOeWXWsJI%3D&"
                 "SignatureMethod=HmacSHA256&SignatureVersion=2&"
-                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2009-11-30")
+                "Timestamp=2010-06-04T23%3A40%3A00Z&Version=2012-08-15")
             self.assertEqual("GET", self.method)
             self.assertEqual(url, self.url)
             self.assertEqual("URL: %s\n"

=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py	2012-05-05 00:17:02 +0000
+++ txaws/ec2/client.py	2012-11-07 13:59:28 +0000
@@ -48,7 +48,7 @@
     def run_instances(self, image_id, min_count, max_count,
         security_groups=None, key_name=None, instance_type=None,
         user_data=None, availability_zone=None, kernel_id=None,
-        ramdisk_id=None):
+        ramdisk_id=None, subnet_id=None, security_group_ids=None):
         """Run new instances.
 
         TODO: blockDeviceMapping, monitoring, subnetId
@@ -57,9 +57,21 @@
                   "MaxCount": str(max_count)}
         if key_name is not None:
             params["KeyName"] = key_name
-        if security_groups is not None:
+        if subnet_id is not None:
+            params["SubnetId"] = subnet_id
+            if security_group_ids is not None:
+                for i, id in enumerate(security_group_ids):
+                    params["SecurityGroupId.%d" % (i + 1)] = id
+            else:
+                msg = "You must specify the security_group_ids with the subnet_id"
+                raise ValueError(msg)
+        elif security_groups is not None:
             for i, name in enumerate(security_groups):
                 params["SecurityGroup.%d" % (i + 1)] = name
+        else:
+            msg = ("You must specify either the subnet_id and "
+                   "security_group_ids or security_groups")
+            raise ValueError(msg)
         if user_data is not None:
             params["UserData"] = b64encode(user_data)
         if instance_type is not None:

=== modified file 'txaws/ec2/tests/test_client.py'
--- txaws/ec2/tests/test_client.py	2012-03-02 22:00:10 +0000
+++ txaws/ec2/tests/test_client.py	2012-11-07 13:59:28 +0000
@@ -377,6 +377,59 @@
             ramdisk_id=u"r-1234")
         d.addCallback(self.check_parsed_run_instances)
 
+    def test_run_instances_with_subnet(self):
+        class StubQuery(object):
+            def __init__(stub, action="", creds=None, endpoint=None,
+                         other_params={}):
+                self.assertEqual(action, "RunInstances")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEquals(
+                    other_params,
+                    {"ImageId": "ami-1234", "MaxCount": "2", "MinCount": "1",
+                     "SecurityGroupId.1": u"sg-a72d9f92e", "KeyName": u"default",
+                     "UserData": "Zm9v", "InstanceType": u"m1.small",
+                     "Placement.AvailabilityZone": u"us-east-1b",
+                     "KernelId": u"k-1234", "RamdiskId": u"r-1234",
+                     "SubnetId": "subnet-a72d829f"})
+
+            def submit(self):
+                return succeed(
+                    payload.sample_run_instances_result)
+
+        creds = AWSCredentials("foo", "bar")
+        ec2 = client.EC2Client(creds, query_factory=StubQuery)
+        d = ec2.run_instances("ami-1234", 1, 2, security_group_ids=[u"sg-a72d9f92e"],
+            key_name=u"default", user_data=u"foo", instance_type=u"m1.small",
+            availability_zone=u"us-east-1b", kernel_id=u"k-1234",
+            ramdisk_id=u"r-1234", subnet_id="subnet-a72d829f")
+        d.addCallback(self.check_parsed_run_instances)
+
+    def test_run_instances_with_subnet_but_without_secgroup_id(self):
+        creds = AWSCredentials("foo", "bar")
+        ec2 = client.EC2Client(creds)
+        error = self.assertRaises(ValueError, ec2.run_instances, "ami-1234", 1, 2,
+            key_name=u"default", user_data=u"foo", instance_type=u"m1.small",
+            availability_zone=u"us-east-1b", kernel_id=u"k-1234",
+            ramdisk_id=u"r-1234", subnet_id="subnet-a72d829f")
+        self.assertEqual(
+            str(error),
+            "You must specify the security_group_ids with the subnet_id"
+        )
+
+    def test_run_instances_without_subnet_and_secgroups(self):
+        creds = AWSCredentials("foo", "bar")
+        ec2 = client.EC2Client(creds)
+        error = self.assertRaises(ValueError, ec2.run_instances, "ami-1234", 1, 2,
+            key_name=u"default", user_data=u"foo", instance_type=u"m1.small",
+            availability_zone=u"us-east-1b", kernel_id=u"k-1234",
+            ramdisk_id=u"r-1234")
+        self.assertEqual(
+            str(error),
+            ("You must specify either the subnet_id and "
+             "security_group_ids or security_groups")
+        )
+
 
 class EC2ClientSecurityGroupsTestCase(TXAWSTestCase):
 
@@ -1561,7 +1614,7 @@
             {"AWSAccessKeyId": "foo",
              "Action": "DescribeInstances",
              "SignatureVersion": "2",
-             "Version": "2009-11-30"})
+             "Version": "2012-08-15"})
 
     def test_init_other_args_are_params(self):
         query = client.Query(
@@ -1575,7 +1628,7 @@
              "InstanceId.0": "12345",
              "SignatureVersion": "2",
              "Timestamp": "2007-11-12T13:14:15Z",
-             "Version": "2009-11-30"})
+             "Version": "2012-08-15"})
 
     def test_no_timestamp_if_expires_in_other_params(self):
         """
@@ -1593,7 +1646,7 @@
              "Action": "DescribeInstances",
              "SignatureVersion": "2",
              "Expires": "2007-11-12T13:14:15Z",
-             "Version": "2009-11-30"})
+             "Version": "2012-08-15"})
 
     def test_sign(self):
         query = client.Query(
@@ -1601,7 +1654,7 @@
             endpoint=self.endpoint,
             time_tuple=(2007, 11, 12, 13, 14, 15, 0, 0, 0))
         query.sign()
-        self.assertEqual("G4c2NtQaFNhWWT8EWPVIIOpHVr0mGUYwJVYss9krsMU=",
+        self.assertEqual("c0gbkemrGEJdqxWOl2UZYaygYiBLVjrpWBs7bTN7Ndo=",
             query.params["Signature"])
 
     def test_old_sign(self):
@@ -1612,7 +1665,7 @@
             other_params={"SignatureVersion": "1"})
         query.sign()
         self.assertEqual(
-            "9xP+PIs/3QXW+4mWX6WGR4nGqfE=", query.params["Signature"])
+            "7tWrIC5VYvXOjVE+roVoyDUt2Yw=", query.params["Signature"])
 
     def test_unsupported_sign(self):
         query = client.Query(

=== modified file 'txaws/server/tests/test_call.py'
--- txaws/server/tests/test_call.py	2012-01-27 02:10:24 +0000
+++ txaws/server/tests/test_call.py	2012-11-07 13:59:28 +0000
@@ -11,4 +11,4 @@
         2009-11-30, which is the earliest version we support.
         """
         call = Call()
-        self.assertEqual(call.version, "2009-11-30")
+        self.assertEqual(call.version, "2012-08-15")

=== modified file 'txaws/version.py'
--- txaws/version.py	2012-01-24 23:18:36 +0000
+++ txaws/version.py	2012-11-07 13:59:28 +0000
@@ -1,3 +1,3 @@
 txaws = "0.2.3"
-ec2_api = "2009-11-30"
+ec2_api = "2012-08-15"
 s3_api = "2006-03-01"

_______________________________________________
Mailing list: https://launchpad.net/~txaws-dev
Post to     : txaws-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txaws-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to