From 0b2de530053d93cdd9dc4ea08c482325321f7ff7 Mon Sep 17 00:00:00 2001 From: Roman Podoliaka Date: Wed, 29 Jun 2016 14:53:18 +0300 Subject: [PATCH] Make it possible to list quotas with details Allow requests to /os-quota-sets/{tenant_id}/detail for listing of detailed informantion on quotas, which also includes reserved and in-use values in addition to limit ones provided by /os-quota-sets/{tenant_id} Change-Id: I31e939c8eedee1b3b375e1d02cc21ca15dd9932a Closes-Bug: #1596891 --- novaclient/tests/unit/fixture_data/quotas.py | 2 +- novaclient/tests/unit/v2/fakes.py | 76 ++++++++++++++++++++ novaclient/tests/unit/v2/test_quotas.py | 14 ++++ novaclient/tests/unit/v2/test_shell.py | 17 +++++ novaclient/v2/quotas.py | 14 ++-- novaclient/v2/shell.py | 8 ++- 6 files changed, 125 insertions(+), 6 deletions(-) diff --git a/novaclient/tests/unit/fixture_data/quotas.py b/novaclient/tests/unit/fixture_data/quotas.py index 487cfa003..5051bf3ed 100644 --- a/novaclient/tests/unit/fixture_data/quotas.py +++ b/novaclient/tests/unit/fixture_data/quotas.py @@ -26,7 +26,7 @@ class V1(base.Fixture): self.headers = self.json_headers for u in ('test', 'tenant-id', 'tenant-id/defaults', - '%s/defaults' % uuid2): + '%s/defaults' % uuid2, 'test/detail'): self.requests.register_uri('GET', self.url(u), json=test_json, headers=self.headers) diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py index baf345236..edaeafb23 100644 --- a/novaclient/tests/unit/v2/fakes.py +++ b/novaclient/tests/unit/v2/fakes.py @@ -1259,6 +1259,82 @@ class FakeHTTPClient(base_client.HTTPClient): 'security_groups': 1, 'security_group_rules': 1}}) + def get_os_quota_sets_97f4c221bff44578b0300df4ef119353_detail(self, **kw): + return (200, {}, { + 'quota_set': { + 'tenant_id': '97f4c221bff44578b0300df4ef119353', + 'cores': { + 'in_use': 0, + 'limit': 20, + 'reserved': 0 + }, + 'fixed_ips': { + 'in_use': 0, + 'limit': -1, + 'reserved': 0 + }, + 'floating_ips': { + 'in_use': 0, + 'limit': 10, + 'reserved': 0 + }, + 'injected_file_content_bytes': { + 'in_use': 0, + 'limit': 10240, + 'reserved': 0 + }, + 'injected_file_path_bytes': { + 'in_use': 0, + 'limit': 255, + 'reserved': 0 + }, + 'injected_files': { + 'in_use': 0, + 'limit': 5, + 'reserved': 0 + }, + 'instances': { + 'in_use': 0, + 'limit': 10, + 'reserved': 0 + }, + 'key_pairs': { + 'in_use': 0, + 'limit': 100, + 'reserved': 0 + }, + 'metadata_items': { + 'in_use': 0, + 'limit': 128, + 'reserved': 0 + }, + 'ram': { + 'in_use': 0, + 'limit': 51200, + 'reserved': 0 + }, + 'security_group_rules': { + 'in_use': 0, + 'limit': 20, + 'reserved': 0 + }, + 'security_groups': { + 'in_use': 0, + 'limit': 10, + 'reserved': 0 + }, + 'server_group_members': { + 'in_use': 0, + 'limit': 10, + 'reserved': 0 + }, + 'server_groups': { + 'in_use': 0, + 'limit': 10, + 'reserved': 0 + } + }}) + def get_os_quota_sets_97f4c221bff44578b0300df4ef119353_defaults(self): return (200, {}, { 'quota_set': { diff --git a/novaclient/tests/unit/v2/test_quotas.py b/novaclient/tests/unit/v2/test_quotas.py index d8144a55c..0ed766a03 100644 --- a/novaclient/tests/unit/v2/test_quotas.py +++ b/novaclient/tests/unit/v2/test_quotas.py @@ -38,6 +38,20 @@ class QuotaSetsTest(utils.FixturedTestCase): url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id) self.assert_called('GET', url) + def test_tenant_quotas_get_detail(self): + tenant_id = 'test' + q = self.cs.quotas.get(tenant_id, detail=True) + self.assert_request_id(q, fakes.FAKE_REQUEST_ID_LIST) + self.assert_called('GET', '/os-quota-sets/%s/detail' % tenant_id) + + def test_user_quotas_get_detail(self): + tenant_id = 'test' + user_id = 'fake_user' + q = self.cs.quotas.get(tenant_id, user_id=user_id, detail=True) + self.assert_request_id(q, fakes.FAKE_REQUEST_ID_LIST) + url = '/os-quota-sets/%s/detail?user_id=%s' % (tenant_id, user_id) + self.assert_called('GET', url) + def test_tenant_quotas_defaults(self): tenant_id = '97f4c221bff44578b0300df4ef119353' q = self.cs.quotas.defaults(tenant_id) diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 8790b2a2b..d68ecc90b 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -2141,6 +2141,14 @@ class ShellTest(utils.TestCase): 'GET', '/os-quota-sets/97f4c221bff44578b0300df4ef119353') + def test_quota_show_detail(self): + self.run_command( + 'quota-show --tenant ' + '97f4c221bff44578b0300df4ef119353 --detail') + self.assert_called( + 'GET', + '/os-quota-sets/97f4c221bff44578b0300df4ef119353/detail') + def test_user_quota_show(self): self.run_command( 'quota-show --tenant ' @@ -2149,6 +2157,15 @@ class ShellTest(utils.TestCase): 'GET', '/os-quota-sets/97f4c221bff44578b0300df4ef119353?user_id=u1') + def test_user_quota_show_detail(self): + self.run_command( + 'quota-show --tenant ' + '97f4c221bff44578b0300df4ef119353 --user u1 --detail') + self.assert_called( + 'GET', + '/os-quota-sets/97f4c221bff44578b0300df4ef119353/detail' + '?user_id=u1') + def test_quota_show_no_tenant(self): self.run_command('quota-show') self.assert_called('GET', '/os-quota-sets/tenant_id') diff --git a/novaclient/v2/quotas.py b/novaclient/v2/quotas.py index e05435b35..1aee5b17e 100644 --- a/novaclient/v2/quotas.py +++ b/novaclient/v2/quotas.py @@ -32,14 +32,20 @@ class QuotaSet(base.Resource): class QuotaSetManager(base.Manager): resource_class = QuotaSet - def get(self, tenant_id, user_id=None): + def get(self, tenant_id, user_id=None, detail=False): + url = '/os-quota-sets/%(tenant_id)s' + if detail: + url += '/detail' + if hasattr(tenant_id, 'tenant_id'): tenant_id = tenant_id.tenant_id if user_id: - url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id) + params = {'tenant_id': tenant_id, 'user_id': user_id} + url += '?user_id=%(user_id)s' else: - url = '/os-quota-sets/%s' % tenant_id - return self._get(url, "quota_set") + params = {'tenant_id': tenant_id} + + return self._get(url % params, "quota_set") def update(self, tenant_id, **kwargs): diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 1aeba676f..ceb6dfe92 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -4367,6 +4367,11 @@ def _quota_update(manager, identifier, args): metavar='', default=None, help=_('ID of user to list the quotas for.')) +@utils.arg( + '--detail', + action='store_true', + default=False, + help=_('Show detailed info (limit, reserved, in-use).')) def do_quota_show(cs, args): """List the quotas for a tenant/user.""" @@ -4378,7 +4383,8 @@ def do_quota_show(cs, args): else: project_id = cs.client.tenant_id - _quota_show(cs.quotas.get(project_id, user_id=args.user)) + _quota_show(cs.quotas.get(project_id, user_id=args.user, + detail=args.detail)) @utils.arg(