Add the support for 'detail' flag

Magnum API supports a 'detail' flag to show the list
of cluster templates with details but that was not supported
at client.
So this patch adds the support for cluster-template-list command.

Change-Id: I7df73aae1c489132aaf091d162b1d081e65f09c7
Partial-Bug: #1674314
This commit is contained in:
Madhuri Kumari 2017-04-02 07:53:34 +00:00 committed by Madhuri Kumari
parent 06f9c511ca
commit 2850d1714f
5 changed files with 46 additions and 6 deletions

View File

@ -37,11 +37,12 @@ class FakeBayModel(BayModel):
class ShellTest(shell_test_base.TestCommandLineArgument):
def _get_expected_args_list(self, limit=None, sort_dir=None,
sort_key=None):
sort_key=None, detail=False):
expected_args = {}
expected_args['limit'] = limit
expected_args['sort_dir'] = sort_dir
expected_args['sort_key'] = sort_key
expected_args['detail'] = detail
return expected_args
@ -549,6 +550,13 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
expected_args = self._get_expected_args_list(1, 'asc', 'uuid')
mock_list.assert_called_once_with(**expected_args)
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
def test_baymodel_list_success_detailed(self, mock_list):
self._test_arg_success('baymodel-list '
'--detail')
expected_args = self._get_expected_args_list(detail=True)
mock_list.assert_called_once_with(**expected_args)
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
def test_baymodel_list_ignored_duplicated_field(self, mock_list):
mock_list.return_value = [FakeBayModel()]

View File

@ -37,11 +37,12 @@ class FakeClusterTemplate(ClusterTemplate):
class ShellTest(shell_test_base.TestCommandLineArgument):
def _get_expected_args_list(self, limit=None, sort_dir=None,
sort_key=None):
sort_key=None, detail=False):
expected_args = {}
expected_args['limit'] = limit
expected_args['sort_dir'] = sort_dir
expected_args['sort_key'] = sort_key
expected_args['detail'] = detail
return expected_args
@ -728,6 +729,14 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
expected_args = self._get_expected_args_list(1, 'asc', 'uuid')
mock_list.assert_called_once_with(**expected_args)
@mock.patch(
'magnumclient.v1.cluster_templates.ClusterTemplateManager.list')
def test_cluster_template_list_success_detailed(self, mock_list):
self._test_arg_success('cluster-template-list '
'--detail')
expected_args = self._get_expected_args_list(detail=True)
mock_list.assert_called_once_with(**expected_args)
@mock.patch(
'magnumclient.v1.cluster_templates.ClusterTemplateManager.list')
def test_cluster_template_list_ignored_duplicated_field(self, mock_list):

View File

@ -24,6 +24,11 @@ CREATION_ATTRIBUTES = ['name', 'image_id', 'flavor_id', 'master_flavor_id',
'docker_storage_driver', 'master_lb_enabled',
'floating_ip_enabled']
OUTPUT_ATTRIBUTES = CREATION_ATTRIBUTES + ['apiserver_port', 'created_at',
'insecure_registry', 'links',
'updated_at', 'cluster_distro',
'uuid']
class BaseModel(base.Resource):
# model_name needs to be overridden by any derived class.

View File

@ -15,6 +15,7 @@
from magnumclient.common import cliutils as utils
from magnumclient.common import utils as magnum_utils
from magnumclient.i18n import _
from magnumclient.v1 import basemodels
DEPRECATION_MESSAGE = (
@ -211,6 +212,10 @@ def do_baymodel_show(cs, args):
'apiserver_port, server_type, tls_disabled, registry_enabled'
)
)
@utils.arg('--detail',
action='store_true', default=False,
help=_('Show detailed information about the baymodels.')
)
@utils.deprecated(DEPRECATION_MESSAGE)
def do_baymodel_list(cs, args):
"""Print a list of baymodels.
@ -219,7 +224,11 @@ def do_baymodel_list(cs, args):
"""
nodes = cs.baymodels.list(limit=args.limit,
sort_key=args.sort_key,
sort_dir=args.sort_dir)
sort_dir=args.sort_dir,
detail=args.detail)
if args.detail:
columns = basemodels.OUTPUT_ATTRIBUTES
else:
columns = ['uuid', 'name']
columns += utils._get_list_table_columns_and_formatters(
args.fields, nodes,

View File

@ -15,6 +15,7 @@
from magnumclient.common import cliutils as utils
from magnumclient.common import utils as magnum_utils
from magnumclient.i18n import _
from magnumclient.v1 import basemodels
# Maps old parameter names to their new names and whether they are required
@ -255,11 +256,19 @@ def do_cluster_template_show(cs, args):
'apiserver_port, server_type, tls_disabled, registry_enabled'
)
)
@utils.arg('--detail',
action='store_true', default=False,
help=_('Show detailed information about the cluster templates.')
)
def do_cluster_template_list(cs, args):
"""Print a list of cluster templates."""
nodes = cs.cluster_templates.list(limit=args.limit,
sort_key=args.sort_key,
sort_dir=args.sort_dir)
sort_dir=args.sort_dir,
detail=args.detail)
if args.detail:
columns = basemodels.OUTPUT_ATTRIBUTES
else:
columns = ['uuid', 'name']
columns += utils._get_list_table_columns_and_formatters(
args.fields, nodes,