From e31408d2a4c524181c37ef565b021c0b729cbbe3 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Mon, 18 Jul 2016 15:14:51 +0800 Subject: [PATCH] Add options to "volume type list" command Add "--public" and "--private" options to "volume type command" in volumev2 (v2 only) to list optional volume types Change-Id: I8605990d62116c10d89ce192c14e550657dabee5 Closes-Bug: #1597198 --- doc/source/command-objects/volume-type.rst | 13 ++++++++ openstackclient/tests/volume/v2/test_type.py | 33 +++++++++++++++++-- openstackclient/volume/v2/volume_type.py | 20 ++++++++++- .../notes/bug-1597198-e36b55f3fd185a3a.yaml | 5 +++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/bug-1597198-e36b55f3fd185a3a.yaml diff --git a/doc/source/command-objects/volume-type.rst b/doc/source/command-objects/volume-type.rst index dfc169cd1..9141c9ed5 100644 --- a/doc/source/command-objects/volume-type.rst +++ b/doc/source/command-objects/volume-type.rst @@ -71,11 +71,24 @@ List volume types os volume type list [--long] + [--public | --private] .. option:: --long List additional fields in output +.. option:: --public + + List only public types + + *Volume version 2 only* + +.. option:: --private + + List only private types (admin only) + + *Volume version 2 only* + volume type set --------------- diff --git a/openstackclient/tests/volume/v2/test_type.py b/openstackclient/tests/volume/v2/test_type.py index 174f33f2f..e1c2c1dbc 100644 --- a/openstackclient/tests/volume/v2/test_type.py +++ b/openstackclient/tests/volume/v2/test_type.py @@ -176,23 +176,50 @@ class TestTypeList(TestType): def test_type_list_without_options(self): arglist = [] verifylist = [ - ("long", False) + ("long", False), + ("private", False), + ("public", False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + self.types_mock.list.assert_called_once_with(is_public=None) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) def test_type_list_with_options(self): - arglist = ["--long"] - verifylist = [("long", True)] + arglist = [ + "--long", + "--public", + ] + verifylist = [ + ("long", True), + ("private", False), + ("public", True), + ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + self.types_mock.list.assert_called_once_with(is_public=True) self.assertEqual(self.columns_long, columns) self.assertEqual(self.data_long, list(data)) + def test_type_list_with_private_option(self): + arglist = [ + "--private", + ] + verifylist = [ + ("long", False), + ("private", True), + ("public", False), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + self.types_mock.list.assert_called_once_with(is_public=False) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + class TestTypeSet(TestType): diff --git a/openstackclient/volume/v2/volume_type.py b/openstackclient/volume/v2/volume_type.py index 91ac17a16..05597bec6 100644 --- a/openstackclient/volume/v2/volume_type.py +++ b/openstackclient/volume/v2/volume_type.py @@ -135,6 +135,17 @@ class ListVolumeType(command.Lister): action='store_true', default=False, help=_('List additional fields in output')) + public_group = parser.add_mutually_exclusive_group() + public_group.add_argument( + "--public", + action="store_true", + help=_("List only public types") + ) + public_group.add_argument( + "--private", + action="store_true", + help=_("List only private types (admin only)") + ) return parser def take_action(self, parsed_args): @@ -144,7 +155,14 @@ class ListVolumeType(command.Lister): else: columns = ['ID', 'Name'] column_headers = columns - data = self.app.client_manager.volume.volume_types.list() + + is_public = None + if parsed_args.public: + is_public = True + if parsed_args.private: + is_public = False + data = self.app.client_manager.volume.volume_types.list( + is_public=is_public) return (column_headers, (utils.get_item_properties( s, columns, diff --git a/releasenotes/notes/bug-1597198-e36b55f3fd185a3a.yaml b/releasenotes/notes/bug-1597198-e36b55f3fd185a3a.yaml new file mode 100644 index 000000000..a08caace8 --- /dev/null +++ b/releasenotes/notes/bug-1597198-e36b55f3fd185a3a.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--public`` and ``--private`` options to ``volume type list`` command. + [Bug `1597198 `_]