summaryrefslogtreecommitdiff
path: root/glanceclient/common/utils.py
diff options
context:
space:
mode:
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>2013-01-05 07:32:25 +0900
committerKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>2013-01-05 07:32:25 +0900
commit0aba81ac1f11af283b4aca5a6ec65899200f6d5b (patch)
tree1a148869a110dde8d4d56b73dcf6cf779bcf7ff3 /glanceclient/common/utils.py
parent19d542ef5f570d98e08008898a0ee31a3186d5a9 (diff)
downloadpython-glanceclient-0aba81ac1f11af283b4aca5a6ec65899200f6d5b.tar.gz
Add image names to glance command arguments.
Now a user should specify ID as an image by glance command, and I feel it is easy-use that a user can specify name also as an image like nova command(ex. "nova boot"). By applying this patch, a user can specify name as image like the following examples: $ glance image-show cirros-0.3.0-x86_64-uec $ glance image-update --name root-fs cirros-0.3.0-x86_64-uec $ glance image-delete cirros-0.3.0-x86_64-uec $ glance image-download cirros-0.3.0-x86_64-uec $ glance member-create cirros-0.3.0-x86_64-uec 94b0e63a27ca43348fe056622fe3fe94 $ glance member-delete cirros-0.3.0-x86_64-uec 94b0e63a27ca43348fe056622fe3fe94 Fixes bug 1093380 Change-Id: Ia0a070eed6ae3853ef02032f479087edb1d75a67
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r--glanceclient/common/utils.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index 5304014..0159129 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -81,12 +81,19 @@ def find_resource(manager, name_or_id):
pass
# finally try to find entity by name
- try:
- return manager.find(name=name_or_id)
- except exc.NotFound:
+ matches = list(manager.list(filters={'name': name_or_id}))
+ num_matches = len(matches)
+ if num_matches == 0:
msg = "No %s with a name or ID of '%s' exists." % \
(manager.resource_class.__name__.lower(), name_or_id)
raise exc.CommandError(msg)
+ elif num_matches > 1:
+ msg = ("Multiple %s matches found for '%s', use an ID to be more"
+ " specific." % (manager.resource_class.__name__.lower(),
+ name_or_id))
+ raise exc.CommandError(msg)
+ else:
+ return matches[0]
def skip_authentication(f):