Skip to content

Commit 60aec78

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Catch exception when getting quota"
2 parents 50a8377 + 7ea5f89 commit 60aec78

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

‎openstackclient/common/quota.py‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ def get_parser(self, prog_name):
147147
)
148148
return parser
149149

150+
def get_quota(self, client, parsed_args):
151+
try:
152+
if parsed_args.quota_class:
153+
quota = client.quota_classes.get(parsed_args.project)
154+
elif parsed_args.default:
155+
quota = client.quotas.defaults(parsed_args.project)
156+
else:
157+
quota = client.quotas.get(parsed_args.project)
158+
except Exception as e:
159+
if type(e).__name__ == 'EndpointNotFound':
160+
return {}
161+
else:
162+
raise e
163+
return quota._info
164+
150165
def take_action(self, parsed_args):
151166
self.log.debug('take_action(%s)', parsed_args)
152167

@@ -159,23 +174,12 @@ def take_action(self, parsed_args):
159174
# does not exist. If this is determined to be the
160175
# intended behaviour of the API we will validate
161176
# the argument with Identity ourselves later.
162-
if parsed_args.quota_class:
163-
compute_quota = compute_client.quota_classes.get(
164-
parsed_args.project)
165-
volume_quota = volume_client.quota_classes.get(
166-
parsed_args.project)
167-
elif parsed_args.default:
168-
compute_quota = compute_client.quotas.defaults(
169-
parsed_args.project)
170-
volume_quota = volume_client.quotas.defaults(
171-
parsed_args.project)
172-
else:
173-
compute_quota = compute_client.quotas.get(parsed_args.project)
174-
volume_quota = volume_client.quotas.get(parsed_args.project)
177+
compute_quota_info = self.get_quota(compute_client, parsed_args)
178+
volume_quota_info = self.get_quota(volume_client, parsed_args)
175179

176180
info = {}
177-
info.update(compute_quota._info)
178-
info.update(volume_quota._info)
181+
info.update(compute_quota_info)
182+
info.update(volume_quota_info)
179183

180184
# Map the internal quota names to the external ones
181185
for k, v in itertools.chain(

0 commit comments

Comments
 (0)