Support quota show for current project
The "os quota show" command "<project/class>" argument is now optional. If not specified, the user's current project is used. This allows non-admin users to show quotas for their current project. Change-Id: I602d4cc09c9d29ce84271eff78137f8810cb1a47 Closes-Bug: #1572733
This commit is contained in:
parent
0d3a06db1c
commit
27024d70af
@ -4,7 +4,7 @@ quota
|
|||||||
|
|
||||||
Resource quotas appear in multiple APIs, OpenStackClient presents them as a single object with multiple properties.
|
Resource quotas appear in multiple APIs, OpenStackClient presents them as a single object with multiple properties.
|
||||||
|
|
||||||
Compute v2, Block Storage v1
|
Block Storage v1, Compute v2, Network v2
|
||||||
|
|
||||||
quota set
|
quota set
|
||||||
---------
|
---------
|
||||||
@ -129,14 +129,14 @@ Set quotas for class
|
|||||||
quota show
|
quota show
|
||||||
----------
|
----------
|
||||||
|
|
||||||
Show quotas for project
|
Show quotas for project or class
|
||||||
|
|
||||||
.. program:: quota show
|
.. program:: quota show
|
||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
os quota show
|
os quota show
|
||||||
[--default]
|
[--default]
|
||||||
<project>
|
[<project>]
|
||||||
|
|
||||||
|
|
||||||
.. option:: --default
|
.. option:: --default
|
||||||
@ -146,13 +146,13 @@ Show quotas for project
|
|||||||
.. _quota_show-project:
|
.. _quota_show-project:
|
||||||
.. describe:: <project>
|
.. describe:: <project>
|
||||||
|
|
||||||
Show quotas for class
|
Show quotas for this project (name or ID)
|
||||||
|
|
||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
os quota show
|
os quota show
|
||||||
--class
|
--class
|
||||||
<class>
|
[<class>]
|
||||||
|
|
||||||
.. option:: --class
|
.. option:: --class
|
||||||
|
|
||||||
@ -161,4 +161,4 @@ Show quotas for project
|
|||||||
.. _quota_show-class:
|
.. _quota_show-class:
|
||||||
.. describe:: <class>
|
.. describe:: <class>
|
||||||
|
|
||||||
Class to show
|
Show quotas for this class (name or ID)
|
||||||
|
@ -36,3 +36,8 @@ class QuotaTests(test.TestCase):
|
|||||||
raw_output = self.openstack('quota show ' + self.PROJECT_NAME)
|
raw_output = self.openstack('quota show ' + self.PROJECT_NAME)
|
||||||
for expected_field in self.EXPECTED_FIELDS:
|
for expected_field in self.EXPECTED_FIELDS:
|
||||||
self.assertIn(expected_field, raw_output)
|
self.assertIn(expected_field, raw_output)
|
||||||
|
|
||||||
|
def test_quota_show_default_project(self):
|
||||||
|
raw_output = self.openstack('quota show')
|
||||||
|
for expected_field in self.EXPECTED_FIELDS:
|
||||||
|
self.assertIn(expected_field, raw_output)
|
||||||
|
@ -145,7 +145,8 @@ class ShowQuota(command.ShowOne):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'project',
|
'project',
|
||||||
metavar='<project/class>',
|
metavar='<project/class>',
|
||||||
help='Show this project or class (name/ID)',
|
nargs='?',
|
||||||
|
help='Show quotas for this project or class (name or ID)',
|
||||||
)
|
)
|
||||||
type_group = parser.add_mutually_exclusive_group()
|
type_group = parser.add_mutually_exclusive_group()
|
||||||
type_group.add_argument(
|
type_group.add_argument(
|
||||||
@ -164,12 +165,22 @@ class ShowQuota(command.ShowOne):
|
|||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
def _get_project(self, parsed_args):
|
||||||
|
if parsed_args.project is not None:
|
||||||
|
identity_client = self.app.client_manager.identity
|
||||||
|
project = utils.find_resource(
|
||||||
|
identity_client.projects,
|
||||||
|
parsed_args.project,
|
||||||
|
).id
|
||||||
|
elif self.app.client_manager.auth_ref:
|
||||||
|
# Get the project from the current auth
|
||||||
|
project = self.app.client_manager.auth_ref.project_id
|
||||||
|
else:
|
||||||
|
project = None
|
||||||
|
return project
|
||||||
|
|
||||||
def get_compute_volume_quota(self, client, parsed_args):
|
def get_compute_volume_quota(self, client, parsed_args):
|
||||||
identity_client = self.app.client_manager.identity
|
project = self._get_project(parsed_args)
|
||||||
project = utils.find_resource(
|
|
||||||
identity_client.projects,
|
|
||||||
parsed_args.project,
|
|
||||||
).id
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if parsed_args.quota_class:
|
if parsed_args.quota_class:
|
||||||
@ -189,11 +200,7 @@ class ShowQuota(command.ShowOne):
|
|||||||
if parsed_args.quota_class or parsed_args.default:
|
if parsed_args.quota_class or parsed_args.default:
|
||||||
return {}
|
return {}
|
||||||
if self.app.client_manager.is_network_endpoint_enabled():
|
if self.app.client_manager.is_network_endpoint_enabled():
|
||||||
identity_client = self.app.client_manager.identity
|
project = self._get_project(parsed_args)
|
||||||
project = utils.find_resource(
|
|
||||||
identity_client.projects,
|
|
||||||
parsed_args.project,
|
|
||||||
).id
|
|
||||||
return self.app.client_manager.network.get_quota(project)
|
return self.app.client_manager.network.get_quota(project)
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
@ -59,6 +59,7 @@ class TestQuota(compute_fakes.TestComputev2):
|
|||||||
self.service_catalog_mock = \
|
self.service_catalog_mock = \
|
||||||
self.app.client_manager.auth_ref.service_catalog
|
self.app.client_manager.auth_ref.service_catalog
|
||||||
self.service_catalog_mock.reset_mock()
|
self.service_catalog_mock.reset_mock()
|
||||||
|
self.app.client_manager.auth_ref.project_id = identity_fakes.project_id
|
||||||
|
|
||||||
|
|
||||||
class TestQuotaSet(TestQuota):
|
class TestQuotaSet(TestQuota):
|
||||||
@ -304,3 +305,13 @@ class TestQuotaShow(TestQuota):
|
|||||||
identity_fakes.project_id)
|
identity_fakes.project_id)
|
||||||
self.volume_quotas_class_mock.get.assert_called_with(
|
self.volume_quotas_class_mock.get.assert_called_with(
|
||||||
identity_fakes.project_id)
|
identity_fakes.project_id)
|
||||||
|
|
||||||
|
def test_quota_show_no_project(self):
|
||||||
|
parsed_args = self.check_parser(self.cmd, [], [])
|
||||||
|
|
||||||
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.quotas_mock.get.assert_called_with(identity_fakes.project_id)
|
||||||
|
self.volume_quotas_mock.get.assert_called_with(
|
||||||
|
identity_fakes.project_id)
|
||||||
|
self.network.get_quota.assert_called_with(identity_fakes.project_id)
|
||||||
|
6
releasenotes/notes/bug-1572733-874b37a7fa8292d0.yaml
Normal file
6
releasenotes/notes/bug-1572733-874b37a7fa8292d0.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- The ``quota show`` command ``<project/class>`` argument is now
|
||||||
|
optional. If not specified, the user's current project is used.
|
||||||
|
This allows non-admin users to show quotas for their current project.
|
||||||
|
[Bug `1572733 <https://bugs.launchpad.net/bugs/1572733>`_]
|
Loading…
Reference in New Issue
Block a user