Frank Wierzbicki has proposed merging 
lp:~fwierzbicki/txaws/break-out-parse-instance into lp:txaws.

Requested reviews:
  txAWS Developers (txaws-dev)
  txAWS Developers (txaws-dev)
Related bugs:
  Bug #766216 in txAWS: "It will help our use of txAWS in Landscape if the 
instance parsing is broken out from parsing instance sets"
  https://bugs.launchpad.net/txaws/+bug/766216

For more details, see:
https://code.launchpad.net/~fwierzbicki/txaws/break-out-parse-instance/+merge/58340

This branch breaks out the parsing of an instance from the parsing of an 
instance set for use in Landscape where we need to extend Instance with our own 
field.

It also adds a query_factory parameter to FakeEC2Client to match the real 
EC2Client.
-- 
https://code.launchpad.net/~fwierzbicki/txaws/break-out-parse-instance/+merge/58340
Your team txAWS Developers is requested to review the proposed merge of 
lp:~fwierzbicki/txaws/break-out-parse-instance into lp:txaws.
=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py	2011-03-21 08:55:48 +0000
+++ txaws/ec2/client.py	2011-04-19 16:13:02 +0000
@@ -45,33 +45,36 @@
     def _parse_instances_set(self, root, reservation):
         instances = []
         for instance_data in root.find("instancesSet"):
-            instance_id = instance_data.findtext("instanceId")
-            instance_state = instance_data.find(
-                "instanceState").findtext("name")
-            instance_type = instance_data.findtext("instanceType")
-            image_id = instance_data.findtext("imageId")
-            private_dns_name = instance_data.findtext("privateDnsName")
-            dns_name = instance_data.findtext("dnsName")
-            key_name = instance_data.findtext("keyName")
-            ami_launch_index = instance_data.findtext("amiLaunchIndex")
-            launch_time = instance_data.findtext("launchTime")
-            placement = instance_data.find("placement").findtext(
-                "availabilityZone")
-            products = []
-            product_codes = instance_data.find("productCodes")
-            if product_codes:
-                for product_data in instance_data.find("productCodes"):
-                    products.append(product_data.text)
-            kernel_id = instance_data.findtext("kernelId")
-            ramdisk_id = instance_data.findtext("ramdiskId")
-            instance = model.Instance(
-                instance_id, instance_state, instance_type, image_id,
-                private_dns_name, dns_name, key_name, ami_launch_index,
-                launch_time, placement, products, kernel_id, ramdisk_id,
-                reservation=reservation)
-            instances.append(instance)
+            instances.append(self._parse_instance(instance_data, reservation))
         return instances
 
+    def _parse_instance(self, instance_data, reservation):
+        instance_id = instance_data.findtext("instanceId")
+        instance_state = instance_data.find(
+            "instanceState").findtext("name")
+        instance_type = instance_data.findtext("instanceType")
+        image_id = instance_data.findtext("imageId")
+        private_dns_name = instance_data.findtext("privateDnsName")
+        dns_name = instance_data.findtext("dnsName")
+        key_name = instance_data.findtext("keyName")
+        ami_launch_index = instance_data.findtext("amiLaunchIndex")
+        launch_time = instance_data.findtext("launchTime")
+        placement = instance_data.find("placement").findtext(
+            "availabilityZone")
+        products = []
+        product_codes = instance_data.find("productCodes")
+        if product_codes:
+            for product_data in instance_data.find("productCodes"):
+                products.append(product_data.text)
+        kernel_id = instance_data.findtext("kernelId")
+        ramdisk_id = instance_data.findtext("ramdiskId")
+        instance = model.Instance(
+            instance_id, instance_state, instance_type, image_id,
+            private_dns_name, dns_name, key_name, ami_launch_index,
+            launch_time, placement, products, kernel_id, ramdisk_id,
+            reservation=reservation)
+        return instance
+
     def _parse_describe_instances(self, xml_bytes):
         """
         Parse the reservations XML payload that is returned from an AWS

=== modified file 'txaws/testing/ec2.py'
--- txaws/testing/ec2.py	2009-10-14 14:41:28 +0000
+++ txaws/testing/ec2.py	2011-04-19 16:13:02 +0000
@@ -10,13 +10,16 @@
 
 from txaws.ec2.model import Keypair, SecurityGroup
 
+
 class FakeEC2Client(object):
 
-    def __init__(self, creds, endpoint, instances=None, keypairs=None,
-                 volumes=None, key_material="", security_groups=None,
-                 snapshots=None, addresses=None, availability_zones=None):
+    def __init__(self, creds, endpoint, query_factory=None, instances=None,
+                 keypairs=None, volumes=None, key_material="",
+                 security_groups=None, snapshots=None, addresses=None,
+                 availability_zones=None):
         self.creds = creds
         self.endpoint = endpoint
+        query_factory = query_factory
         self.instances = instances or []
         self.keypairs = keypairs or []
         self.keypairs_deleted = []
@@ -141,4 +144,3 @@
         except:
             failure = Failure()
         return fail(failure)
-

_______________________________________________
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