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 for init_config
in tosca_props
['initial_config']:
75 if 'parameter' in init_config
:
76 parameters
= init_config
.pop('parameter')
77 init_config
['parameter'] = []
78 for parameter
in parameters
:
79 for key
, value
in parameter
.items():
80 init_config
['parameter'].append({'name': key
, 'value': str(value
)})
82 if 'user_defined_script' in init_config
:
83 self
.scripts
.append('../scripts/{}'. \
84 format(init_config
['user_defined_script']))
85 prop
['initial-config-primitive'].append(init_config
)
87 self
.properties
= prop
89 def generate_yang_submodel_gi(self
, vnfd
):
93 props
= convert_keys_to_python(self
.properties
)
94 vnfd
.vnf_configuration
.from_dict(props
)
95 except Exception as e
:
96 err_msg
= _("{0} Exception vdu from dict {1}: {2}"). \
97 format(self
, props
, e
)
98 self
.log
.error(err_msg
)
101 def get_policy_props(self
):
104 for prop
in self
.policy
.get_properties_objects():
105 if isinstance(prop
.value
, GetInput
):
106 tosca_props
[prop
.name
] = {'get_param': prop
.value
.input_name
}
108 tosca_props
[prop
.name
] = prop
.value
110 def get_supporting_files(self
, files
, desc_id
=None):
111 if not len(self
.scripts
):
114 if self
._vnf
_id
not in files
:
115 files
[self
._vnf
_id
] = []
117 for script
in self
.scripts
:
118 files
[self
._vnf
_id
].append({