From 80843644134e5eaa2c738ab35e5236ecfbcf8f74 Mon Sep 17 00:00:00 2001 From: Chen Hanxiao Date: Wed, 27 Dec 2017 16:14:25 +0800 Subject: [PATCH] boot: show warning if more than one match when setting --image-with When setting --image-with meta_key=meta_value, we may got more than one results. We selected the first matched one silently. This patch prints a warning message for this scenario. Change-Id: I5be73fb61fb08d3abd0a509f3ac5cb6ea623c85a Signed-off-by: Chen Hanxiao --- novaclient/v2/shell.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index a30579de3..0f211d0a0 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -91,6 +91,15 @@ def emit_fixed_floating_deprecation_warning(command_name): command_name, file=sys.stderr) +def emit_duplicated_image_with_warning(img, image_with): + img_uuid_list = [str(image.id) for image in img] + print(_('WARNING: Multiple matching images: %(img_uuid_list)s\n' + 'Using image: %(chosen_one)s') % + {'img_uuid_list': img_uuid_list, + 'chosen_one': img_uuid_list[0]}, + file=sys.stderr) + + CLIENT_BDM2_KEYS = { 'id': 'uuid', 'source': 'source_type', @@ -396,9 +405,9 @@ def _boot(cs, args): if not image and args.image_with: images = _match_image(cs, args.image_with) + if len(images) > 1: + emit_duplicated_image_with_warning(images, args.image_with) if images: - # TODO(harlowja): log a warning that we - # are selecting the first of many? image = images[0] min_count = 1