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
This commit is contained in:
Steve Martinelli 2015-09-24 23:24:44 -04:00 committed by Dean Troyer
parent 678e690648
commit 05f5e043d8

View File

@ -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):