Skip to content

Commit 6da7a12

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add options to "volume type list" command"
2 parents 566b856 + e31408d commit 6da7a12

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
@@ -87,11 +87,24 @@ List volume types
8787
8888
os volume type list
8989
[--long]
90+
[--public | --private]
9091
9192
.. option:: --long
9293

9394
List additional fields in output
9495

96+
.. option:: --public
97+
98+
List only public types
99+
100+
*Volume version 2 only*
101+
102+
.. option:: --private
103+
104+
List only private types (admin only)
105+
106+
*Volume version 2 only*
107+
95108
volume type set
96109
---------------
97110

openstackclient/tests/volume/v2/test_type.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,50 @@ def setUp(self):
199199
def test_type_list_without_options(self):
200200
arglist = []
201201
verifylist = [
202-
("long", False)
202+
("long", False),
203+
("private", False),
204+
("public", False),
203205
]
204206
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
205207

206208
columns, data = self.cmd.take_action(parsed_args)
209+
self.types_mock.list.assert_called_once_with(is_public=None)
207210
self.assertEqual(self.columns, columns)
208211
self.assertEqual(self.data, list(data))
209212

210213
def test_type_list_with_options(self):
211-
arglist = ["--long"]
212-
verifylist = [("long", True)]
214+
arglist = [
215+
"--long",
216+
"--public",
217+
]
218+
verifylist = [
219+
("long", True),
220+
("private", False),
221+
("public", True),
222+
]
213223
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
214224

215225
columns, data = self.cmd.take_action(parsed_args)
226+
self.types_mock.list.assert_called_once_with(is_public=True)
216227
self.assertEqual(self.columns_long, columns)
217228
self.assertEqual(self.data_long, list(data))
218229

230+
def test_type_list_with_private_option(self):
231+
arglist = [
232+
"--private",
233+
]
234+
verifylist = [
235+
("long", False),
236+
("private", True),
237+
("public", False),
238+
]
239+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
240+
241+
columns, data = self.cmd.take_action(parsed_args)
242+
self.types_mock.list.assert_called_once_with(is_public=False)
243+
self.assertEqual(self.columns, columns)
244+
self.assertEqual(self.data, list(data))
245+
219246

220247
class TestTypeSet(TestType):
221248

openstackclient/volume/v2/volume_type.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ def get_parser(self, prog_name):
160160
action='store_true',
161161
default=False,
162162
help=_('List additional fields in output'))
163+
public_group = parser.add_mutually_exclusive_group()
164+
public_group.add_argument(
165+
"--public",
166+
action="store_true",
167+
help=_("List only public types")
168+
)
169+
public_group.add_argument(
170+
"--private",
171+
action="store_true",
172+
help=_("List only private types (admin only)")
173+
)
163174
return parser
164175

165176
def take_action(self, parsed_args):
@@ -169,7 +180,14 @@ def take_action(self, parsed_args):
169180
else:
170181
columns = ['ID', 'Name']
171182
column_headers = columns
172-
data = self.app.client_manager.volume.volume_types.list()
183+
184+
is_public = None
185+
if parsed_args.public:
186+
is_public = True
187+
if parsed_args.private:
188+
is_public = False
189+
data = self.app.client_manager.volume.volume_types.list(
190+
is_public=is_public)
173191
return (column_headers,
174192
(utils.get_item_properties(
175193
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)