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:
Sahdev Zala 2016-02-08 07:41:18 -08:00
parent 52e067dbf2
commit cb9df1065a
3 changed files with 18 additions and 10 deletions

View File

@ -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):

View File

@ -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,6 +83,7 @@ class TranslateInputs(object):
hot_default = DataEntity.validate_datatype(input.type,
input.default)
else:
if self.deploy:
msg = _("Need to specify a value "
"for input {0}.").format(input.name)
log.error(msg)
@ -110,6 +112,7 @@ class TranslateInputs(object):
hot_constraints = []
if input.constraints:
for constraint in input.constraints:
if hot_default:
constraint.validate(hot_default)
hc, hvalue = self._translate_constraints(
constraint.constraint_key, constraint.constraint_value)

View File

@ -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