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
21 from toscaparser
.functions
import GetInput
22 from rift
.mano
.tosca_translator
.common
.utils
import convert_keys_to_python
24 from toscaparser
.common
.exception
import ValidationError
27 # Name used to dynamically load appropriate map class.
28 TARGET_CLASS_NAME
= 'ToscaVnfConfiguration'
31 class ToscaVnfConfiguration(ManoResource
):
32 '''Translate TOSCA node type tosca.policies.Scaling.'''
34 toscatype
= 'tosca.policies.nfv.riftio.vnf_configuration'
38 def __init__(self
, log
, policy
, metadata
=None, vnf_name
= None):
40 self
.name
= policy
.name
41 self
.type_
= 'place-grp'
42 self
.metadata
= metadata
45 self
.linked_to_vnf
= True
46 self
._vnf
_name
= vnf_name
51 return "%s(%s)" % (self
.name
, self
.type)
53 def handle_properties(self
, nodes
, groups
):
54 tosca_props
= self
.get_policy_props()
56 vnf_node
= self
.get_node_with_name(self
._vnf
_name
, nodes
)
57 self
._vnf
_id
= vnf_node
.id
58 self
.properties
["vnf-configuration"] = {}
60 prop
["config-attributes"] = {}
62 if 'config' in tosca_props
:
63 if 'config_delay' in tosca_props
['config']:
64 prop
["config-attributes"]['config-delay'] = tosca_props
['config']['config_delay']
65 if 'config_priority' in tosca_props
['config']:
66 prop
["config-attributes"]['config-priority'] = tosca_props
['config']['config_priority']
67 if 'config_template' in tosca_props
['config']:
68 prop
["config-template"] = tosca_props
['config']['config_template']
69 if 'config_details' in tosca_props
['config']:
70 if 'script_type' in tosca_props
['config']['config_details']:
71 prop
["script"]["script-type"] = tosca_props
['config']['config_details']['script_type']
72 if 'initial_config' in tosca_props
:
73 prop
['initial-config-primitive'] = []
74 #print("Weleek " + str(tosca_props['initial_config']))
75 for init_config
in tosca_props
['initial_config']:
76 if 'parameter' in init_config
:
77 parameters
= init_config
.pop('parameter')
78 init_config
['parameter'] = []
79 for key
, value
in parameters
.items():
80 init_config
['parameter'].append({'name': key
, 'value': str(value
)})
81 if 'user_defined_script' in init_config
:
82 self
.scripts
.append('../scripts/{}'. \
83 format(init_config
['user_defined_script']))
84 prop
['initial-config-primitive'].append(init_config
)
86 self
.properties
= prop
88 def generate_yang_submodel_gi(self
, vnfd
):
92 props
= convert_keys_to_python(self
.properties
)
93 vnfd
.vnf_configuration
.from_dict(props
)
94 except Exception as e
:
95 err_msg
= _("{0} Exception vdu from dict {1}: {2}"). \
96 format(self
, props
, e
)
97 self
.log
.error(err_msg
)
100 def get_policy_props(self
):
103 for prop
in self
.policy
.get_properties_objects():
104 if isinstance(prop
.value
, GetInput
):
105 tosca_props
[prop
.name
] = {'get_param': prop
.value
.input_name
}
107 tosca_props
[prop
.name
] = prop
.value
109 def get_supporting_files(self
, files
, desc_id
=None):
110 if not len(self
.scripts
):
113 if self
._vnf
_id
not in files
:
116 for script
in self
.scripts
:
117 files
[self
._vnf
_id
].append({