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 2013/02/07 14:28:01 UTC

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

Author: tomaz
Date: Thu Feb  7 13:28:00 2013
New Revision: 1443458

URL: http://svn.apache.org/viewvc?rev=1443458&view=rev
Log:
Allow users to filter images returned by the list_images method in the EC2
driver by providing ex_image_ids argument.

Contributed by Chris Psaltis, part of LIBCLOUD-294.

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

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1443458&r1=1443457&r2=1443458&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Thu Feb  7 13:28:00 2013
@@ -159,6 +159,10 @@ Changes with Apache Libcloud in developm
      attribute is not present in the response.
      [Gavin McCance, Tomaz Muraus]
 
+   - Allow users to filter images returned by the list_images method in the EC2
+     driver by providing ex_image_ids argument. (LIBCLOUD-294)
+     [Chris Psaltis, Joseph Hall]
+
   *) Storage
 
     - Add a new local storage driver.

Modified: libcloud/trunk/libcloud/compute/drivers/ec2.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/ec2.py?rev=1443458&r1=1443457&r2=1443458&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/ec2.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/ec2.py Thu Feb  7 13:28:00 2013
@@ -644,8 +644,24 @@ class BaseEC2NodeDriver(NodeDriver):
             sizes.append(NodeSize(driver=self, **attributes))
         return sizes
 
-    def list_images(self, location=None):
+    def list_images(self, location=None, ex_image_ids=None):
+        """
+        List all images
+
+        Ex_image_ids parameter is used to filter the list of
+        images that should be returned. Only the images
+        with the corresponding image ids will be returned.
+
+        @param      ex_image_ids: List of C{NodeImage.id}
+        @type       ex_image_ids: C{list} of C{str}
+
+        @rtype: C{list} of L{NodeImage}
+        """
         params = {'Action': 'DescribeImages'}
+
+        if ex_image_ids:
+            params.update(self._pathlist('ImageId', ex_image_ids))
+
         images = self._to_images(
             self.connection.request(self.path, params=params).object
         )

Modified: libcloud/trunk/libcloud/test/compute/test_ec2.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_ec2.py?rev=1443458&r1=1443457&r2=1443458&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_ec2.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_ec2.py Thu Feb  7 13:28:00 2013
@@ -266,6 +266,12 @@ class EC2Tests(LibcloudTestCase, TestCas
                     'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml')
         self.assertEqual(image.id, 'ami-be3adfd7')
 
+    def test_list_images_with_image_ids(self):
+        images = self.driver.list_images(ex_image_ids=['ami-be3adfd7'])
+        self.assertEqual(len(images), 1)
+        self.assertEqual(images[0].name,
+                    'ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml')
+
     def test_ex_list_availability_zones(self):
         availability_zones = self.driver.ex_list_availability_zones()
         availability_zone = availability_zones[0]