Do not always require user parameters
Only require user to pass parameters if user wants to deploy translated template with Heat. For now by default deploy option is set to false as the work to allow user to automatically deploy is still in progress. The current changes makes it flexble and allows user to provide parameters at the time of manual deployment with heat instead of forcefully provding them during translation. Closes-Bug: 1541518 Partially Implements: blueprint handle-cli-user-input Change-Id: Iea7e704d045f56eb758892ff4f73d9357d718857
This commit is contained in:
parent
52e067dbf2
commit
cb9df1065a
@ -24,11 +24,12 @@ log = logging.getLogger('heat-translator')
|
||||
class TOSCATranslator(object):
|
||||
'''Invokes translation methods.'''
|
||||
|
||||
def __init__(self, tosca, parsed_params):
|
||||
def __init__(self, tosca, parsed_params, deploy=None):
|
||||
super(TOSCATranslator, self).__init__()
|
||||
self.tosca = tosca
|
||||
self.hot_template = HotTemplate()
|
||||
self.parsed_params = parsed_params
|
||||
self.deploy = deploy
|
||||
self.node_translator = None
|
||||
log.info(_('Initialized parmaters for translation.'))
|
||||
|
||||
@ -43,7 +44,8 @@ class TOSCATranslator(object):
|
||||
return self.hot_template.output_to_yaml()
|
||||
|
||||
def _translate_inputs(self):
|
||||
translator = TranslateInputs(self.tosca.inputs, self.parsed_params)
|
||||
translator = TranslateInputs(self.tosca.inputs, self.parsed_params,
|
||||
self.deploy)
|
||||
return translator.translate()
|
||||
|
||||
def _translate_outputs(self):
|
||||
|
@ -61,18 +61,19 @@ class TranslateInputs(object):
|
||||
|
||||
'''Translate TOSCA Inputs to Heat Parameters.'''
|
||||
|
||||
def __init__(self, inputs, parsed_params):
|
||||
def __init__(self, inputs, parsed_params, deploy=None):
|
||||
self.inputs = inputs
|
||||
self.parsed_params = parsed_params
|
||||
self.deploy = deploy
|
||||
|
||||
def translate(self):
|
||||
return self._translate_inputs()
|
||||
|
||||
def _translate_inputs(self):
|
||||
hot_inputs = []
|
||||
hot_default = None
|
||||
log.info(_('Translating TOSCA input type to HOT input type.'))
|
||||
for input in self.inputs:
|
||||
hot_default = None
|
||||
hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type]
|
||||
|
||||
if input.name in self.parsed_params:
|
||||
@ -82,10 +83,11 @@ class TranslateInputs(object):
|
||||
hot_default = DataEntity.validate_datatype(input.type,
|
||||
input.default)
|
||||
else:
|
||||
msg = _("Need to specify a value "
|
||||
"for input {0}.").format(input.name)
|
||||
log.error(msg)
|
||||
raise Exception(msg)
|
||||
if self.deploy:
|
||||
msg = _("Need to specify a value "
|
||||
"for input {0}.").format(input.name)
|
||||
log.error(msg)
|
||||
raise Exception(msg)
|
||||
if input.type == "scalar-unit.size":
|
||||
# Assumption here is to use this scalar-unit.size for size of
|
||||
# cinder volume in heat templates and will be in GB.
|
||||
@ -110,7 +112,8 @@ class TranslateInputs(object):
|
||||
hot_constraints = []
|
||||
if input.constraints:
|
||||
for constraint in input.constraints:
|
||||
constraint.validate(hot_default)
|
||||
if hot_default:
|
||||
constraint.validate(hot_default)
|
||||
hc, hvalue = self._translate_constraints(
|
||||
constraint.constraint_key, constraint.constraint_value)
|
||||
hot_constraints.append({hc: hvalue})
|
||||
|
@ -64,6 +64,9 @@ class TranslatorShell(object):
|
||||
raise ValueError(msg)
|
||||
|
||||
def main(self, args):
|
||||
# TODO(spzala): set self.deploy based on passed args once support for
|
||||
# --deploy argument is enabled.
|
||||
self.deploy = False
|
||||
self._validate(args)
|
||||
path = args[0].split('--template-file=')[1]
|
||||
# e.g. --template_file=translator/tests/data/tosca_helloworld.yaml
|
||||
@ -151,7 +154,7 @@ class TranslatorShell(object):
|
||||
if sourcetype == "tosca":
|
||||
log.debug(_('Loading the tosca template.'))
|
||||
tosca = ToscaTemplate(path, parsed_params, a_file)
|
||||
translator = TOSCATranslator(tosca, parsed_params)
|
||||
translator = TOSCATranslator(tosca, parsed_params, self.deploy)
|
||||
log.debug(_('Translating the tosca template.'))
|
||||
output = translator.translate()
|
||||
return output
|
||||
|
Loading…
x
Reference in New Issue
Block a user