Browse Source

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
changes/72/343472/4
Huanxuan Ao 5 years ago
parent
commit
e31408d2a4
4 changed files with 67 additions and 4 deletions
  1. +13
    -0
      doc/source/command-objects/volume-type.rst
  2. +30
    -3
      openstackclient/tests/volume/v2/test_type.py
  3. +19
    -1
      openstackclient/volume/v2/volume_type.py
  4. +5
    -0
      releasenotes/notes/bug-1597198-e36b55f3fd185a3a.yaml

+ 13
- 0
doc/source/command-objects/volume-type.rst View File

@ -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
---------------


+ 30
- 3
openstackclient/tests/volume/v2/test_type.py View File

@ -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):


+ 19
- 1
openstackclient/volume/v2/volume_type.py View File

@ -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,


+ 5
- 0
releasenotes/notes/bug-1597198-e36b55f3fd185a3a.yaml View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``--public`` and ``--private`` options to ``volume type list`` command.
[Bug `1597198 <https://bugs.launchpad.net/bugs/1597198>`_]

Loading…
Cancel
Save