diff --git a/releasenotes/notes/quota-management-3792cbc25ebe16bb.yaml b/releasenotes/notes/quota-management-3792cbc25ebe16bb.yaml new file mode 100644 index 0000000000..3cee10e055 --- /dev/null +++ b/releasenotes/notes/quota-management-3792cbc25ebe16bb.yaml @@ -0,0 +1,4 @@ +features: + - New quota management APIs for reviewing and changing + the quota for a particular tenant. Requires admin + privileges. diff --git a/trove/extensions/mgmt/quota/service.py b/trove/extensions/mgmt/quota/service.py index 0859a726da..8c0c8ff202 100644 --- a/trove/extensions/mgmt/quota/service.py +++ b/trove/extensions/mgmt/quota/service.py @@ -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): diff --git a/trove/extensions/mgmt/quota/views.py b/trove/extensions/mgmt/quota/views.py index e723106383..1d8d341c8e 100644 --- a/trove/extensions/mgmt/quota/views.py +++ b/trove/extensions/mgmt/quota/views.py @@ -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()]} diff --git a/trove/quota/quota.py b/trove/quota/quota.py index eeb97eaffe..1cb48cd56e 100644 --- a/trove/quota/quota.py +++ b/trove/quota/quota.py @@ -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) diff --git a/trove/tests/api/instances.py b/trove/tests/api/instances.py index 22a6e59859..d9afeecf2b 100644 --- a/trove/tests/api/instances.py +++ b/trove/tests/api/instances.py @@ -279,7 +279,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'])