Skip to content

Commit 4993693

Browse files
author
Tang Chen
committed
Add --marker option to "image list" command
Users could specify the last image (name or ID) of the previous page with --marker option to control the start image of the output. Change-Id: Idca0235ee83b1226b00c89cf3d38500fa898b7d0 Closes-Bug: #1540988
1 parent 5812803 commit 4993693

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

doc/source/command-objects/image.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ List available images
168168
[--long]
169169
[--sort <key>[:<direction>]]
170170
[--limit <limit>]
171+
[--marker <marker>]
171172
172173
.. option:: --public
173174
@@ -200,6 +201,11 @@ List available images
200201
201202
Maximum number of images to display.
202203
204+
.. option:: --marker <marker>
205+
206+
The last image (name or ID) of the previous page. Display list of images
207+
after marker. Display all images if not specified.
208+
203209
image save
204210
----------
205211

openstackclient/image/v2/image.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ def get_parser(self, prog_name):
437437
type=int,
438438
help="Maximum number of images to display.",
439439
)
440+
parser.add_argument(
441+
'--marker',
442+
metavar='<marker>',
443+
default=None,
444+
help="The last image (name or ID) of the previous page. Display "
445+
"list of images after marker. Display all images if not "
446+
"specified."
447+
)
440448
return parser
441449

442450
def take_action(self, parsed_args):
@@ -451,6 +459,9 @@ def take_action(self, parsed_args):
451459
kwargs['shared'] = True
452460
if parsed_args.limit:
453461
kwargs['limit'] = parsed_args.limit
462+
if parsed_args.marker:
463+
kwargs['marker'] = utils.find_resource(image_client.images,
464+
parsed_args.marker).id
454465

455466
if parsed_args.long:
456467
columns = (

openstackclient/tests/image/v2/test_image.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,27 @@ def test_image_list_limit_option(self):
672672
self.assertEqual(self.columns, columns)
673673
self.assertEqual(len(self.datalist), len(tuple(data)))
674674

675+
@mock.patch('openstackclient.common.utils.find_resource')
676+
def test_image_list_marker_option(self, fr_mock):
677+
# tangchen: Since image_fakes.IMAGE is a dict, it cannot offer a .id
678+
# operation. Will fix this by using FakeImage class instead
679+
# of IMAGE dict.
680+
fr_mock.return_value = mock.Mock()
681+
fr_mock.return_value.id = image_fakes.image_id
682+
683+
arglist = [
684+
'--marker', image_fakes.image_name,
685+
]
686+
verifylist = [
687+
('marker', image_fakes.image_name),
688+
]
689+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
690+
691+
columns, data = self.cmd.take_action(parsed_args)
692+
self.api_mock.image_list.assert_called_with(
693+
marker=image_fakes.image_id,
694+
)
695+
675696

676697
class TestRemoveProjectImage(TestImage):
677698

releasenotes/notes/bug-1540988-17841cfd5accf7f5.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ features:
44
Add ``--limit`` option to ``image list`` to limit the number of images
55
in output.
66
[Bug `1540988 <https://bugs.launchpad.net/bugs/1540988>`_]
7+
- |
8+
Add ``--marker`` option to ``image list`` to handle paginate requests.
9+
[Bug `1540988 <https://bugs.launchpad.net/bugs/1540988>`_]

0 commit comments

Comments
 (0)