image-list should support filters 'name','status'
nova api support parameters like 'name', 'server', 'status', etc in image-list(). So openstackclient should support this too. DocImpact Closes-Bug: #1698742 Change-Id: Ice66b409f989e6785aa3b2d42f2fdbf6e23fa0aa
This commit is contained in:
parent
3cba09e767
commit
bca8d57eb3
@ -209,6 +209,9 @@ List available images
|
|||||||
[--sort <key>[:<direction>]]
|
[--sort <key>[:<direction>]]
|
||||||
[--limit <num-images>]
|
[--limit <num-images>]
|
||||||
[--marker <image>]
|
[--marker <image>]
|
||||||
|
[--name <name>]
|
||||||
|
[--status <status>]
|
||||||
|
|
||||||
|
|
||||||
.. option:: --public
|
.. option:: --public
|
||||||
|
|
||||||
@ -248,6 +251,15 @@ List available images
|
|||||||
The last image of the previous page. Display list of images
|
The last image of the previous page. Display list of images
|
||||||
after marker. Display all images if not specified. (name or ID)
|
after marker. Display all images if not specified. (name or ID)
|
||||||
|
|
||||||
|
.. option:: --name <name>
|
||||||
|
|
||||||
|
Filter images based on name
|
||||||
|
|
||||||
|
.. option:: --status <status>
|
||||||
|
|
||||||
|
Filter images based on status
|
||||||
|
|
||||||
|
|
||||||
*Image version 2 only*
|
*Image version 2 only*
|
||||||
|
|
||||||
image remove project
|
image remove project
|
||||||
|
@ -452,6 +452,18 @@ class ListImage(command.Lister):
|
|||||||
action=parseractions.KeyValueAction,
|
action=parseractions.KeyValueAction,
|
||||||
help=_('Filter output based on property'),
|
help=_('Filter output based on property'),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--name',
|
||||||
|
metavar='<name>',
|
||||||
|
default=None,
|
||||||
|
help=_("Filter images based on name.")
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--status',
|
||||||
|
metavar='<status>',
|
||||||
|
default=None,
|
||||||
|
help=_("Filter images based on status.")
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--long',
|
'--long',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -505,6 +517,10 @@ class ListImage(command.Lister):
|
|||||||
if parsed_args.marker:
|
if parsed_args.marker:
|
||||||
kwargs['marker'] = utils.find_resource(image_client.images,
|
kwargs['marker'] = utils.find_resource(image_client.images,
|
||||||
parsed_args.marker).id
|
parsed_args.marker).id
|
||||||
|
if parsed_args.name:
|
||||||
|
kwargs['name'] = parsed_args.name
|
||||||
|
if parsed_args.status:
|
||||||
|
kwargs['status'] = parsed_args.status
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
|
@ -51,6 +51,24 @@ class ImageTests(base.TestCase):
|
|||||||
[img['Name'] for img in json_output]
|
[img['Name'] for img in json_output]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_image_list_with_name_filter(self):
|
||||||
|
json_output = json.loads(self.openstack(
|
||||||
|
'image list --name ' + self.NAME + ' -f json'
|
||||||
|
))
|
||||||
|
self.assertIn(
|
||||||
|
self.NAME,
|
||||||
|
[img['Name'] for img in json_output]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_image_list_with_status_filter(self):
|
||||||
|
json_output = json.loads(self.openstack(
|
||||||
|
'image list ' + ' --status active -f json'
|
||||||
|
))
|
||||||
|
self.assertIn(
|
||||||
|
'active',
|
||||||
|
[img['Status'] for img in json_output]
|
||||||
|
)
|
||||||
|
|
||||||
def test_image_attributes(self):
|
def test_image_attributes(self):
|
||||||
"""Test set, unset, show on attributes, tags and properties"""
|
"""Test set, unset, show on attributes, tags and properties"""
|
||||||
|
|
||||||
|
@ -750,6 +750,34 @@ class TestImageList(TestImage):
|
|||||||
marker=image_fakes.image_id,
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_image_list_name_option(self):
|
||||||
|
arglist = [
|
||||||
|
'--name', 'abc',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('name', 'abc'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.api_mock.image_list.assert_called_with(
|
||||||
|
name='abc', marker=self._image.id
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_image_list_status_option(self):
|
||||||
|
arglist = [
|
||||||
|
'--status', 'active',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('status', 'active'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.api_mock.image_list.assert_called_with(
|
||||||
|
status='active', marker=self._image.id
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestRemoveProjectImage(TestImage):
|
class TestRemoveProjectImage(TestImage):
|
||||||
|
|
||||||
|
6
releasenotes/notes/bug-1698742-66d9d4e6c7ad274a.yaml
Normal file
6
releasenotes/notes/bug-1698742-66d9d4e6c7ad274a.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--name`` and ``--status`` options to ``image list`` command
|
||||||
|
to filter images based on name and status respectively.
|
||||||
|
[Bug `1698742 <https://bugs.launchpad.net/bugs/1698742>`_]
|
Loading…
Reference in New Issue
Block a user