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 2013/12/17 12:04:43 UTC
[2/4] git commit: Add ex_get_limits method to EC2 driver.
Add ex_get_limits method to EC2 driver.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ac14b3bb
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ac14b3bb
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ac14b3bb
Branch: refs/heads/trunk
Commit: ac14b3bbf8358323f90da4c07c5037f1939688c5
Parents: 88c468a
Author: Tomaz Muraus <to...@apache.org>
Authored: Mon Dec 16 23:37:21 2013 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Dec 16 23:37:21 2013 +0100
----------------------------------------------------------------------
libcloud/compute/drivers/ec2.py | 33 ++++++++++++++++++++
.../ec2/describe_account_attributes.xml | 30 ++++++++++++++++++
libcloud/test/compute/test_ec2.py | 11 +++++++
3 files changed, 74 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/ac14b3bb/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 3242922..a2d148e 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -793,6 +793,39 @@ class BaseEC2NodeDriver(NodeDriver):
)
return images
+ def ex_get_limits(self):
+ """
+ Retrieve account resource limits.
+
+ :rtype: ``dict``
+ """
+ attributes = ['max-instances', 'max-elastic-ips',
+ 'vpc-max-elastic-ips']
+ params = {}
+ params['Action'] = 'DescribeAccountAttributes'
+
+ for index, attribute in enumerate(attributes):
+ params['AttributeName.%s' % (index)] = attribute
+
+ response = self.connection.request(self.path, params=params)
+ data = response.object
+
+ elems = data.findall(fixxpath(xpath='accountAttributeSet/item',
+ namespace=NAMESPACE))
+
+ result = {'resource': {}}
+
+ for elem in elems:
+ name = findtext(element=elem, xpath='attributeName',
+ namespace=NAMESPACE)
+ value = findtext(element=elem,
+ xpath='attributeValueSet/item/attributeValue',
+ namespace=NAMESPACE)
+
+ result['resource'][name] = int(value)
+
+ return result
+
def list_locations(self):
locations = []
for index, availability_zone in \
http://git-wip-us.apache.org/repos/asf/libcloud/blob/ac14b3bb/libcloud/test/compute/fixtures/ec2/describe_account_attributes.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/describe_account_attributes.xml b/libcloud/test/compute/fixtures/ec2/describe_account_attributes.xml
new file mode 100644
index 0000000..bca2e42
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ec2/describe_account_attributes.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<DescribeAccountAttributesResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
+ <requestId>a00adaf6-f86c-48eb-85f8-7ac470ae993d</requestId>
+ <accountAttributeSet>
+ <item>
+ <attributeName>max-instances</attributeName>
+ <attributeValueSet>
+ <item>
+ <attributeValue>20</attributeValue>
+ </item>
+ </attributeValueSet>
+ </item>
+ <item>
+ <attributeName>max-elastic-ips</attributeName>
+ <attributeValueSet>
+ <item>
+ <attributeValue>5</attributeValue>
+ </item>
+ </attributeValueSet>
+ </item>
+ <item>
+ <attributeName>vpc-max-elastic-ips</attributeName>
+ <attributeValueSet>
+ <item>
+ <attributeValue>5</attributeValue>
+ </item>
+ </attributeValueSet>
+ </item>
+ </accountAttributeSet>
+</DescribeAccountAttributesResponse>
http://git-wip-us.apache.org/repos/asf/libcloud/blob/ac14b3bb/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index f516059..4e31803 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -701,6 +701,13 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
self.assertEqual(metadata['Num'], '42')
self.assertEqual(len(metadata), 3)
+ def test_ex_get_limits(self):
+ limits = self.driver.ex_get_limits()
+
+ expected = {'max-instances': 20, 'vpc-max-elastic-ips': 5,
+ 'max-elastic-ips': 5}
+ self.assertEqual(limits['resource'], expected)
+
class EC2USWest1Tests(EC2Tests):
region = 'us-west-1'
@@ -968,6 +975,10 @@ class EC2MockHttp(MockHttpTestCase):
body = self.fixtures.load('modify_image_attribute.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _DescribeAccountAttributes(self, method, url, body, headers):
+ body = self.fixtures.load('describe_account_attributes.xml')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
class EucMockHttp(EC2MockHttp):
fixtures = ComputeFileFixtures('ec2')