0a54bcc013076b6f675b0b28823afa09a4bda0fe
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
49 return "%s(%s)" % (self
.name
, self
.type)
51 def handle_properties(self
, nodes
, groups
):
52 tosca_props
= self
.get_policy_props()
53 self
.properties
["vnf-configuration"] = {}
55 prop
["config-attributes"] = {}
57 if 'config' in tosca_props
:
58 if 'config_delay' in tosca_props
['config']:
59 prop
["config-attributes"]['config-delay'] = tosca_props
['config']['config_delay']
60 if 'config_priority' in tosca_props
['config']:
61 prop
["config-attributes"]['config-priority'] = tosca_props
['config']['config_priority']
62 if 'config_template' in tosca_props
['config']:
63 prop
["config-template"] = tosca_props
['config']['config_template']
64 if 'config_details' in tosca_props
['config']:
65 if 'script_type' in tosca_props
['config']['config_details']:
66 prop
["script"]["script-type"] = tosca_props
['config']['config_details']['script_type']
67 self
.properties
= prop
69 def generate_yang_submodel_gi(self
, vnfd
):
73 props
= convert_keys_to_python(self
.properties
)
74 vnfd
.vnf_configuration
.from_dict(props
)
75 except Exception as e
:
76 err_msg
= _("{0} Exception vdu from dict {1}: {2}"). \
77 format(self
, props
, e
)
78 self
.log
.error(err_msg
)
81 def get_policy_props(self
):
84 for prop
in self
.policy
.get_properties_objects():
85 if isinstance(prop
.value
, GetInput
):
86 tosca_props
[prop
.name
] = {'get_param': prop
.value
.input_name
}
88 tosca_props
[prop
.name
] = prop
.value