Return-Path: X-Original-To: apmail-libcloud-commits-archive@www.apache.org Delivered-To: apmail-libcloud-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AA68910B22 for ; Sun, 2 Feb 2014 17:15:35 +0000 (UTC) Received: (qmail 78757 invoked by uid 500); 2 Feb 2014 17:15:35 -0000 Delivered-To: apmail-libcloud-commits-archive@libcloud.apache.org Received: (qmail 78718 invoked by uid 500); 2 Feb 2014 17:15:35 -0000 Mailing-List: contact commits-help@libcloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@libcloud.apache.org Delivered-To: mailing list commits@libcloud.apache.org Received: (qmail 78710 invoked by uid 99); 2 Feb 2014 17:15:34 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Feb 2014 17:15:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 88B918C1235; Sun, 2 Feb 2014 17:15:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tomaz@apache.org To: commits@libcloud.apache.org Date: Sun, 02 Feb 2014 17:15:34 -0000 Message-Id: <33d88016782e4b4f84fefe3a34e914b2@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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. 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 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 Authored: Sun Feb 2 10:18:12 2014 -0500 Committer: Tomaz Muraus 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):