Skip to content

Commit 1e37c12

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "quota: Allow showing project-specific quotas"
2 parents a03b235 + 00e7019 commit 1e37c12

3 files changed

Lines changed: 134 additions & 26 deletions

File tree

openstackclient/common/quota.py

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,40 @@ def get_parser(self, prog_name):
739739
default=False,
740740
help=_('Show details about quotas usage'),
741741
)
742+
service_group = parser.add_mutually_exclusive_group()
743+
service_group.add_argument(
744+
'--all',
745+
action='store_const',
746+
const='all',
747+
dest='service',
748+
default='all',
749+
help=_('Show quotas for all services'),
750+
)
751+
service_group.add_argument(
752+
'--compute',
753+
action='store_const',
754+
const='compute',
755+
dest='service',
756+
default='all',
757+
help=_('Show compute quota'),
758+
)
759+
service_group.add_argument(
760+
'--volume',
761+
action='store_const',
762+
const='volume',
763+
dest='service',
764+
default='all',
765+
help=_('Show volume quota'),
766+
)
767+
service_group.add_argument(
768+
'--network',
769+
action='store_const',
770+
const='network',
771+
dest='service',
772+
default='all',
773+
help=_('Show network quota'),
774+
)
775+
742776
return parser
743777

744778
def take_action(self, parsed_args):
@@ -748,32 +782,39 @@ def take_action(self, parsed_args):
748782
project_info = get_project(self.app, parsed_args.project)
749783
project = project_info['id']
750784

751-
# NOTE(dtroyer): These quota API calls do not validate the project or
752-
# class arguments and return what appears to be the default quota
753-
# values if the project or class does not exist. If this is determined
754-
# to be the intended behaviour of the API we will validate the argument
755-
# with Identity ourselves later.
756-
compute_quota_info = get_compute_quotas(
757-
self.app,
758-
project,
759-
detail=parsed_args.usage,
760-
quota_class=parsed_args.quota_class,
761-
default=parsed_args.default,
762-
)
763-
volume_quota_info = get_volume_quotas(
764-
self.app,
765-
project,
766-
detail=parsed_args.usage,
767-
quota_class=parsed_args.quota_class,
768-
default=parsed_args.default,
769-
)
770-
network_quota_info = get_network_quotas(
771-
self.app,
772-
project,
773-
detail=parsed_args.usage,
774-
quota_class=parsed_args.quota_class,
775-
default=parsed_args.default,
776-
)
785+
compute_quota_info = {}
786+
volume_quota_info = {}
787+
network_quota_info = {}
788+
789+
# NOTE(stephenfin): These quota API calls do not validate the project
790+
# or class arguments and return what appears to be the default quota
791+
# values if the project or class does not exist. This is expected
792+
# behavior. However, we have already checked for the presence of the
793+
# project above so it shouldn't be an issue.
794+
if parsed_args.service in {'all', 'compute'}:
795+
compute_quota_info = get_compute_quotas(
796+
self.app,
797+
project,
798+
detail=parsed_args.usage,
799+
quota_class=parsed_args.quota_class,
800+
default=parsed_args.default,
801+
)
802+
if parsed_args.service in {'all', 'volume'}:
803+
volume_quota_info = get_volume_quotas(
804+
self.app,
805+
project,
806+
detail=parsed_args.usage,
807+
quota_class=parsed_args.quota_class,
808+
default=parsed_args.default,
809+
)
810+
if parsed_args.service in {'all', 'network'}:
811+
network_quota_info = get_network_quotas(
812+
self.app,
813+
project,
814+
detail=parsed_args.usage,
815+
quota_class=parsed_args.quota_class,
816+
default=parsed_args.default,
817+
)
777818

778819
info = {}
779820
info.update(compute_quota_info)

openstackclient/tests/unit/common/test_quota.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ def test_quota_show(self):
10871087
self.projects[0].name,
10881088
]
10891089
verifylist = [
1090+
('service', 'all'),
10901091
('project', self.projects[0].name),
10911092
]
10921093
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -1107,6 +1108,67 @@ def test_quota_show(self):
11071108
)
11081109
self.assertNotCalled(self.network.get_quota_default)
11091110

1111+
def test_quota_show__with_compute(self):
1112+
arglist = [
1113+
'--compute',
1114+
self.projects[0].name,
1115+
]
1116+
verifylist = [
1117+
('service', 'compute'),
1118+
('project', self.projects[0].name),
1119+
]
1120+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1121+
1122+
self.cmd.take_action(parsed_args)
1123+
1124+
self.compute_quotas_mock.get.assert_called_once_with(
1125+
self.projects[0].id,
1126+
detail=False,
1127+
)
1128+
self.volume_quotas_mock.get.assert_not_called()
1129+
self.network.get_quota.assert_not_called()
1130+
1131+
def test_quota_show__with_volume(self):
1132+
arglist = [
1133+
'--volume',
1134+
self.projects[0].name,
1135+
]
1136+
verifylist = [
1137+
('service', 'volume'),
1138+
('project', self.projects[0].name),
1139+
]
1140+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1141+
1142+
self.cmd.take_action(parsed_args)
1143+
1144+
self.compute_quotas_mock.get.assert_not_called()
1145+
self.volume_quotas_mock.get.assert_called_once_with(
1146+
self.projects[0].id,
1147+
usage=False,
1148+
)
1149+
self.network.get_quota.assert_not_called()
1150+
1151+
def test_quota_show__with_network(self):
1152+
arglist = [
1153+
'--network',
1154+
self.projects[0].name,
1155+
]
1156+
verifylist = [
1157+
('service', 'network'),
1158+
('project', self.projects[0].name),
1159+
]
1160+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1161+
1162+
self.cmd.take_action(parsed_args)
1163+
1164+
self.compute_quotas_mock.get.assert_not_called()
1165+
self.volume_quotas_mock.get.assert_not_called()
1166+
self.network.get_quota.assert_called_once_with(
1167+
self.projects[0].id,
1168+
details=False,
1169+
)
1170+
self.assertNotCalled(self.network.get_quota_default)
1171+
11101172
def test_quota_show__with_default(self):
11111173
arglist = [
11121174
'--default',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
The ``quota show`` command now allows you to show quotas for a specific
5+
service using the ``--compute``, ``--volume``, or ``--network`` options.

0 commit comments

Comments
 (0)