quota: Split up 'quota list' command

This is really three separate commands rolled into one. Split the logic
up more to simplify it somewhat.

Change-Id: Ief3c3c413f791dda076f90e5ec76a033d3a9e12b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2024-07-10 12:29:56 +01:00
parent da7eda66e9
commit b4f30a1583

View File

@@ -241,14 +241,10 @@ class ListQuota(command.Lister):
)
return parser
def take_action(self, parsed_args):
result = []
project_ids = [
p.id for p in self.app.client_manager.identity.projects.list()
]
if parsed_args.compute:
def _list_quota_compute(self, parsed_args, project_ids):
compute_client = self.app.client_manager.compute
result = []
for p in project_ids:
try:
data = compute_client.quotas.get(p)
@@ -309,8 +305,10 @@ class ListQuota(command.Lister):
(utils.get_dict_properties(s, columns) for s in result),
)
if parsed_args.volume:
def _list_quota_volume(self, parsed_args, project_ids):
volume_client = self.app.client_manager.volume
result = []
for p in project_ids:
try:
data = volume_client.quotas.get(p)
@@ -360,8 +358,10 @@ class ListQuota(command.Lister):
(utils.get_dict_properties(s, columns) for s in result),
)
if parsed_args.network:
def _list_quota_network(self, parsed_args, project_ids):
client = self.app.client_manager.network
result = []
for p in project_ids:
try:
data = client.get_quota(p)
@@ -417,6 +417,18 @@ class ListQuota(command.Lister):
(utils.get_dict_properties(s, columns) for s in result),
)
def take_action(self, parsed_args):
project_ids = [
p.id for p in self.app.client_manager.identity.projects.list()
]
if parsed_args.compute:
return self._list_quota_compute(parsed_args, project_ids)
elif parsed_args.volume:
return self._list_quota_volume(parsed_args, project_ids)
elif parsed_args.network:
return self._list_quota_network(parsed_args, project_ids)
# will never get here
return ((), ())