diff options
author | Chen Hanxiao <chenhx@certusnet.com.cn> | 2017-12-27 16:14:25 +0800 |
---|---|---|
committer | Chen Hanxiao <chenhx@certusnet.com.cn> | 2017-12-28 13:38:36 +0800 |
commit | 80843644134e5eaa2c738ab35e5236ecfbcf8f74 (patch) | |
tree | 651536097a28e51eeec6d8b5299b04785dd612f7 | |
parent | e386d5dbe53fce42d467c5d38c6048c25b32f245 (diff) | |
download | python-novaclient-80843644134e5eaa2c738ab35e5236ecfbcf8f74.tar.gz |
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 <chenhx@certusnet.com.cn>
-rw-r--r-- | novaclient/v2/shell.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index a30579de..0f211d0a 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 |