Skip to content

Commit 05f5e04

Browse files
Steve MartinelliDean Troyer
authored andcommitted
Additional exception handling for find_resource
A few things here: 1) we need to check if the client class even has a 'resource_class', in the case of glanceclient, it does not. 2) If everything fails we should print a better error message, rather than a "find" failed, since some clients don't support find. Change-Id: I6277322639e75b1635f9f3d159753efadbce1031
1 parent 678e690 commit 05f5e04

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

openstackclient/common/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ def find_resource(manager, name_or_id, **kwargs):
9494
if len(kwargs) == 0:
9595
kwargs = {}
9696

97-
# Prepare the kwargs for calling find
98-
if 'NAME_ATTR' in manager.resource_class.__dict__:
99-
# novaclient does this for oddball resources
100-
kwargs[manager.resource_class.NAME_ATTR] = name_or_id
101-
else:
102-
kwargs['name'] = name_or_id
97+
try:
98+
# Prepare the kwargs for calling find
99+
if 'NAME_ATTR' in manager.resource_class.__dict__:
100+
# novaclient does this for oddball resources
101+
kwargs[manager.resource_class.NAME_ATTR] = name_or_id
102+
else:
103+
kwargs['name'] = name_or_id
104+
except Exception:
105+
pass
103106

104107
# finally try to find entity by name
105108
try:
@@ -118,7 +121,8 @@ def find_resource(manager, name_or_id, **kwargs):
118121
(manager.resource_class.__name__.lower(), name_or_id)
119122
raise exceptions.CommandError(msg)
120123
else:
121-
raise
124+
msg = "Could not find resource %s" % name_or_id
125+
raise exceptions.CommandError(msg)
122126

123127

124128
def format_dict(data):

0 commit comments

Comments
 (0)