diff options
| author | Mark Washenberger <mark.washenberger@rackspace.com> | 2011-05-17 15:45:22 -0400 |
|---|---|---|
| committer | Mark Washenberger <mark.washenberger@rackspace.com> | 2011-05-17 15:45:22 -0400 |
| commit | 7c06d37f952e1f02bf1bb81809330b1b6737c2d5 (patch) | |
| tree | a5e7eb006a06fe78723175552b36764c60b8bc91 | |
| parent | 1bc00ba6e7d13ab3533297ecda6c10965776dd8a (diff) | |
| parent | 6fc708b463e47de560fe388ada0639eb2b2383d5 (diff) | |
merge ram-limits
| -rw-r--r-- | nova/api/openstack/limits.py | 7 | ||||
| -rw-r--r-- | nova/api/openstack/views/limits.py | 40 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_limits.py | 4 |
3 files changed, 45 insertions, 6 deletions
diff --git a/nova/api/openstack/limits.py b/nova/api/openstack/limits.py index f30c9ec59..cf96b1bce 100644 --- a/nova/api/openstack/limits.py +++ b/nova/api/openstack/limits.py @@ -53,9 +53,11 @@ class LimitsController(common.OpenstackController): "attributes": { "limit": ["verb", "URI", "uri", "regex", "value", "unit", "resetTime", "next-available", "remaining", "name"], + "absolute_limit": ["limit", "value"], }, "plurals": { "rate": "limit", + "absolute": "absolute_limit", }, }, } @@ -65,8 +67,9 @@ class LimitsController(common.OpenstackController): Return all global and rate limit information. """ # TODO(alex.meade) make this work - project_quota = quota.get_project_quota(...) - abs_limits = project_quota.limits + #project_quota = quota.get_project_quota(...) + #abs_limits = project_quota.limits + abs_limits = {} rate_limits = req.environ.get("nova.limits", []) builder = self._get_view_builder(req) diff --git a/nova/api/openstack/views/limits.py b/nova/api/openstack/views/limits.py index 552db39ee..7fae2d166 100644 --- a/nova/api/openstack/views/limits.py +++ b/nova/api/openstack/views/limits.py @@ -36,6 +36,15 @@ class ViewBuilder(object): return output + def _build_absolute_limits(self, absolute_limits): + raise NotImplementedError() + + def _build_rate_limits(self, rate_limits): + raise NotImplementedError() + + def _build_rate_limit(self, rate_limit): + raise NotImplementedError() + class ViewBuilderV10(ViewBuilder): """Openstack API v1.0 limits view builder.""" @@ -96,5 +105,32 @@ class ViewBuilderV11(ViewBuilder): "next-available": rate_limit["resetTime"], } - def _build_absolute_limits(self, absolute_limit): - return {} + def _build_absolute_limits(self, absolute_limits): + """Builder for absolute limits + + absolute_limits should be given as a dict of limits. + For example: {"ram": 512, "gigabytes": 1024}. + + """ + limits = [] + #loops through absolute limits and their values + for absolute_limit_key, absolute_limit_value \ + in absolute_limits.items(): + _abs_limit = None + + # check for existing key + for limit in limits: + if limit["limit"] == absolute_limit_key: + _abs_limit = limit + break + + # ensure we have a key if we didn't find one + if not _abs_limit: + _abs_limit = { + "limit": absolute_limit_key, + "value": absolute_limit_value, + } + + limits.append(_abs_limit) + + return limits diff --git a/nova/tests/api/openstack/test_limits.py b/nova/tests/api/openstack/test_limits.py index 45bd4d501..2689c7a24 100644 --- a/nova/tests/api/openstack/test_limits.py +++ b/nova/tests/api/openstack/test_limits.py @@ -208,7 +208,7 @@ class LimitsControllerV11Test(BaseLimitTestSuite): expected = { "limits": { "rate": [], - "absolute": {}, + "absolute": [], }, } body = json.loads(response.body) @@ -257,7 +257,7 @@ class LimitsControllerV11Test(BaseLimitTestSuite): }, ], - "absolute": {}, + "absolute": [], }, } body = json.loads(response.body) |
