From 106f928cb66fbfb3fb99f32b9d3e8ffdbda04d75 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Wed, 2 Dec 2015 14:02:12 +0800 Subject: [PATCH] Support "server list" searching by both image name and ID. Nova API only supports list servers searching by image ID. In OSC, we can support both image name and ID by mapping the name to ID. This patch also fix the inconsistent doc in .py and .rst files. Closes-Bug: 1521492 Change-Id: I70613843f82d74732bd32a457cd4a31aba57825f --- doc/source/command-objects/server.rst | 2 +- openstackclient/compute/v2/server.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index 59c047ad6d..627b673325 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -220,7 +220,7 @@ List servers .. option:: --image - Search by image ID + Search by image (name or ID) .. option:: --host diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 42699f8d2a..d58ebacd92 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -717,7 +717,7 @@ class ListServer(lister.Lister): parser.add_argument( '--image', metavar='', - help=_('Search by image'), + help=_('Search by image (name or ID)'), ) parser.add_argument( '--host', @@ -796,6 +796,13 @@ class ListServer(lister.Lister): flavor_id = utils.find_resource(compute_client.flavors, parsed_args.flavor).id + # Nova only supports list servers searching by image ID. So if a + # image name is given, map it to ID. + image_id = None + if parsed_args.image: + image_id = utils.find_resource(compute_client.images, + parsed_args.image).id + search_opts = { 'reservation_id': parsed_args.reservation_id, 'ip': parsed_args.ip, @@ -804,7 +811,7 @@ class ListServer(lister.Lister): 'instance_name': parsed_args.instance_name, 'status': parsed_args.status, 'flavor': flavor_id, - 'image': parsed_args.image, + 'image': image_id, 'host': parsed_args.host, 'tenant_id': project_id, 'all_tenants': parsed_args.all_projects,