diff options
| author | Alex Meade <alex.meade@rackspace.com> | 2011-05-17 11:27:41 -0400 |
|---|---|---|
| committer | Alex Meade <alex.meade@rackspace.com> | 2011-05-17 11:27:41 -0400 |
| commit | 6fc708b463e47de560fe388ada0639eb2b2383d5 (patch) | |
| tree | fe1c3f324543b0acc45d36b29f5c413a6f809801 /nova/api | |
| parent | b1e14b1451a860871c20e8a5a733e89c72bdccd5 (diff) | |
| parent | 8cf2087747ab87fec0e1f7cc3d57ed1fa5065749 (diff) | |
| download | nova-6fc708b463e47de560fe388ada0639eb2b2383d5.tar.gz nova-6fc708b463e47de560fe388ada0639eb2b2383d5.tar.xz nova-6fc708b463e47de560fe388ada0639eb2b2383d5.zip | |
Implemented builder for absolute limits and updated tests
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/limits.py | 5 | ||||
| -rw-r--r-- | nova/api/openstack/views/limits.py | 40 |
2 files changed, 43 insertions, 2 deletions
diff --git a/nova/api/openstack/limits.py b/nova/api/openstack/limits.py index 47bc238f1..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", }, }, } @@ -64,6 +66,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 abs_limits = {} rate_limits = req.environ.get("nova.limits", []) 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 |
