Merge "Quota Management"
This commit is contained in:
commit
8ba72a5f3f
@ -0,0 +1,4 @@
|
|||||||
|
features:
|
||||||
|
- New quota management APIs for reviewing and changing
|
||||||
|
the quota for a particular tenant. Requires admin
|
||||||
|
privileges.
|
@ -36,8 +36,11 @@ class QuotaController(wsgi.Controller):
|
|||||||
"req : '%(req)s'\n\n") % {
|
"req : '%(req)s'\n\n") % {
|
||||||
"id": id, "req": req})
|
"id": id, "req": req})
|
||||||
|
|
||||||
quotas = quota_engine.get_all_quotas_by_tenant(id)
|
usages = quota_engine.get_all_quota_usages_by_tenant(id)
|
||||||
return wsgi.Result(views.QuotaView(quotas).data(), 200)
|
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
|
@admin_context
|
||||||
def update(self, req, body, tenant_id, id):
|
def update(self, req, body, tenant_id, id):
|
||||||
|
@ -24,3 +24,16 @@ class QuotaView(object):
|
|||||||
for resource_name, quota in self.quotas.items():
|
for resource_name, quota in self.quotas.items():
|
||||||
rtn[resource_name] = quota.hard_limit
|
rtn[resource_name] = quota.hard_limit
|
||||||
return {'quotas': rtn}
|
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()]}
|
||||||
|
@ -274,6 +274,15 @@ class QuotaEngine(object):
|
|||||||
return self._driver.get_all_quotas_by_tenant(tenant_id,
|
return self._driver.get_all_quotas_by_tenant(tenant_id,
|
||||||
self._resources)
|
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):
|
def check_quotas(self, tenant_id, **deltas):
|
||||||
self._driver.check_quotas(tenant_id, self._resources, deltas)
|
self._driver.check_quotas(tenant_id, self._resources, deltas)
|
||||||
|
|
||||||
|
@ -279,7 +279,8 @@ class CreateInstanceQuotaTest(unittest.TestCase):
|
|||||||
new_quotas = dbaas_admin.quota.update(self.test_info.user.tenant_id,
|
new_quotas = dbaas_admin.quota.update(self.test_info.user.tenant_id,
|
||||||
quota_dict)
|
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(new_quotas['instances'], quota_dict['instances'])
|
||||||
assert_equal(0, verify_quota['instances'])
|
assert_equal(0, verify_quota['instances'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user