libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] branch trunk updated: ec2 list_volumes should accept more filters
Date Mon, 01 Jul 2019 20:46:15 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 839ea67  ec2 list_volumes should accept more filters
     new 195ba82  Merge pull request #1300 from palashgandhi/list_volumes_filters
839ea67 is described below

commit 839ea675a7bb7747b45541cb32d3a35bd579304e
Author: Palash Gandhi <palash.gandhi@delphix.com>
AuthorDate: Sun Jun 30 13:46:57 2019 -0700

    ec2 list_volumes should accept more filters
---
 libcloud/compute/drivers/ec2.py   | 22 +++++++++++++++++++---
 libcloud/test/compute/test_ec2.py | 25 +++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 1d501a7..55f6485 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1783,13 +1783,29 @@ class BaseEC2NodeDriver(NodeDriver):
             )
         return locations
 
-    def list_volumes(self, node=None):
+    def list_volumes(self, node=None, ex_filters=None):
+        """
+        List volumes that are attached to a node, if specified and those that
+        satisfy the filters, if specified.
+
+        :param node: The node to which the volumes are attached.
+        :type node: :class:`Node`
+
+        :param ex_filters: The dictionary of additional filters.
+        :type ex_filters: ``dict``
+
+        :return: The list of volumes that match the criteria.
+        :rtype: ``list`` of :class:`StorageVolume`
+        """
         params = {
             'Action': 'DescribeVolumes',
         }
+        if not ex_filters:
+            ex_filters = {}
         if node:
-            filters = {'attachment.instance-id': node.id}
-            params.update(self._build_filters(filters))
+            ex_filters['attachment.instance-id'] = node.id
+        if node or ex_filters:
+            params.update(self._build_filters(ex_filters))
 
         response = self.connection.request(self.path, params=params).object
         volumes = [self._to_volume(el) for el in response.findall(
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index f5c5d1f..475c2be 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -869,6 +869,11 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.assertEqual('snap-30d37269', volumes[2].extra['snapshot_id'])
         self.assertEqual(StorageVolumeState.UNKNOWN, volumes[2].state)
 
+        EC2MockHttp.type = 'filters'
+        node = Node('i-d334b4b3', None, None, None, None, self.driver)
+        self.driver.list_volumes(node=node)
+        self.driver.list_volumes(ex_filters={'status': 'available'})
+
     def test_create_volume(self):
         location = self.driver.list_locations()[0]
         vol = self.driver.create_volume(10, 'vol', location)
@@ -1548,6 +1553,26 @@ class EC2MockHttp(MockHttp):
         body = self.fixtures.load('describe_volumes.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _filters_DescribeVolumes(self, method, url, body, headers):
+        expected_params_1 = {
+            'Filter.1.Name': 'attachment.instance-id',
+            'Filter.1.Value.1': 'i-d334b4b3',
+        }
+
+        expected_params_2 = {
+            'Filter.1.Name': 'status',
+            'Filter.1.Value.1': 'available'
+        }
+
+        try:
+            self.assertUrlContainsQueryParams(url, expected_params_1)
+        except AssertionError:
+            # dict ordering is not guaranteed
+            self.assertUrlContainsQueryParams(url, expected_params_2)
+
+        body = self.fixtures.load('describe_volumes.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _CreateSnapshot(self, method, url, body, headers):
         body = self.fixtures.load('create_snapshot.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])


Mime
View raw message