summaryrefslogtreecommitdiff
path: root/cinderclient/utils.py
diff options
context:
space:
mode:
authorAnton Arefiev <aarefiev@mirantis.com>2015-04-28 13:12:48 +0300
committerAnton Arefiev <aarefiev@mirantis.com>2015-05-12 14:52:46 +0300
commitc5c2d67b7f683ea1f4e8acfb54930bfc2954b342 (patch)
tree47e3ed43b4fa58ccdb0d90a59b130c25f227ec13 /cinderclient/utils.py
parentd936ebaaf661bf3d64b4b62872d3e203a2ca06b8 (diff)
downloadpython-cinderclient-c5c2d67b7f683ea1f4e8acfb54930bfc2954b342.tar.gz
Find resource refactoring
The 'name' field for some resources is called something different, for example 'display_name' for volumes, 'name' for volumes type. So class 'resource' has attribute 'NAME_ATTR' wich contains attribute name for different resources. This change removes reduntant call find in resource manager, instead of it checks NAME_ATTR value. Related-Bug: #1449444 Change-Id: Ide334d7535c73cbdff72c30319eb539d8f5304d6
Diffstat (limited to 'cinderclient/utils.py')
-rw-r--r--cinderclient/utils.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/cinderclient/utils.py b/cinderclient/utils.py
index cb9125c..896c646 100644
--- a/cinderclient/utils.py
+++ b/cinderclient/utils.py
@@ -179,23 +179,20 @@ def find_resource(manager, name_or_id):
try:
try:
- return manager.find(human_id=name_or_id)
+ resource = getattr(manager, 'resource_class', None)
+ name_attr = resource.NAME_ATTR if resource else 'name'
+ return manager.find(**{name_attr: name_or_id})
except exceptions.NotFound:
pass
- # finally try to find entity by name
+ # finally try to find entity by human_id
try:
- return manager.find(name=name_or_id)
+ return manager.find(human_id=name_or_id)
except exceptions.NotFound:
- 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(),