You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/02/16 11:50:28 UTC
svn commit: r1071201 - in /incubator/libcloud/trunk: libcloud/drivers/ec2.py
test/fixtures/ec2/describe_addresses.xml test/test_ec2.py
Author: tomaz
Date: Wed Feb 16 10:50:28 2011
New Revision: 1071201
URL: http://svn.apache.org/viewvc?rev=1071201&view=rev
Log:
Add ex_describe_addresses method to the EC2 driver.
Added:
incubator/libcloud/trunk/test/fixtures/ec2/describe_addresses.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=1071201&r1=1071200&r2=1071201&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/ec2.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/ec2.py Wed Feb 16 10:50:28 2011
@@ -632,6 +632,29 @@ class EC2NodeDriver(NodeDriver):
tags[key] = value
return tags
+ def ex_describe_addresses(self, node):
+ """
+ Return a list of Elastic IP addresses associated with this node.
+
+ @type node: C{Node}
+ @param node: Node instance
+
+ @return list Elastic IP addresses attached to this node.
+ """
+ params = { 'Action': 'DescribeAddresses',
+ 'Filter.0.Name': 'instance-id',
+ 'Filter.0.Value.0': node.id
+ }
+
+ result = self.connection.request(self.path,
+ params=params.copy()).object
+
+ ip_addresses = []
+ for element in self._findall(result, 'addressesSet/item'):
+ ip_address = self._findtext(element, 'publicIp')
+ ip_addresses.append(ip_address)
+ return ip_addresses
+
def create_node(self, **kwargs):
"""Create a new EC2 node
Added: incubator/libcloud/trunk/test/fixtures/ec2/describe_addresses.xml
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/ec2/describe_addresses.xml?rev=1071201&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/ec2/describe_addresses.xml (added)
+++ incubator/libcloud/trunk/test/fixtures/ec2/describe_addresses.xml Wed Feb 16 10:50:28 2011
@@ -0,0 +1,9 @@
+<DescribeAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+ <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
+ <addressesSet>
+ <item>
+ <publicIp>1.2.3.4</publicIp>
+ <instanceId>i-4382922a</instanceId>
+ </item>
+ </addressesSet>
+</DescribeAddressesResponse>
Modified: incubator/libcloud/trunk/test/test_ec2.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_ec2.py?rev=1071201&r1=1071200&r2=1071201&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_ec2.py (original)
+++ incubator/libcloud/trunk/test/test_ec2.py Wed Feb 16 10:50:28 2011
@@ -156,6 +156,14 @@ class EC2Tests(unittest.TestCase, TestCa
self.assertTrue('owner' in tags)
self.assertTrue('stack' in tags)
+ def test_ex_describe_addresses(self):
+ node = Node('i-4382922a', None, None, None, None, self.driver)
+ ip_addresses = self.driver.ex_describe_addresses(node)
+
+ self.assertEqual(len(ip_addresses), 1)
+ self.assertEqual(ip_addresses[0], '1.2.3.4')
+
+
class EC2MockHttp(MockHttp):
fixtures = FileFixtures('ec2')
@@ -196,6 +204,11 @@ class EC2MockHttp(MockHttp):
body = self.fixtures.load('describe_tags.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _DescribeAddresses(self, method, url, body, headers):
+ body = self.fixtures.load('describe_addresses.xml')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+
class EC2APSETests(EC2Tests):
def setUp(self):
EC2APSENodeDriver.connectionCls.conn_classes = (None, EC2MockHttp)