Skip to content

Commit e31408d

Browse files
author
Huanxuan Ao
committed
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
1 parent 9f61481 commit e31408d

4 files changed

Lines changed: 67 additions & 4 deletions

File tree

doc/source/command-objects/volume-type.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,24 @@ List volume types
7171
7272
os volume type list
7373
[--long]
74+
[--public | --private]
7475
7576
.. option:: --long
7677

7778
List additional fields in output
7879

80+
.. option:: --public
81+
82+
List only public types
83+
84+
*Volume version 2 only*
85+
86+
.. option:: --private
87+
88+
List only private types (admin only)
89+
90+
*Volume version 2 only*
91+
7992
volume type set
8093
---------------
8194

openstackclient/tests/volume/v2/test_type.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,50 @@ def setUp(self):
176176
def test_type_list_without_options(self):
177177
arglist = []
178178
verifylist = [
179-
("long", False)
179+
("long", False),
180+
("private", False),
181+
("public", False),
180182
]
181183
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
182184

183185
columns, data = self.cmd.take_action(parsed_args)
186+
self.types_mock.list.assert_called_once_with(is_public=None)
184187
self.assertEqual(self.columns, columns)
185188
self.assertEqual(self.data, list(data))
186189

187190
def test_type_list_with_options(self):
188-
arglist = ["--long"]
189-
verifylist = [("long", True)]
191+
arglist = [
192+
"--long",
193+
"--public",
194+
]
195+
verifylist = [
196+
("long", True),
197+
("private", False),
198+
("public", True),
199+
]
190200
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
191201

192202
columns, data = self.cmd.take_action(parsed_args)
203+
self.types_mock.list.assert_called_once_with(is_public=True)
193204
self.assertEqual(self.columns_long, columns)
194205
self.assertEqual(self.data_long, list(data))
195206

207+
def test_type_list_with_private_option(self):
208+
arglist = [
209+
"--private",
210+
]
211+
verifylist = [
212+
("long", False),
213+
("private", True),
214+
("public", False),
215+
]
216+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
217+
218+
columns, data = self.cmd.take_action(parsed_args)
219+
self.types_mock.list.assert_called_once_with(is_public=False)
220+
self.assertEqual(self.columns, columns)
221+
self.assertEqual(self.data, list(data))
222+
196223

197224
class TestTypeSet(TestType):
198225

openstackclient/volume/v2/volume_type.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ def get_parser(self, prog_name):
135135
action='store_true',
136136
default=False,
137137
help=_('List additional fields in output'))
138+
public_group = parser.add_mutually_exclusive_group()
139+
public_group.add_argument(
140+
"--public",
141+
action="store_true",
142+
help=_("List only public types")
143+
)
144+
public_group.add_argument(
145+
"--private",
146+
action="store_true",
147+
help=_("List only private types (admin only)")
148+
)
138149
return parser
139150

140151
def take_action(self, parsed_args):
@@ -144,7 +155,14 @@ def take_action(self, parsed_args):
144155
else:
145156
columns = ['ID', 'Name']
146157
column_headers = columns
147-
data = self.app.client_manager.volume.volume_types.list()
158+
159+
is_public = None
160+
if parsed_args.public:
161+
is_public = True
162+
if parsed_args.private:
163+
is_public = False
164+
data = self.app.client_manager.volume.volume_types.list(
165+
is_public=is_public)
148166
return (column_headers,
149167
(utils.get_item_properties(
150168
s, columns,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``--public`` and ``--private`` options to ``volume type list`` command.
5+
[Bug `1597198 <https://bugs.launchpad.net/bugs/1597198>`_]

0 commit comments

Comments
 (0)