* YANG to TOSCA translator
[osm/SO.git] / common / python / rift / mano / tosca_translator / rwmano / 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 # Copyright 2016 RIFT.io Inc
15
16 from rift.mano.tosca_translator.common.utils import _
17 from rift.mano.tosca_translator.rwmano.syntax.mano_output import ManoOutput
18
19
20 class TranslateOutputs(object):
21 '''Translate TOSCA Outputs to Heat Outputs.'''
22
23 def __init__(self, log, outputs, node_translator):
24 log.debug(_('Translating TOSCA outputs to MANO outputs.'))
25 self.log = log
26 self.outputs = outputs
27 self.nodes = node_translator
28
29 def translate(self):
30 return self._translate_outputs()
31
32 def _translate_outputs(self):
33 mano_outputs = []
34 for output in self.outputs:
35 if output.value.name == 'get_attribute':
36 get_parameters = output.value.args
37 mano_target = self.nodes.find_mano_resource(get_parameters[0])
38 mano_value = mano_target.get_mano_attribute(get_parameters[1],
39 get_parameters)
40 mano_outputs.append(ManoOutput(output.name,
41 mano_value,
42 output.description))
43 else:
44 mano_outputs.append(ManoOutput(output.name,
45 output.value,
46 output.description))
47 return mano_outputs