summaryrefslogtreecommitdiff
path: root/cinderclient/utils.py
diff options
context:
space:
mode:
authorGorka Eguileor <geguileo@redhat.com>2015-03-06 13:13:05 +0100
committerGorka Eguileor <geguileo@redhat.com>2015-04-01 12:38:19 +0200
commit6ebe6e98d7ca6b3db6cc830898e51e00e06f4ef4 (patch)
tree3c6800398080e7e44e572d74e29bbe172753cac5 /cinderclient/utils.py
parente5a13047918402ab0373181e25bb842d33c4ad50 (diff)
downloadpython-cinderclient-6ebe6e98d7ca6b3db6cc830898e51e00e06f4ef4.tar.gz
Remove duplicate find request in find_resource
Removed duplicate manager.find method call using search argument display_name that affected any command that searches for a volume by display_name or any command that searches for non existent volumes. Change-Id: I86c99b41dd231b058ed3f6d5d78eafe35a111dec Closes-Bug: #1429102
Diffstat (limited to 'cinderclient/utils.py')
-rw-r--r--cinderclient/utils.py33
1 files changed, 16 insertions, 17 deletions
diff --git a/cinderclient/utils.py b/cinderclient/utils.py
index 330d52d..cb9125c 100644
--- a/cinderclient/utils.py
+++ b/cinderclient/utils.py
@@ -166,17 +166,17 @@ def find_resource(manager, name_or_id):
return manager.get(int(name_or_id))
except exceptions.NotFound:
pass
+ else:
+ # now try to get entity as uuid
+ try:
+ uuid.UUID(name_or_id)
+ return manager.get(name_or_id)
+ except (ValueError, exceptions.NotFound):
+ pass
if sys.version_info <= (3, 0):
name_or_id = strutils.safe_decode(name_or_id)
- # now try to get entity as uuid
- try:
- uuid.UUID(name_or_id)
- return manager.get(name_or_id)
- except (ValueError, exceptions.NotFound):
- pass
-
try:
try:
return manager.find(human_id=name_or_id)
@@ -187,16 +187,15 @@ def find_resource(manager, name_or_id):
try:
return manager.find(name=name_or_id)
except exceptions.NotFound:
- try:
- return manager.find(display_name=name_or_id)
- except (UnicodeDecodeError, exceptions.NotFound):
- try:
- # Volumes does not have name, but display_name
- return manager.find(display_name=name_or_id)
- except exceptions.NotFound:
- msg = "No %s with a name or ID of '%s' exists." % \
- (manager.resource_class.__name__.lower(), name_or_id)
- raise exceptions.CommandError(msg)
+ pass
+
+ # Volumes don't have name, but display_name
+ try:
+ return manager.find(display_name=name_or_id)
+ except (UnicodeDecodeError, exceptions.NotFound):
+ msg = "No %s with a name or ID of '%s' exists." % \
+ (manager.resource_class.__name__.lower(), name_or_id)
+ raise exceptions.CommandError(msg)
except exceptions.NoUniqueMatch:
msg = ("Multiple %s matches found for '%s', use an ID to be more"
" specific." % (manager.resource_class.__name__.lower(),