Quota Management

Modifies the management extension for Quotas to include
usage information and update return values to current
paradigms.

Change-Id: I39122673082544e33bec0d3d5070df2c17aacb55
Depends-On: I6ca1a87fbc46781f83bc9b7bd33745783b8aaab1
Implements blueprint: quota-management
This commit is contained in:
Morgan Jones 2016-06-17 15:47:17 -04:00
parent a5f1ec074c
commit e0482b4d7d
5 changed files with 33 additions and 3 deletions

View File

@ -0,0 +1,4 @@
features:
- New quota management APIs for reviewing and changing
the quota for a particular tenant. Requires admin
privileges.

View File

@ -36,8 +36,11 @@ class QuotaController(wsgi.Controller):
"req : '%(req)s'\n\n") % {
"id": id, "req": req})
quotas = quota_engine.get_all_quotas_by_tenant(id)
return wsgi.Result(views.QuotaView(quotas).data(), 200)
usages = quota_engine.get_all_quota_usages_by_tenant(id)
limits = quota_engine.get_all_quotas_by_tenant(id)
map(lambda r: setattr(usages[r], "limit", limits[r].hard_limit),
usages.keys())
return wsgi.Result(views.QuotaUsageView(usages).data(), 200)
@admin_context
def update(self, req, body, tenant_id, id):

View File

@ -24,3 +24,16 @@ class QuotaView(object):
for resource_name, quota in self.quotas.items():
rtn[resource_name] = quota.hard_limit
return {'quotas': rtn}
class QuotaUsageView(object):
def __init__(self, usages):
self.usages = usages
def data(self):
return {'quotas': [{'resource': resource,
'in_use': usage['in_use'],
'reserved': usage['reserved'],
'limit': usage['limit']
} for resource, usage in self.usages.items()]}

View File

@ -274,6 +274,15 @@ class QuotaEngine(object):
return self._driver.get_all_quotas_by_tenant(tenant_id,
self._resources)
def get_all_quota_usages_by_tenant(self, tenant_id):
"""Retrieve the quota usages for the given tenant.
:param tenant_id: The ID of the tenant to return quota usages for.
"""
return self._driver.get_all_quota_usages_by_tenant(tenant_id,
self._resources)
def check_quotas(self, tenant_id, **deltas):
self._driver.check_quotas(tenant_id, self._resources, deltas)

View File

@ -277,7 +277,8 @@ class CreateInstanceQuotaTest(unittest.TestCase):
new_quotas = dbaas_admin.quota.update(self.test_info.user.tenant_id,
quota_dict)
verify_quota = dbaas_admin.quota.show(self.test_info.user.tenant_id)
set_quota = dbaas_admin.quota.show(self.test_info.user.tenant_id)
verify_quota = {q.resource: q.limit for q in set_quota}
assert_equal(new_quotas['instances'], quota_dict['instances'])
assert_equal(0, verify_quota['instances'])