libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] git commit: LIBCLOUD-507: Add ex_limits call to return a dictionary or resource limits associated with the account. Examples of resource limits would be the maximum number of instances, volumes, snapshots and networks.
Date Sun, 02 Feb 2014 17:15:34 GMT
Updated Branches:
  refs/heads/trunk 8eb07e4a1 -> 2840b6f5a


LIBCLOUD-507: Add ex_limits call to return a dictionary or resource limits associated with
the account. Examples of resource limits would be the maximum number of instances, volumes,
snapshots and networks.

Closes #240.

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


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

Branch: refs/heads/trunk
Commit: ee8d43ccfc136ef6b7c4113c683042c2093ab965
Parents: 8eb07e4
Author: Chris DeRamus <chris@divvycloud.com>
Authored: Sun Feb 2 10:18:12 2014 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Sun Feb 2 18:11:21 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/cloudstack.py          | 33 ++++++++++++++++++++
 .../cloudstack/listResourceLimits_default.json  |  1 +
 libcloud/test/compute/test_cloudstack.py        | 11 +++++++
 3 files changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/ee8d43cc/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index 5c49dc3..4e6a36b 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -1482,6 +1482,39 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
                                   zoneid=location.id,
                                   params=params)
 
+    def ex_limits(self):
+        """
+        Extra call to get account's resource limits, such as
+        the amount of instances, volumes, snapshots and networks.
+
+        CloudStack uses integers as the resource type so we will convert
+        them to a more human readable string using the resource map
+
+        :return: dict
+        :rtype: ``dict``
+        """
+
+        result = self._sync_request(command='listResourceLimits',
+                                    method='GET')
+
+        limits = {}
+        resource_map = {
+            0: 'max_instances',
+            1: 'max_public_ips',
+            2: 'max_volumes',
+            3: 'max_snapshots',
+            4: 'max_images',
+            5: 'max_projects',
+            6: 'max_networks',
+            7: 'max_vpc'
+        }
+
+        for limit in result.get('resourcelimit', []):
+            resource = resource_map[int(limit['resourcetype'])]
+            limits[resource] = int(limit['max'])
+
+        return limits
+
     def _to_node(self, data, public_ips=None):
         """
         :param data: Node data object.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ee8d43cc/libcloud/test/compute/fixtures/cloudstack/listResourceLimits_default.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/listResourceLimits_default.json b/libcloud/test/compute/fixtures/cloudstack/listResourceLimits_default.json
new file mode 100644
index 0000000..2f0dd87
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/listResourceLimits_default.json
@@ -0,0 +1 @@
+{ "listresourcelimitsresponse" : { "count":8 ,"resourcelimit" : [  {"account":"fakeuser@mycompany.com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"0","max":20},
{"account":"fakeuser@mycompany.com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"1","max":-1},
{"account":"fakeuser@mycompany.com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"2","max":20},
{"account":"fakeuser@mycompany.com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"3","max":20},
{"account":"fakeuser@mycompany.com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"4","max":20},
{"account":"fakeuser@mycompany.com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"5","max":-1},
{"account":"fakeuser@mycompany
 .com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"6","max":20},
{"account":"fakeuser@mycompany.com","domainid":"bd0b5c60-cd1e-4bf0-8d90-72c4b0de7520","domain":"fakeuser@mycompany.com","resourcetype":"7","max":20}
] } }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ee8d43cc/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index 146241e..c54d423 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -485,6 +485,17 @@ class CloudStackCommonTestCase(TestCaseMixin):
         self.assertEqual(rule.private_end_port, private_end_port)
         self.assertEqual(len(node.extra['port_forwarding_rules']), 2)
 
+    def test_ex_limits(self):
+        limits = self.driver.ex_limits()
+        self.assertEqual(limits['max_images'], 20)
+        self.assertEqual(limits['max_networks'], 20)
+        self.assertEqual(limits['max_public_ips'], -1)
+        self.assertEqual(limits['max_vpc'], 20)
+        self.assertEqual(limits['max_instances'], 20)
+        self.assertEqual(limits['max_projects'], -1)
+        self.assertEqual(limits['max_volumes'], 20)
+        self.assertEqual(limits['max_snapshots'], 20)
+
 
 class CloudStackTestCase(CloudStackCommonTestCase, unittest.TestCase):
     def test_driver_instantiation(self):


Mime
View raw message