Add an option to generate template based on resource type
Add an option 'template_type' to allow user specify what kind of template to generate. Blueprint support-to-generate-hot-templates Change-Id: I4aa6c2688533900ea26f59533883984b337c1c4d
This commit is contained in:
@@ -60,6 +60,8 @@ class ResourceTypeManagerTest(testtools.TestCase):
|
||||
def test_generate_template(self):
|
||||
key = 'resource_types'
|
||||
resource_type = 'OS::Nova::KeyPair'
|
||||
expect = ('GET', '/resource_types/OS%3A%3ANova%3A%3AKeyPair/template')
|
||||
template_type = 'cfn'
|
||||
expect = ('GET', '/resource_types/OS%3A%3ANova%3A%3AKeyPair/template'
|
||||
'?template_type=cfn')
|
||||
manager = self._base_test(expect, key)
|
||||
manager.generate_template(resource_type)
|
||||
manager.generate_template(resource_type, template_type)
|
||||
|
||||
@@ -2806,12 +2806,13 @@ class ShellTestResourceTypes(ShellBase):
|
||||
|
||||
http.HTTPClient.json_request(
|
||||
'GET', '/resource_types/OS%3A%3ANova%3A%3AKeyPair/template'
|
||||
'?template_type=hot'
|
||||
).AndReturn((resp, resp_dict))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
show_text = self.shell(
|
||||
'resource-type-template -F yaml OS::Nova::KeyPair')
|
||||
'resource-type-template -F yaml -t hot OS::Nova::KeyPair')
|
||||
required = [
|
||||
"heat_template_version: '2013-05-23'",
|
||||
"outputs: {}",
|
||||
@@ -2835,6 +2836,7 @@ class ShellTestResourceTypes(ShellBase):
|
||||
|
||||
http.HTTPClient.json_request(
|
||||
'GET', '/resource_types/OS%3A%3ANova%3A%3AKeyPair/template'
|
||||
'?template_type=cfn'
|
||||
).AndReturn((resp, resp_dict))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -47,8 +47,11 @@ class ResourceTypeManager(base.BaseManager):
|
||||
resp, body = self.client.json_request('GET', url_str)
|
||||
return body
|
||||
|
||||
def generate_template(self, resource_type):
|
||||
def generate_template(self, resource_type, template_type='cfn'):
|
||||
url_str = '/resource_types/%s/template' % (
|
||||
parse.quote(encodeutils.safe_encode(resource_type), ''))
|
||||
if template_type:
|
||||
url_str += '?%s' % parse.urlencode(
|
||||
{'template_type': template_type}, True)
|
||||
resp, body = self.client.json_request('GET', url_str)
|
||||
return body
|
||||
|
||||
@@ -630,12 +630,16 @@ def do_resource_type_show(hc, args):
|
||||
|
||||
@utils.arg('resource_type', metavar='<RESOURCE_TYPE>',
|
||||
help=_('Resource type to generate a template for.'))
|
||||
@utils.arg('-t', '--template-type', metavar='<TEMPLATE_TYPE>',
|
||||
default='cfn',
|
||||
help=_('Template type to generate, hot or cfn.'))
|
||||
@utils.arg('-F', '--format', metavar='<FORMAT>',
|
||||
help=_("The template output format, one of: %s.")
|
||||
% ', '.join(utils.supported_formats.keys()))
|
||||
def do_resource_type_template(hc, args):
|
||||
'''Generate a template based on a resource type.'''
|
||||
fields = {'resource_type': args.resource_type}
|
||||
fields = {'resource_type': args.resource_type,
|
||||
'template_type': args.template_type}
|
||||
try:
|
||||
template = hc.resource_types.generate_template(**fields)
|
||||
except exc.HTTPNotFound:
|
||||
@@ -748,6 +752,9 @@ def do_resource_show(hc, args):
|
||||
|
||||
@utils.arg('resource_type', metavar='<RESOURCE_TYPE>',
|
||||
help=_('Resource type to generate a template for.'))
|
||||
@utils.arg('-t', '--template-type', metavar='<TEMPLATE_TYPE>',
|
||||
default='cfn',
|
||||
help=_('Template type to generate, hot or cfn.'))
|
||||
@utils.arg('-F', '--format', metavar='<FORMAT>',
|
||||
help=_("The template output format, one of: %s.")
|
||||
% ', '.join(utils.supported_formats.keys()))
|
||||
|
||||
Reference in New Issue
Block a user