Skip to content

Commit 106f928

Browse files
tang-chenSteve Martinelli
authored andcommitted
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
1 parent 0069a01 commit 106f928

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

doc/source/command-objects/server.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ List servers
220220
221221
.. option:: --image <image>
222222
223-
Search by image ID
223+
Search by image (name or ID)
224224
225225
.. option:: --host <hostname>
226226

openstackclient/compute/v2/server.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def get_parser(self, prog_name):
717717
parser.add_argument(
718718
'--image',
719719
metavar='<image>',
720-
help=_('Search by image'),
720+
help=_('Search by image (name or ID)'),
721721
)
722722
parser.add_argument(
723723
'--host',
@@ -796,6 +796,13 @@ def take_action(self, parsed_args):
796796
flavor_id = utils.find_resource(compute_client.flavors,
797797
parsed_args.flavor).id
798798

799+
# Nova only supports list servers searching by image ID. So if a
800+
# image name is given, map it to ID.
801+
image_id = None
802+
if parsed_args.image:
803+
image_id = utils.find_resource(compute_client.images,
804+
parsed_args.image).id
805+
799806
search_opts = {
800807
'reservation_id': parsed_args.reservation_id,
801808
'ip': parsed_args.ip,
@@ -804,7 +811,7 @@ def take_action(self, parsed_args):
804811
'instance_name': parsed_args.instance_name,
805812
'status': parsed_args.status,
806813
'flavor': flavor_id,
807-
'image': parsed_args.image,
814+
'image': image_id,
808815
'host': parsed_args.host,
809816
'tenant_id': project_id,
810817
'all_tenants': parsed_args.all_projects,

0 commit comments

Comments
 (0)