From 9471115a9a516049684755d7582338c83b3ca1f5 Mon Sep 17 00:00:00 2001 From: liyingjun Date: Wed, 14 Oct 2015 11:05:02 +0800 Subject: [PATCH] Support pagination params for flavor list Missing 'marker' and 'limit' params for `openstack flavor list` shell command. It would be nice to have this when there are many flavors. Closes-bug: #1505874 Change-Id: I088ac5d24f0d7595f5cbce14f063e296a449eb26 --- doc/source/command-objects/flavor.rst | 10 ++++++++++ openstackclient/compute/v2/flavor.py | 13 +++++++++++- .../tests/compute/v2/test_flavor.py | 20 ++++++++++++++----- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/doc/source/command-objects/flavor.rst b/doc/source/command-objects/flavor.rst index 5254b12cae..2389f7dc94 100644 --- a/doc/source/command-objects/flavor.rst +++ b/doc/source/command-objects/flavor.rst @@ -91,6 +91,8 @@ List flavors os flavor list [--public | --private | --all] [--long] + [--marker ] + [--limit ] .. option:: --public @@ -108,6 +110,14 @@ List flavors List additional fields in output +.. option:: --marker + + The last flavor ID of the previous page + +.. option:: --limit + + Maximum number of flavors to display + flavor show ----------- diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index 3458cf7969..7474580b60 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -181,6 +181,15 @@ class ListFlavor(lister.Lister): action='store_true', default=False, help='List additional fields in output') + parser.add_argument( + '--marker', + metavar="", + help='The last flavor ID of the previous page') + parser.add_argument( + '--limit', + type=int, + metavar="", + help='Maximum number of flavors to display') return parser def take_action(self, parsed_args): @@ -202,7 +211,9 @@ class ListFlavor(lister.Lister): # and flavors from their own projects only. is_public = None if parsed_args.all else parsed_args.public - data = compute_client.flavors.list(is_public=is_public) + data = compute_client.flavors.list(is_public=is_public, + marker=parsed_args.marker, + limit=parsed_args.limit) if parsed_args.long: columns = columns + ( diff --git a/openstackclient/tests/compute/v2/test_flavor.py b/openstackclient/tests/compute/v2/test_flavor.py index 19be812403..523104f091 100644 --- a/openstackclient/tests/compute/v2/test_flavor.py +++ b/openstackclient/tests/compute/v2/test_flavor.py @@ -76,7 +76,9 @@ class TestFlavorList(TestFlavor): # Set expected values kwargs = { - 'is_public': True + 'is_public': True, + 'limit': None, + 'marker': None } self.flavors_mock.list.assert_called_with( @@ -119,7 +121,9 @@ class TestFlavorList(TestFlavor): # Set expected values kwargs = { - 'is_public': None + 'is_public': None, + 'limit': None, + 'marker': None } self.flavors_mock.list.assert_called_with( @@ -162,7 +166,9 @@ class TestFlavorList(TestFlavor): # Set expected values kwargs = { - 'is_public': False + 'is_public': False, + 'limit': None, + 'marker': None } self.flavors_mock.list.assert_called_with( @@ -205,7 +211,9 @@ class TestFlavorList(TestFlavor): # Set expected values kwargs = { - 'is_public': True + 'is_public': True, + 'limit': None, + 'marker': None } self.flavors_mock.list.assert_called_with( @@ -248,7 +256,9 @@ class TestFlavorList(TestFlavor): # Set expected values kwargs = { - 'is_public': True + 'is_public': True, + 'limit': None, + 'marker': None } self.flavors_mock.list.assert_called_with(