Add 'is_public' support in '--filters' option

'--is-public' is a valid argument for cinder type-list command[1]
and cinder group-type-list command but is missing in cinderclient.
This patch adds the support for it.

[1] https://developer.openstack.org/api-ref/block-storage/v3/?expanded=list-all-volume-types-detail#list-all-volume-types

Change-Id: I8af9bb06a28f3cc384c4925b8b52bdeaed52cb15
This commit is contained in:
whoami-rajat 2019-03-07 20:50:55 +05:30 committed by Rajat Dhasmana
parent 15295acb07
commit 6a498163e2
5 changed files with 61 additions and 5 deletions

View File

@ -265,7 +265,17 @@ class ShellTest(utils.TestCase):
{six.text_type('key'): six.text_type('value')}}))
self.assert_call_contained(parse.urlencode({'is_public': None}))
def test_type_list_no_filters(self):
def test_type_list_public(self):
self.run_command('--os-volume-api-version 3.52 type-list '
'--filters is_public=True')
self.assert_called('GET', '/types?is_public=True')
def test_type_list_private(self):
self.run_command('--os-volume-api-version 3.52 type-list '
'--filters is_public=False')
self.assert_called('GET', '/types?is_public=False')
def test_type_list_public_private(self):
self.run_command('--os-volume-api-version 3.52 type-list')
self.assert_called('GET', '/types?is_public=None')
@ -555,6 +565,20 @@ class ShellTest(utils.TestCase):
self.run_command('--os-volume-api-version 3.11 group-type-list')
self.assert_called_anytime('GET', '/group_types?is_public=None')
def test_group_type_list_public(self):
self.run_command('--os-volume-api-version 3.52 group-type-list '
'--filters is_public=True')
self.assert_called('GET', '/group_types?is_public=True')
def test_group_type_list_private(self):
self.run_command('--os-volume-api-version 3.52 group-type-list '
'--filters is_public=False')
self.assert_called('GET', '/group_types?is_public=False')
def test_group_type_list_public_private(self):
self.run_command('--os-volume-api-version 3.52 group-type-list')
self.assert_called('GET', '/group_types?is_public=None')
def test_group_type_show(self):
self.run_command('--os-volume-api-version 3.11 '
'group-type-show 1')

View File

@ -16,6 +16,8 @@
"""Group Type interface."""
from six.moves.urllib import parse
from cinderclient import api_versions
from cinderclient import base
@ -84,9 +86,14 @@ class GroupTypeManager(base.ManagerWithFind):
:rtype: list of :class:`GroupType`.
"""
if not search_opts:
search_opts = dict()
query_string = ''
if not is_public:
query_string = '?is_public=%s' % is_public
if 'is_public' not in search_opts:
search_opts['is_public'] = is_public
query_string = "?%s" % parse.urlencode(search_opts)
return self._list("/group_types%s" % (query_string), "group_types")
@api_versions.wraps("3.11")

View File

@ -750,9 +750,20 @@ def do_summary(cs, args):
@api_versions.wraps('3.11')
@utils.arg('--filters',
type=six.text_type,
nargs='*',
start_version='3.52',
metavar='<key=value>',
default=None,
help="Filter key and value pairs. Admin only.")
def do_group_type_list(cs, args):
"""Lists available 'group types'. (Admin only will see private types)"""
gtypes = cs.group_types.list()
search_opts = {}
# Update search option with `filters`
if hasattr(args, 'filters') and args.filters is not None:
search_opts.update(shell_utils.extract_filters(args.filters))
gtypes = cs.group_types.list(search_opts=search_opts)
shell_utils.print_group_type_list(gtypes)

View File

@ -99,7 +99,8 @@ class VolumeTypeManager(base.ManagerWithFind):
# Need to keep backwards compatibility with is_public usage. If it
# isn't included then cinder will assume you want is_public=True, which
# negatively affects the results.
search_opts['is_public'] = is_public
if 'is_public' not in search_opts:
search_opts['is_public'] = is_public
query_string = "?%s" % parse.urlencode(search_opts)
return self._list("/types%s" % query_string, "volume_types")

View File

@ -0,0 +1,13 @@
---
upgrade:
- |
Adding ``is_public`` support in ``--filters`` option for ``type-list``
and ``group-type-list`` command.
This option is used to filter volume types and group types on the basis
of visibility.
This option has 3 possible values : True, False, None with details as
follows :
* True: List public types only
* False: List private types only
* None: List both public and private types