Hi,

The attached patch changes the list_nodes implementation in ec2.py so
that the returned node objects have a list of security groups in the
extras dictionary.  

If there's anything that needs improvement to get this feature added,
please let me know.

Thanks,
Richard Kreuter

Index: libcloud/drivers/ec2.py
===================================================================
--- libcloud/drivers/ec2.py	(revision 933785)
+++ libcloud/drivers/ec2.py	(working copy)
@@ -230,11 +230,11 @@
                      for term_status
                      in ('shutting-down', 'terminated') ])
 
-    def _to_nodes(self, object, xpath):
-        return [ self._to_node(el) 
+    def _to_nodes(self, object, xpath, groups=None):
+        return [ self._to_node(el, groups=groups) 
                  for el in object.findall(self._fixxpath(xpath)) ]
         
-    def _to_node(self, element):
+    def _to_node(self, element, groups=None):
         try:
             state = self.NODE_STATE_MAP[
                 self._findattr(element, "instanceState/name")
@@ -266,7 +266,8 @@
                 'availability': self._findattr(element,
                                                "placement/availabilityZone"),
                 'kernelid': self._findattr(element, "kernelId"),
-                'ramdiskid': self._findattr(element, "ramdiskId")
+                'ramdiskid': self._findattr(element, "ramdiskId"),
+                'groups': groups
             }
         )
         return n
@@ -285,9 +286,11 @@
 
     def list_nodes(self):
         params = {'Action': 'DescribeInstances' }
-        nodes = self._to_nodes(
-                    self.connection.request('/', params=params).object,
-                    'reservationSet/item/instancesSet/item')
+        elem=self.connection.request('/', params=params).object
+        nodes=[]
+        for rs in self._findall(elem, 'reservationSet/item'):
+            groups=[g.findtext('') for g in self._findall(rs, 'groupSet/item/groupId')]
+            nodes += self._to_nodes(rs, 'instancesSet/item', groups)
         return nodes
 
     def list_sizes(self, location=None):

Reply via email to