Merge "netsted template validate type error"
[parser.git] / tosca2heat / heat-translator / translator / hot / translate_outputs.py
1 #
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
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
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
12 # under the License.
13
14 import logging
15
16 from toscaparser.utils.gettextutils import _
17 from translator.hot.syntax.hot_output import HotOutput
18
19 log = logging.getLogger('heat-translator')
20
21
22 class TranslateOutputs(object):
23     '''Translate TOSCA Outputs to Heat Outputs.'''
24
25     def __init__(self, outputs, node_translator):
26         log.debug(_('Translating TOSCA outputs to HOT outputs.'))
27         self.outputs = outputs
28         self.nodes = node_translator
29
30     def translate(self):
31         return self._translate_outputs()
32
33     def _translate_outputs(self):
34         hot_outputs = []
35         for output in self.outputs:
36             if output.value.name == 'get_attribute':
37                 get_parameters = output.value.args
38                 hot_target = self.nodes.find_hot_resource(get_parameters[0])
39                 hot_value = hot_target.get_hot_attribute(get_parameters[1],
40                                                          get_parameters)
41                 hot_outputs.append(HotOutput(output.name,
42                                              hot_value,
43                                              output.description))
44             else:
45                 hot_outputs.append(HotOutput(output.name,
46                                              output.value,
47                                              output.description))
48         return hot_outputs