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:
committed by
Dean Troyer
parent
678e690648
commit
05f5e043d8
@@ -94,12 +94,15 @@ def find_resource(manager, name_or_id, **kwargs):
|
|||||||
if len(kwargs) == 0:
|
if len(kwargs) == 0:
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
||||||
|
try:
|
||||||
# Prepare the kwargs for calling find
|
# Prepare the kwargs for calling find
|
||||||
if 'NAME_ATTR' in manager.resource_class.__dict__:
|
if 'NAME_ATTR' in manager.resource_class.__dict__:
|
||||||
# novaclient does this for oddball resources
|
# novaclient does this for oddball resources
|
||||||
kwargs[manager.resource_class.NAME_ATTR] = name_or_id
|
kwargs[manager.resource_class.NAME_ATTR] = name_or_id
|
||||||
else:
|
else:
|
||||||
kwargs['name'] = name_or_id
|
kwargs['name'] = name_or_id
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# finally try to find entity by name
|
# finally try to find entity by name
|
||||||
try:
|
try:
|
||||||
@@ -118,7 +121,8 @@ def find_resource(manager, name_or_id, **kwargs):
|
|||||||
(manager.resource_class.__name__.lower(), name_or_id)
|
(manager.resource_class.__name__.lower(), name_or_id)
|
||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
else:
|
else:
|
||||||
raise
|
msg = "Could not find resource %s" % name_or_id
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
def format_dict(data):
|
def format_dict(data):
|
||||||
|
|||||||
Reference in New Issue
Block a user