diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-06-11 20:39:00 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-06-11 20:39:00 +0000 |
| commit | 00d0e2c187ade3a9acdbdb08c78956bcff8e09ac (patch) | |
| tree | 86c58c1c900a29951bf93e6ebfac68c0a75886bb /nova/api | |
| parent | 9b5e206027149861de86585690bc3d5141ec240e (diff) | |
| parent | 9f9c40d56954baf183968b6ea9db9aec62f4c064 (diff) | |
| download | nova-00d0e2c187ade3a9acdbdb08c78956bcff8e09ac.tar.gz nova-00d0e2c187ade3a9acdbdb08c78956bcff8e09ac.tar.xz nova-00d0e2c187ade3a9acdbdb08c78956bcff8e09ac.zip | |
Merge "Return Customer's Quota Usage through Admin API"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/used_limits.py | 23 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/used_limits_for_admin.py | 27 |
2 files changed, 47 insertions, 3 deletions
diff --git a/nova/api/openstack/compute/contrib/used_limits.py b/nova/api/openstack/compute/contrib/used_limits.py index e00f0a9eb..5a90a9def 100644 --- a/nova/api/openstack/compute/contrib/used_limits.py +++ b/nova/api/openstack/compute/contrib/used_limits.py @@ -26,6 +26,8 @@ QUOTAS = quota.QUOTAS XMLNS = "http://docs.openstack.org/compute/ext/used_limits/api/v1.1" ALIAS = "os-used-limits" authorize = extensions.soft_extension_authorizer('compute', 'used_limits') +authorize_for_admin = extensions.extension_authorizer('compute', + 'used_limits_for_admin') class UsedLimitsTemplate(xmlutil.TemplateBuilder): @@ -37,6 +39,9 @@ class UsedLimitsTemplate(xmlutil.TemplateBuilder): class UsedLimitsController(wsgi.Controller): + def __init__(self, ext_mgr): + self.ext_mgr = ext_mgr + @staticmethod def _reserved(req): try: @@ -48,8 +53,8 @@ class UsedLimitsController(wsgi.Controller): def index(self, req, resp_obj): resp_obj.attach(xml=UsedLimitsTemplate()) context = req.environ['nova.context'] - quotas = QUOTAS.get_project_quotas(context, context.project_id, - usages=True) + project_id = self._project_id(context, req) + quotas = QUOTAS.get_project_quotas(context, project_id, usages=True) quota_map = { 'totalRAMUsed': 'ram', 'totalCoresUsed': 'cores', @@ -66,6 +71,18 @@ class UsedLimitsController(wsgi.Controller): resp_obj.obj['limits']['absolute'].update(used_limits) + def _project_id(self, context, req): + if self.ext_mgr.is_loaded('os-used-limits-for-admin'): + if 'tenant_id' in req.GET: + tenant_id = req.GET.get('tenant_id') + target = { + 'project_id': tenant_id, + 'user_id': context.user_id + } + authorize_for_admin(context, target=target) + return tenant_id + return context.project_id + class Used_limits(extensions.ExtensionDescriptor): """Provide data on limited resources that are being used.""" @@ -76,7 +93,7 @@ class Used_limits(extensions.ExtensionDescriptor): updated = "2012-07-13T00:00:00+00:00" def get_controller_extensions(self): - controller = UsedLimitsController() + controller = UsedLimitsController(self.ext_mgr) limits_ext = extensions.ControllerExtension(self, 'limits', controller=controller) return [limits_ext] diff --git a/nova/api/openstack/compute/contrib/used_limits_for_admin.py b/nova/api/openstack/compute/contrib/used_limits_for_admin.py new file mode 100644 index 000000000..a6ec9c002 --- /dev/null +++ b/nova/api/openstack/compute/contrib/used_limits_for_admin.py @@ -0,0 +1,27 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License + +from nova.api.openstack import extensions + + +class Used_limits_for_admin(extensions.ExtensionDescriptor): + """Provide data to admin on limited resources used by other tenants.""" + + name = "UsedLimitsForAdmin" + alias = "os-used-limits-for-admin" + namespace = ("http://docs.openstack.org/compute/ext/used_limits_for_admin" + "/api/v1.1") + updated = "2013-05-02T00:00:00+00:00" |
