Add "--marker" and "--limit" options to "snapshot list"

Add "--marker" and "--limit" options to
"snapshot list" command in volume v2 (v2 only).

Change-Id: Ib60840b9b83dfe5e599e4037e8ec308844a9448b
Closes-Bug: #1605475
This commit is contained in:
Huanxuan Ao 2016-07-22 13:23:30 +08:00
parent d20d97fd09
commit 61b9d9fe2d
4 changed files with 68 additions and 3 deletions

View File

@ -68,6 +68,9 @@ List snapshots
os snapshot list
[--all-projects]
[--long]
[--limit <limit>]
[--marker <marker>]
.. option:: --all-projects
@ -77,6 +80,18 @@ List snapshots
List additional fields in output
.. option:: --limit <limit>
Maximum number of snapshots to display
*Volume version 2 only*
.. option:: --marker <marker>
The last snapshot ID of the previous page
*Volume version 2 only*
snapshot set
------------

View File

@ -12,6 +12,7 @@
# under the License.
#
import argparse
import mock
from mock import call
@ -260,16 +261,33 @@ class TestSnapshotList(TestSnapshot):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
limit=None, marker=None, search_opts={'all_tenants': False})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_snapshot_list_with_options(self):
arglist = ["--long"]
verifylist = [("long", True), ('all_projects', False)]
arglist = [
"--long",
"--limit", "2",
"--marker", self.snapshots[0].id,
]
verifylist = [
("long", True),
("limit", 2),
("marker", self.snapshots[0].id),
('all_projects', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
limit=2,
marker=self.snapshots[0].id,
search_opts={'all_tenants': False}
)
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
@ -285,9 +303,21 @@ class TestSnapshotList(TestSnapshot):
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
limit=None, marker=None, search_opts={'all_tenants': True})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_snapshot_list_negative_limit(self):
arglist = [
"--limit", "-2",
]
verifylist = [
("limit", -2),
]
self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
self.cmd, arglist, verifylist)
class TestSnapshotSet(TestSnapshot):

View File

@ -134,6 +134,18 @@ class ListSnapshot(command.Lister):
default=False,
help=_('List additional fields in output'),
)
parser.add_argument(
'--marker',
metavar='<marker>',
help=_('The last snapshot ID of the previous page'),
)
parser.add_argument(
'--limit',
type=int,
action=parseractions.NonNegativeAction,
metavar='<limit>',
help=_('Maximum number of snapshots to display'),
)
return parser
def take_action(self, parsed_args):
@ -174,7 +186,10 @@ class ListSnapshot(command.Lister):
}
data = self.app.client_manager.volume.volume_snapshots.list(
search_opts=search_opts)
search_opts=search_opts,
marker=parsed_args.marker,
limit=parsed_args.limit,
)
return (column_headers,
(utils.get_item_properties(
s, columns,

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``--limit`` and ``--marker`` options to ``snapshot list`` command.
[Bug `1605475 <https://bugs.launchpad.net/bugs/1605475>`_]