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
= 'ToscaVnfNSServiceConfiguration'
31 class ToscaVnfNSServiceConfiguration(ManoResource
):
32 '''Translate TOSCA node type tosca.policies.Scaling.'''
34 toscatype
= 'tosca.policies.nfv.riftio.ns_service_primitives'
37 VALUE_TYPE_CONVERSION_MAP
= {
46 def __init__(self
, log
, policy
, metadata
=None, vnf_name
= None):
48 self
.name
= policy
.name
49 self
.type_
= 'place-grp'
50 self
.metadata
= metadata
51 self
.linked_to_vnf
= False
53 self
.service_primitive
= None
58 return "%s(%s)" % (self
.name
, self
.type)
60 def handle_properties(self
, nodes
, groups
):
61 tosca_props
= self
.get_policy_props()
62 service_primitive
= {}
63 if 'name' in tosca_props
:
64 service_primitive
['name'] = tosca_props
['name']
65 if 'user_defined_script' in tosca_props
:
66 service_primitive
['user_defined_script'] = tosca_props
['user_defined_script']
67 self
.scripts
.append('../scripts/{}'. \
68 format(tosca_props
['user_defined_script']))
71 if 'parameter' in tosca_props
:
72 service_primitive
['parameter'] = []
73 for parameter
in tosca_props
['parameter']:
75 if 'name' in parameter
:
76 prop
['name'] = parameter
['name']
77 if 'hidden' in parameter
:
78 prop
['hidden'] = parameter
['hidden']
79 if 'mandatory' in parameter
:
80 prop
['mandatory'] = parameter
['mandatory']
81 if 'data_type' in parameter
:
82 prop
['data_type'] = ToscaVnfNSServiceConfiguration
.VALUE_TYPE_CONVERSION_MAP
[parameter
['data_type']]
83 if 'default_value' in parameter
:
84 prop
['default_value'] = str(parameter
['default_value'])
85 service_primitive
['parameter'].append(prop
)
87 self
.service_primitive
= service_primitive
92 #self.properties = prop
94 def generate_yang_submodel_gi(self
, vnfd
):
97 def generate_yang_model(self
, nsd
, vnfds
, use_gi
):
98 if self
.service_primitive
is not None:
99 nsd
.service_primitive
.add().from_dict(self
.service_primitive
)
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
):
113 if desc_id
not in files
:
115 for script
in self
.scripts
:
116 files
[desc_id
].append({