Node filters for ec2 driver

Closes #320

Signed-off-by: Tomaz Muraus <to...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/8d93bf13
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8d93bf13
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8d93bf13

Branch: refs/heads/trunk
Commit: 8d93bf1383ff1001e3f4155009a784ba179cc0f8
Parents: 8aa715b
Author: Lior Goikhburg <goikhb...@gmail.com>
Authored: Fri Jun 20 18:24:55 2014 +0400
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Jun 25 16:01:55 2014 +0200

----------------------------------------------------------------------
 CHANGES.rst                     |  5 +++++
 libcloud/compute/drivers/ec2.py | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/8d93bf13/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index d5ccdc5..c4df822 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -19,6 +19,11 @@ Compute
   (LIBCLOUD-572, GITHUB-307)
   [Lior Goikhburg]
 
+- Allow user to filter which nodes are returned by passing ``ex_filters``
+  argument to the ``list_nodes`` method in the EC2 driver.
+  (LIBCLOUD-580, GITHUB-320)
+  [Lior Goikhburg]
+
 Changes with Apache Libcloud 0.15.0
 -----------------------------------
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/8d93bf13/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index efd8251..a8124bf 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1879,7 +1879,7 @@ class BaseEC2NodeDriver(NodeDriver):
         'terminated': NodeState.TERMINATED
     }
 
-    def list_nodes(self, ex_node_ids=None):
+    def list_nodes(self, ex_node_ids=None, ex_filters=None):
         """
         List all nodes
 
@@ -1890,21 +1890,34 @@ class BaseEC2NodeDriver(NodeDriver):
         :param      ex_node_ids: List of ``node.id``
         :type       ex_node_ids: ``list`` of ``str``
 
+        :param      ex_filters: The filters so that the response includes
+                             information for only certain nodes.
+        :type       ex_filters: ``dict``
+
         :rtype: ``list`` of :class:`Node`
         """
+
         params = {'Action': 'DescribeInstances'}
+
         if ex_node_ids:
             params.update(self._pathlist('InstanceId', ex_node_ids))
+
+        if ex_filters:
+            params.update(self._build_filters(ex_filters))
+
         elem = self.connection.request(self.path, params=params).object
+
         nodes = []
         for rs in findall(element=elem, xpath='reservationSet/item',
                           namespace=NAMESPACE):
             nodes += self._to_nodes(rs, 'instancesSet/item')
 
         nodes_elastic_ips_mappings = self.ex_describe_addresses(nodes)
+
         for node in nodes:
             ips = nodes_elastic_ips_mappings[node.id]
             node.public_ips.extend(ips)
+
         return nodes
 
     def list_sizes(self, location=None):

Reply via email to