diff --git a/doc/source/command-objects/volume-type.rst b/doc/source/command-objects/volume-type.rst index ddc8933586..d93532c731 100644 --- a/doc/source/command-objects/volume-type.rst +++ b/doc/source/command-objects/volume-type.rst @@ -87,11 +87,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 e148bba420..9cf0f2fe0e 100644 --- a/openstackclient/tests/volume/v2/test_type.py +++ b/openstackclient/tests/volume/v2/test_type.py @@ -199,23 +199,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 62d619d086..e42fffe032 100644 --- a/openstackclient/volume/v2/volume_type.py +++ b/openstackclient/volume/v2/volume_type.py @@ -160,6 +160,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): @@ -169,7 +180,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 0000000000..a08caace84 --- /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 `_]