Add limit option to "image list" command
This option is quite useful if there are too many images. Change-Id: If6a901c27c5da2d1f4412e8fa9ba3bed3b72fdd9 Co-Authored-By: Tang Chen <chen.tang@easystack.cn> Partial-Bug: #1540988
This commit is contained in:
parent
0b6fdcbe4c
commit
5812803865
doc/source/command-objects
openstackclient
releasenotes/notes
@ -167,6 +167,7 @@ List available images
|
||||
[--property <key=value>]
|
||||
[--long]
|
||||
[--sort <key>[:<direction>]]
|
||||
[--limit <limit>]
|
||||
|
||||
.. option:: --public
|
||||
|
||||
@ -195,6 +196,10 @@ List available images
|
||||
Sort output by selected keys and directions(asc or desc) (default: asc),
|
||||
multiple keys and directions can be specified separated by comma
|
||||
|
||||
.. option:: --limit <limit>
|
||||
|
||||
Maximum number of images to display.
|
||||
|
||||
image save
|
||||
----------
|
||||
|
||||
|
@ -431,6 +431,12 @@ class ListImage(command.Lister):
|
||||
"(default: asc), multiple keys and directions can be "
|
||||
"specified separated by comma",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--limit",
|
||||
metavar="<limit>",
|
||||
type=int,
|
||||
help="Maximum number of images to display.",
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -443,6 +449,8 @@ class ListImage(command.Lister):
|
||||
kwargs['private'] = True
|
||||
if parsed_args.shared:
|
||||
kwargs['shared'] = True
|
||||
if parsed_args.limit:
|
||||
kwargs['limit'] = parsed_args.limit
|
||||
|
||||
if parsed_args.long:
|
||||
columns = (
|
||||
|
@ -655,6 +655,23 @@ class TestImageList(TestImage):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.datalist, tuple(data))
|
||||
|
||||
def test_image_list_limit_option(self):
|
||||
arglist = [
|
||||
'--limit', str(1),
|
||||
]
|
||||
verifylist = [
|
||||
('limit', 1),
|
||||
]
|
||||
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(
|
||||
limit=1,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(len(self.datalist), len(tuple(data)))
|
||||
|
||||
|
||||
class TestRemoveProjectImage(TestImage):
|
||||
|
||||
|
6
releasenotes/notes/bug-1540988-17841cfd5accf7f5.yaml
Normal file
6
releasenotes/notes/bug-1540988-17841cfd5accf7f5.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--limit`` option to ``image list`` to limit the number of images
|
||||
in output.
|
||||
[Bug `1540988 <https://bugs.launchpad.net/bugs/1540988>`_]
|
Loading…
x
Reference in New Issue
Block a user