2 # Copyright 2016 RIFT.io Inc
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from rift
.mano
.tosca_translator
.common
.utils
import _
19 from rift
.mano
.tosca_translator
.common
.utils
import convert_keys_to_python
20 from rift
.mano
.tosca_translator
.rwmano
.syntax
.mano_resource
import ManoResource
22 from toscaparser
.common
.exception
import ValidationError
25 # Name used to dynamically load appropriate map class.
26 TARGET_CLASS_NAME
= 'ToscaInitialConfig'
29 class ToscaInitialConfig(ManoResource
):
30 '''Translate TOSCA node type tosca.policies.InitialConfigPrimitive.'''
32 toscatype
= 'tosca.policies.riftio.InitialConfigPrimitive'
36 def __init__(self
, log
, primitive
, metadata
=None):
37 # TODO(Philip):Not inheriting for ManoResource, as there is no
38 # instance from parser
40 for name
, details
in primitive
.items():
42 self
.details
= details
44 self
.type_
= 'initial-cfg'
45 self
.metadata
= metadata
50 return "%s(%s)" % (self
.name
, self
.type)
52 def handle_properties(self
, nodes
, groups
):
53 tosca_props
= self
.details
54 self
.log
.debug(_("{0} with tosca properties: {1}").
55 format(self
, tosca_props
))
56 self
.properties
['name'] = tosca_props
['name']
57 self
.properties
['seq'] = \
59 self
.properties
['user-defined-script'] = \
60 tosca_props
['user_defined_script']
61 self
.scripts
.append('../scripts/{}'. \
62 format(tosca_props
['user_defined_script']))
64 if 'parameter' in tosca_props
:
65 self
.properties
['parameter'] = []
66 for name
, value
in tosca_props
['parameter'].items():
67 self
.properties
['parameter'].append({
72 self
.log
.debug(_("{0} properties: {1}").format(self
, self
.properties
))
74 def get_yang_model_gi(self
, nsd
, vnfds
):
75 props
= convert_keys_to_python(self
.properties
)
77 nsd
.initial_config_primitive
.add().from_dict(props
)
78 except Exception as e
:
79 err_msg
= _("{0} Exception nsd initial config from dict {1}: {2}"). \
80 format(self
, props
, e
)
81 self
.log
.error(err_msg
)
84 def generate_yang_model(self
, nsd
, vnfds
, use_gi
=False):
85 """Generate yang model for the node"""
86 self
.log
.debug(_("Generate YANG model for {0}").
89 for key
in ToscaInitialConfig
.IGNORE_PROPS
:
90 if key
in self
.properties
:
91 self
.properties
.pop(key
)
94 return self
.get_yang_model_gi(nsd
, vnfds
)
96 if 'initial-config-primitive' not in nsd
:
97 nsd
['initial-config-primitive'] = []
99 for key
, value
in self
.properties
.items():
101 nsd
['initial-config-primitive'].append(prim
)
103 def get_supporting_files(self
, files
, desc_id
=None):
104 if not len(self
.scripts
):
107 if desc_id
not in files
:
110 for script
in self
.scripts
:
111 files
[desc_id
].append({