summaryrefslogtreecommitdiff
path: root/openstackclient/common/utils.py
diff options
context:
space:
mode:
authorSteve Martinelli <stevemar@ca.ibm.com>2015-09-24 23:24:44 -0400
committerDean Troyer <dtroyer@gmail.com>2015-09-30 09:54:28 -0500
commit05f5e043d8cc536c21acb51c5a9e85fac9563f47 (patch)
tree1c473023991254073ca14086408be1c6b1107b4e /openstackclient/common/utils.py
parent678e69064854e3a3d3499171b0a29f30f2771840 (diff)
downloadpython-openstackclient-05f5e043d8cc536c21acb51c5a9e85fac9563f47.tar.gz
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
Diffstat (limited to 'openstackclient/common/utils.py')
-rw-r--r--openstackclient/common/utils.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index b6726bfa..7a5d33e3 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -94,12 +94,15 @@ def find_resource(manager, name_or_id, **kwargs):
if len(kwargs) == 0:
kwargs = {}
- # Prepare the kwargs for calling find
- if 'NAME_ATTR' in manager.resource_class.__dict__:
- # novaclient does this for oddball resources
- kwargs[manager.resource_class.NAME_ATTR] = name_or_id
- else:
- kwargs['name'] = name_or_id
+ try:
+ # Prepare the kwargs for calling find
+ if 'NAME_ATTR' in manager.resource_class.__dict__:
+ # novaclient does this for oddball resources
+ kwargs[manager.resource_class.NAME_ATTR] = name_or_id
+ else:
+ kwargs['name'] = name_or_id
+ except Exception:
+ pass
# finally try to find entity by name
try:
@@ -118,7 +121,8 @@ def find_resource(manager, name_or_id, **kwargs):
(manager.resource_class.__name__.lower(), name_or_id)
raise exceptions.CommandError(msg)
else:
- raise
+ msg = "Could not find resource %s" % name_or_id
+ raise exceptions.CommandError(msg)
def format_dict(data):