From cc33fc23fdd271b83567e3149c698ea6a9c4e612 Mon Sep 17 00:00:00 2001 From: "Michaelchuck, Jon (DS)" Date: Fri, 16 Sep 2016 12:48:17 -0700 Subject: [PATCH] [LIBCLOUD-852] Support filtering in ec2 list_volumes --- libcloud/compute/drivers/ec2.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index bc382e4..0678a1a 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -2892,13 +2892,37 @@ class BaseEC2NodeDriver(NodeDriver): ) return locations - def list_volumes(self, node=None): + def list_volumes(self, node=None, ex_filters=None): + """ + List volumes + @inherits: :class:`NodeDriver.list_volumes` + + Node parameter is used to filter the list of volumes + that should be returned. Only volumes attached to + the corresponding node will be returned. + + Ex_filters parameter is used to filter the list of + images that should be returned. Only images matching + the filter will be returned. + + :param node: Instance of ``Node`` + :type node: :class: `Node` + + :param ex_filters: Filter by + :type ex_filters: ``dict`` + + :rtype: ``list`` of :class:`StorageVolume` + """ + params = { 'Action': 'DescribeVolumes', } if node: - filters = {'attachment.instance-id': node.id} - params.update(self._build_filters(filters)) + if ex_filters is None: + ex_filters = {} + ex_filters.update({'attachment.instance-id': node.id}) + if 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( -- 2.8.4 (Apple Git-73)