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
This commit is contained in:
Tang Chen 2016-02-02 01:15:25 +08:00
parent 5812803865
commit 499369329c
4 changed files with 41 additions and 0 deletions

View File

@ -168,6 +168,7 @@ List available images
[--long]
[--sort <key>[:<direction>]]
[--limit <limit>]
[--marker <marker>]
.. option:: --public
@ -200,6 +201,11 @@ List available images
Maximum number of images to display.
.. option:: --marker <marker>
The last image (name or ID) of the previous page. Display list of images
after marker. Display all images if not specified.
image save
----------

View File

@ -437,6 +437,14 @@ class ListImage(command.Lister):
type=int,
help="Maximum number of images to display.",
)
parser.add_argument(
'--marker',
metavar='<marker>',
default=None,
help="The last image (name or ID) of the previous page. Display "
"list of images after marker. Display all images if not "
"specified."
)
return parser
def take_action(self, parsed_args):
@ -451,6 +459,9 @@ class ListImage(command.Lister):
kwargs['shared'] = True
if parsed_args.limit:
kwargs['limit'] = parsed_args.limit
if parsed_args.marker:
kwargs['marker'] = utils.find_resource(image_client.images,
parsed_args.marker).id
if parsed_args.long:
columns = (

View File

@ -672,6 +672,27 @@ class TestImageList(TestImage):
self.assertEqual(self.columns, columns)
self.assertEqual(len(self.datalist), len(tuple(data)))
@mock.patch('openstackclient.common.utils.find_resource')
def test_image_list_marker_option(self, fr_mock):
# tangchen: Since image_fakes.IMAGE is a dict, it cannot offer a .id
# operation. Will fix this by using FakeImage class instead
# of IMAGE dict.
fr_mock.return_value = mock.Mock()
fr_mock.return_value.id = image_fakes.image_id
arglist = [
'--marker', image_fakes.image_name,
]
verifylist = [
('marker', image_fakes.image_name),
]
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(
marker=image_fakes.image_id,
)
class TestRemoveProjectImage(TestImage):

View File

@ -4,3 +4,6 @@ features:
Add ``--limit`` option to ``image list`` to limit the number of images
in output.
[Bug `1540988 <https://bugs.launchpad.net/bugs/1540988>`_]
- |
Add ``--marker`` option to ``image list`` to handle paginate requests.
[Bug `1540988 <https://bugs.launchpad.net/bugs/1540988>`_]