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
14 # Copyright 2016 RIFT.io Inc
16 from rift
.mano
.tosca_translator
.common
.utils
import _
17 from rift
.mano
.tosca_translator
.rwmano
.syntax
.mano_template
import ManoTemplate
18 from rift
.mano
.tosca_translator
.rwmano
.translate_inputs
import TranslateInputs
19 from rift
.mano
.tosca_translator
.rwmano
.translate_node_templates \
20 import TranslateNodeTemplates
21 from rift
.mano
.tosca_translator
.rwmano
.translate_outputs \
22 import TranslateOutputs
25 class TOSCATranslator(object):
26 '''Invokes translation methods.'''
28 def __init__(self
, log
, tosca
, parsed_params
, deploy
=None, use_gi
=False):
29 super(TOSCATranslator
, self
).__init
__()
32 self
.mano_template
= ManoTemplate(log
)
33 self
.parsed_params
= parsed_params
36 self
.node_translator
= None
37 log
.info(_('Initialized parmaters for translation.'))
41 self
.mano_template
.description
= self
.tosca
.description
42 self
.mano_template
.parameters
= self
._translate
_inputs
()
43 self
.node_translator
= TranslateNodeTemplates(self
.log
,
46 self
.mano_template
.resources
= self
.node_translator
.translate()
47 # TODO(Philip): Currently doing groups and policies seperately
48 # due to limitations with parser
49 self
.mano_template
.groups
= self
.node_translator
.translate_groups()
50 self
.mano_template
.policies
= self
.node_translator
.translate_policies()
51 self
.mano_template
.metadata
= self
.node_translator
.metadata
52 # Currently we do not use outputs, so not processing them
53 # self.mano_template.outputs = self._translate_outputs()
54 return self
.mano_template
.output_to_yang(use_gi
=self
.use_gi
)
56 def _translate_inputs(self
):
57 translator
= TranslateInputs(self
.log
,
61 return translator
.translate()
63 def _translate_outputs(self
):
64 translator
= TranslateOutputs(self
.log
,
67 return translator
.translate()
69 # check all properties for all node and ensure they are resolved
71 def _resolve_input(self
):
72 for n
in self
.tosca
.nodetemplates
:
73 for node_prop
in n
.get_properties_objects():
74 if isinstance(node_prop
.value
, dict):
75 if 'get_input' in node_prop
.value
:
77 self
.parsed_params
[node_prop
.value
['get_input']]
79 msg
= (_('Must specify all input values in '
80 'TOSCA template, missing %s.') %
81 node_prop
.value
['get_input'])