From 0aba81ac1f11af283b4aca5a6ec65899200f6d5b Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Sat, 5 Jan 2013 07:32:25 +0900 Subject: 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 --- glanceclient/common/utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'glanceclient/common/utils.py') 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): -- cgit v1.2.1