You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/11/25 18:08:49 UTC

svn commit: r1206263 - in /libcloud/trunk: CHANGES libcloud/compute/drivers/ec2.py test/compute/test_ec2.py

Author: tomaz
Date: Fri Nov 25 17:08:48 2011
New Revision: 1206263

URL: http://svn.apache.org/viewvc?rev=1206263&view=rev
Log:
Add ex_node_ids argument to the EC2 driver list_nodes method. This patch has
been contributed by Suvish Vt and it's part of GITHUB-39.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/compute/drivers/ec2.py
    libcloud/trunk/test/compute/test_ec2.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1206263&r1=1206262&r2=1206263&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Fri Nov 25 17:08:48 2011
@@ -3,6 +3,10 @@
 Changes with Apache Libcloud in development:
   *) Compute:
 
+     - Add ex_node_ids argument to the EC2 driver list_nodes method. ;
+       GITHUB-39
+       [Suvish Vt]
+
      - If OpenStack Auth 2.0 API is used, also parse out tenant id and
        name and save it on the connection class (conn.tenant['id'],
        conn.tenant['name']).

Modified: libcloud/trunk/libcloud/compute/drivers/ec2.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/ec2.py?rev=1206263&r1=1206262&r2=1206263&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/ec2.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/ec2.py Fri Nov 25 17:08:48 2011
@@ -448,8 +448,17 @@ class EC2NodeDriver(NodeDriver):
         )
         return n
 
-    def list_nodes(self):
+    def list_nodes(self, ex_node_ids=None):
+        """
+        @type node.id: C{list}
+        @param ex_node_ids: List of C{node.id}
+        This parameter is used to filter the list of
+        nodes that should be returned. Only the nodes
+        with the corresponding node ids will be returned.
+        """
         params = {'Action': 'DescribeInstances'}
+        if ex_node_ids:
+            params.update(self._pathlist('InstanceId', ex_node_ids))
         elem = self.connection.request(self.path, params=params).object
         nodes = []
         for rs in findall(element=elem, xpath='reservationSet/item',

Modified: libcloud/trunk/test/compute/test_ec2.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_ec2.py?rev=1206263&r1=1206262&r2=1206263&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_ec2.py (original)
+++ libcloud/trunk/test/compute/test_ec2.py Fri Nov 25 17:08:48 2011
@@ -65,7 +65,6 @@ class EC2Tests(LibcloudTestCase, TestCas
         self.assertEqual(node.extra['clienttoken'], token)
 
         # from: http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/index.html?Run_Instance_Idempotency.html
-
         #    If you repeat the request with the same client token, but change
         #    another request parameter, Amazon EC2 returns an
         #    IdempotentParameterMismatch error.
@@ -103,12 +102,29 @@ class EC2Tests(LibcloudTestCase, TestCas
         self.assertEqual(node.id, 'i-4382922a')
         self.assertEqual(node.name, node.id)
         self.assertEqual(len(node.public_ips), 2)
-        self.assertEqual(node.extra['launchdatetime'], '2009-08-07T05:47:04.000Z')
+        self.assertEqual(node.extra['launchdatetime'],
+                            '2009-08-07T05:47:04.000Z')
         self.assertTrue('instancetype' in node.extra)
 
         self.assertEqual(public_ips[0], '1.2.3.4')
         self.assertEqual(public_ips[1], '1.2.3.5')
 
+        nodes = self.driver.list_nodes(ex_node_ids=['i-4382922a',
+                                                    'i-8474834a'])
+        ret_node1 = nodes[0]
+        ret_node2 = nodes[1]
+
+        self.assertEqual(ret_node1.id, 'i-4382922a')
+        self.assertEqual(ret_node2.id, 'i-8474834a')
+
+        self.assertEqual(ret_node1.extra['launchdatetime'],
+                                        '2009-08-07T05:47:04.000Z')
+        self.assertTrue('instancetype' in ret_node1.extra)
+
+        self.assertEqual(ret_node2.extra['launchdatetime'],
+                                        '2009-08-07T05:47:04.000Z')
+        self.assertTrue('instancetype' in ret_node2.extra)
+
     def test_list_nodes_with_name_tag(self):
         EC2MockHttp.type = 'WITH_TAGS'
         node = self.driver.list_nodes()[0]
@@ -179,7 +195,8 @@ class EC2Tests(LibcloudTestCase, TestCas
         images = self.driver.list_images()
         image = images[0]
         self.assertEqual(len(images), 1)
-        self.assertEqual(image.name, 'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml')
+        self.assertEqual(image.name,
+                    'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml')
         self.assertEqual(image.id, 'ami-be3adfd7')
 
     def test_ex_list_availability_zones(self):