osc resource-type-show description option
Add new option to osc resource-type-show, which allows to print description of specified resource type. Change-Id: I99347a1aa01cea3fe7e9686e06c7d8180e6551b1 Depends-on: #I148bb7764af4db45b75ce63d7fa58daa210b3ed4 Closes-bug: #1558049
This commit is contained in:
parent
992bef89ce
commit
52cb12d86e
@ -42,11 +42,21 @@ class ResourceTypeShow(format_utils.YamlFormat):
|
||||
metavar='<template-type>',
|
||||
help=_('Optional template type to generate, hot or cfn')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help=_('Show resource type with corresponding description.')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
if parsed_args.template_type is not None and parsed_args.long:
|
||||
msg = _('Cannot use --template-type and --long in one time.')
|
||||
raise exc.CommandError(msg)
|
||||
|
||||
heat_client = self.app.client_manager.orchestration
|
||||
return _show_resourcetype(heat_client, parsed_args)
|
||||
|
||||
@ -63,7 +73,8 @@ def _show_resourcetype(heat_client, parsed_args):
|
||||
'template_type': template_type}
|
||||
data = heat_client.resource_types.generate_template(**fields)
|
||||
else:
|
||||
data = heat_client.resource_types.get(parsed_args.resource_type)
|
||||
data = heat_client.resource_types.get(parsed_args.resource_type,
|
||||
parsed_args.long)
|
||||
except heat_exc.HTTPNotFound:
|
||||
raise exc.CommandError(
|
||||
_('Resource type not found: %s') % parsed_args.resource_type)
|
||||
|
@ -42,7 +42,7 @@ class TestResourceTypeShow(TestResourceType):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.resource_types.get.assert_called_once_with(
|
||||
'OS::Heat::None')
|
||||
'OS::Heat::None', False)
|
||||
|
||||
def test_resourcetype_show_json(self):
|
||||
arglist = ['OS::Heat::None',
|
||||
@ -50,7 +50,7 @@ class TestResourceTypeShow(TestResourceType):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.resource_types.get.assert_called_once_with(
|
||||
'OS::Heat::None')
|
||||
'OS::Heat::None', False)
|
||||
|
||||
def test_resourcetype_show_error_get(self):
|
||||
arglist = ['OS::Heat::None']
|
||||
@ -101,6 +101,20 @@ class TestResourceTypeShow(TestResourceType):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
def test_resourcetype_show_with_description(self):
|
||||
arglist = ['OS::Heat::None', '--long']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.resource_types.get.assert_called_with(
|
||||
'OS::Heat::None', True)
|
||||
|
||||
def test_resourcetype_show_long_and_template_type_error(self):
|
||||
arglist = ['OS::Heat::None',
|
||||
'--template-type', 'cfn',
|
||||
'--long']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
|
||||
class TestTypeList(TestResourceType):
|
||||
|
||||
|
@ -62,15 +62,17 @@ class ResourceTypeManager(base.BaseManager):
|
||||
|
||||
return self._list(url, self.KEY)
|
||||
|
||||
def get(self, resource_type):
|
||||
def get(self, resource_type, with_description=False):
|
||||
"""Get the details for a specific resource_type.
|
||||
|
||||
:param resource_type: name of the resource type to get the details for
|
||||
:param with_description: return result with description or not
|
||||
"""
|
||||
url_str = '/%s/%s' % (
|
||||
self.KEY,
|
||||
parse.quote(encodeutils.safe_encode(resource_type), ''))
|
||||
resp = self.client.get(url_str)
|
||||
resp = self.client.get(url_str,
|
||||
params={'with_description': with_description})
|
||||
body = utils.get_response_body(resp)
|
||||
return body
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user