libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1067376 - in /incubator/libcloud/trunk: libcloud/drivers/ec2.py test/fixtures/ec2/describe_tags.xml test/test_ec2.py
Date Sat, 05 Feb 2011 01:49:50 GMT
Author: tomaz
Date: Sat Feb  5 01:49:50 2011
New Revision: 1067376

URL: http://svn.apache.org/viewvc?rev=1067376&view=rev
Log:
Add ex_describe_tags method to EC2 driver.

Added:
    incubator/libcloud/trunk/test/fixtures/ec2/describe_tags.xml
Modified:
    incubator/libcloud/trunk/libcloud/drivers/ec2.py
    incubator/libcloud/trunk/test/test_ec2.py

Modified: incubator/libcloud/trunk/libcloud/drivers/ec2.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/ec2.py?rev=1067376&r1=1067375&r2=1067376&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/ec2.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/ec2.py Sat Feb  5 01:49:50 2011
@@ -605,6 +605,33 @@ class EC2NodeDriver(NodeDriver):
 
         return availability_zones
 
+    def ex_describe_tags(self, node):
+        """
+        Return a dictionary of tags for this instance.
+
+        @type node: C{Node}
+        @param node: Node instance
+
+        @return dict Node tags
+        """
+        params = { 'Action': 'DescribeTags',
+                   'Filter.0.Name': 'resource-id',
+                   'Filter.0.Value.0': node.id,
+                   'Filter.1.Name': 'resource-type',
+                   'Filter.1.Value.0': 'instance',
+                   }
+
+        result = self.connection.request(self.path,
+                                         params=params.copy()).object
+
+        tags = {}
+        for element in self._findall(result, 'tagSet/item'):
+            key = self._findtext(element, 'key')
+            value = self._findtext(element, 'value')
+
+            tags[key] = value
+        return tags
+
     def create_node(self, **kwargs):
         """Create a new EC2 node
 

Added: incubator/libcloud/trunk/test/fixtures/ec2/describe_tags.xml
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/ec2/describe_tags.xml?rev=1067376&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/ec2/describe_tags.xml (added)
+++ incubator/libcloud/trunk/test/fixtures/ec2/describe_tags.xml Sat Feb  5 01:49:50 2011
@@ -0,0 +1,23 @@
+<DescribeTagsResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+    <requestId>fa7e0e44-df5e-49a0-98d7-5d4d19a29f95</requestId>
+    <tagSet>
+        <item>
+            <resourceId>i-4382922a</resourceId>
+         <resourceType>instance</resourceType>
+            <key>tag</key>
+            <value>test one</value>
+        </item>
+        <item>
+            <resourceId>i-4382922a</resourceId>
+         <resourceType>instance</resourceType>
+            <key>owner</key>
+            <value>libcloud</value>
+        </item>
+        <item>
+            <resourceId>i-4382922a</resourceId>
+         <resourceType>instance</resourceType>
+            <key>stack</key>
+            <value>Production</value>
+        </item>
+    </tagSet>
+</DescribeTagsResponse>

Modified: incubator/libcloud/trunk/test/test_ec2.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_ec2.py?rev=1067376&r1=1067375&r2=1067376&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_ec2.py (original)
+++ incubator/libcloud/trunk/test/test_ec2.py Sat Feb  5 01:49:50 2011
@@ -160,6 +160,15 @@ class EC2Tests(unittest.TestCase, TestCa
         self.assertEqual(availability_zone.zone_state, 'available')
         self.assertEqual(availability_zone.region_name, 'eu-west-1')
 
+    def test_ex_describe_tags(self):
+        node = Node('i-4382922a', None, None, None, None, self.driver)
+        tags = self.driver.ex_describe_tags(node)
+
+        self.assertEqual(len(tags), 3)
+        self.assertTrue('tag' in tags)
+        self.assertTrue('owner' in tags)
+        self.assertTrue('stack' in tags)
+
 class EC2MockHttp(MockHttp):
 
     fixtures = FileFixtures('ec2')
@@ -200,6 +209,10 @@ class EC2MockHttp(MockHttp):
         body = self.fixtures.load('terminate_instances.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _DescribeTags(self, method, url, body, headers):
+        body = self.fixtures.load('describe_tags.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 class EC2APSETests(EC2Tests):
     def setUp(self):
         EC2APSENodeDriver.connectionCls.conn_classes = (None, EC2MockHttp)



Mime
View raw message