heat cli: encapsulate template arg-parsing
Encapsulate template argument parsing in a helper function cleans up some duplication and provides a single place to add swift-template-url logic Ref #216 Change-Id: I36515f318ed79899a2710899ffca83e4452c61f4 Signed-off-by: Steven Hardy <shardy@redhat.com>
This commit is contained in:
parent
4bd5c4a9dd
commit
84ddb9fb65
43
bin/heat
43
bin/heat
|
@ -52,6 +52,18 @@ from heat.common import exception
|
|||
from heat import utils
|
||||
|
||||
|
||||
def get_template_param(options):
|
||||
'''
|
||||
Helper function to extract the template in whatever
|
||||
format has been specified by the cli options
|
||||
'''
|
||||
param={}
|
||||
if options.template_file:
|
||||
param['TemplateBody'] = open(options.template_file).read()
|
||||
elif options.template_url:
|
||||
param['TemplateUrl'] = options.template_url
|
||||
return param
|
||||
|
||||
@utils.catch_error('validate')
|
||||
def template_validate(options, arguments):
|
||||
'''
|
||||
|
@ -66,10 +78,9 @@ def template_validate(options, arguments):
|
|||
--template-url: Specify a URL pointing to a stack description template.
|
||||
'''
|
||||
parameters = {}
|
||||
if options.template_file:
|
||||
parameters['TemplateBody'] = open(options.template_file).read()
|
||||
elif options.template_url:
|
||||
parameters['TemplateUrl'] = options.template_url
|
||||
templ_param = get_template_param(options)
|
||||
if templ_param:
|
||||
parameters.update(templ_param)
|
||||
else:
|
||||
logging.error('Please specify a template file or url')
|
||||
return utils.FAILURE
|
||||
|
@ -90,10 +101,9 @@ def estimate_template_cost(options, arguments):
|
|||
logging.error("as the first argument")
|
||||
return utils.FAILURE
|
||||
|
||||
if options.template_file:
|
||||
parameters['TemplateBody'] = open(options.template_file).read()
|
||||
elif options.template_url:
|
||||
parameters['TemplateUrl'] = options.template_url
|
||||
templ_param = get_template_param(options)
|
||||
if templ_param:
|
||||
parameters.update(templ_param)
|
||||
else:
|
||||
logging.error('Please specify a template file or url')
|
||||
return utils.FAILURE
|
||||
|
@ -149,10 +159,9 @@ def stack_create(options, arguments):
|
|||
|
||||
parameters['TimeoutInMinutes'] = options.timeout
|
||||
|
||||
if options.template_file:
|
||||
parameters['TemplateBody'] = open(options.template_file).read()
|
||||
elif options.template_url:
|
||||
parameters['TemplateUrl'] = options.template_url
|
||||
templ_param = get_template_param(options)
|
||||
if templ_param:
|
||||
parameters.update(templ_param)
|
||||
else:
|
||||
logging.error('Please specify a template file or url')
|
||||
return utils.FAILURE
|
||||
|
@ -191,10 +200,12 @@ def stack_update(options, arguments):
|
|||
logging.error("as the first argument")
|
||||
return utils.FAILURE
|
||||
|
||||
if options.template_file:
|
||||
parameters['TemplateBody'] = open(options.template_file).read()
|
||||
elif options.template_url:
|
||||
parameters['TemplateUrl'] = options.template_url
|
||||
templ_param = get_template_param(options)
|
||||
if templ_param:
|
||||
parameters.update(templ_param)
|
||||
else:
|
||||
logging.error('Please specify a template file or url')
|
||||
return utils.FAILURE
|
||||
|
||||
c = get_client(options)
|
||||
parameters.update(c.format_parameters(options))
|
||||
|
|
Loading…
Reference in New Issue