2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
15 from toscaparser.utils.gettextutils import _
16 from translator.hot.syntax.hot_template import HotTemplate
17 from translator.hot.translate_inputs import TranslateInputs
18 from translator.hot.translate_node_templates import TranslateNodeTemplates
19 from translator.hot.translate_outputs import TranslateOutputs
21 log = logging.getLogger('heat-translator')
24 class TOSCATranslator(object):
25 '''Invokes translation methods.'''
27 def __init__(self, tosca, parsed_params, deploy=None):
28 super(TOSCATranslator, self).__init__()
30 self.hot_template = HotTemplate()
31 self.parsed_params = parsed_params
33 self.node_translator = None
34 log.info(_('Initialized parmaters for translation.'))
38 self.hot_template.description = self.tosca.description
39 self.hot_template.parameters = self._translate_inputs()
40 self.node_translator = TranslateNodeTemplates(self.tosca,
42 self.hot_template.resources = self.node_translator.translate()
43 self.hot_template.outputs = self._translate_outputs()
44 return self.hot_template.output_to_yaml()
46 def _translate_inputs(self):
47 translator = TranslateInputs(self.tosca.inputs, self.parsed_params,
49 return translator.translate()
51 def _translate_outputs(self):
52 translator = TranslateOutputs(self.tosca.outputs, self.node_translator)
53 return translator.translate()
55 # check all properties for all node and ensure they are resolved
57 def _resolve_input(self):
58 for n in self.tosca.nodetemplates:
59 for node_prop in n.get_properties_objects():
60 if isinstance(node_prop.value, dict):
62 self.parsed_params[node_prop.value['get_input']]
64 msg = (_('Must specify all input values in \
65 TOSCA template, missing %s.') %
66 node_prop.value['get_input'])