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

This commit is contained in:
Zuul 2019-08-21 11:13:18 +00:00 committed by Gerrit Code Review
commit fd106c77bf
5 changed files with 61 additions and 5 deletions

View File

@ -266,7 +266,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')
@ -571,6 +581,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

@ -753,9 +753,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