summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorMahesh K P <maheshp@thoughtworks.com>2013-04-17 11:41:41 +0530
committerNavneet Kumar <navneetk@thoughtworks.com>2013-05-17 10:42:07 +0530
commit9f9c40d56954baf183968b6ea9db9aec62f4c064 (patch)
tree4cc12f795f7fa8cd6e8329d6915acaf543a4a164 /nova/api
parent1d5d58c96974a2e5742887aafb48675084fbfd48 (diff)
downloadnova-9f9c40d56954baf183968b6ea9db9aec62f4c064.tar.gz
nova-9f9c40d56954baf183968b6ea9db9aec62f4c064.tar.xz
nova-9f9c40d56954baf183968b6ea9db9aec62f4c064.zip
Return Customer's Quota Usage through Admin API
DocImpact: This patch adds an extension 'UsedLimitsForAdmin'. If this extention is enabled then it extends the used limits API behavior, such that admin can fetch the details of any customer's quota usage by passing the customer's tenant id in query parameters.The API signature for the same is 'v2/{tenant_id}/limits?tenant_id={customer_tenant_id}' Change-Id: I89b8b5083e46b899458407426c89a3865e960faa Implements: blueprint customer-quota-through-admin-api
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/used_limits.py23
-rw-r--r--nova/api/openstack/compute/contrib/used_limits_for_admin.py27
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"