1 # Copyright 2016 RIFT.io Inc
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from copy
import deepcopy
18 from rift
.mano
.yang_translator
.common
.exception
import ValidationError
19 from rift
.mano
.yang_translator
.common
.utils
import _
20 from rift
.mano
.yang_translator
.rwmano
.syntax
.tosca_resource \
23 TARGET_CLASS_NAME
= 'YangVld'
26 class YangVld(ToscaResource
):
27 '''Class for RIFT.io YANG VLD descriptor translation to TOSCA type.'''
31 OTHER_KEYS
= (VNFD_CP_REF
) = \
32 ('vnfd_connection_point_ref')
35 'ELAN': ToscaResource
.T_VL1
,
43 super(YangVld
, self
).__init
__(log
,
50 def process_vld(self
, vnfds
):
51 self
.log
.debug(_("Process VLD desc {0}").format(self
.name
))
53 dic
= deepcopy(self
.yang
)
55 for key
in self
.REQUIRED_FIELDS
:
56 self
.props
[key
] = dic
.pop(key
)
58 self
.id = self
.props
[self
.ID
]
60 if self
.TYPE_Y
in dic
:
61 self
.props
[self
.TYPE
] = dic
.pop(self
.TYPE_Y
)
62 if self
.props
[self
.TYPE
] not in self
.VLD_TYPE_MAP
:
63 err_msg
= (_("{0}: VLD type {1} not supported").
64 format(self
, self
.props
[self
.TYPE
]))
65 self
.log
.error(err_msg
)
66 raise ValidationError(message
=err_msg
)
68 if self
.VNFD_CP_REF
in dic
:
69 for cp_ref
in dic
.pop(self
.VNFD_CP_REF
):
70 vnfd_idx
= cp_ref
.pop(self
.MEM_VNF_INDEX_REF
)
71 vnfd_id
= cp_ref
.pop(self
.VNFD_ID_REF
)
72 vnfd_cp
= cp_ref
.pop(self
.VNFD_CP_REF
)
74 vnfd
= vnfds
[vnfd_idx
]
75 if vnfd
.id == vnfd_id
:
76 # Update the CP as linked to this VLD
77 vnfd
.update_cp_vld(vnfd_cp
, self
.name
)
79 err_msg
= (_("{0}, The VNFD memebr index {1} and id "
80 "{2} did not match the VNFD {3} with "
81 "id {4}").format(self
, vnfd_idx
, vnfd_id
,
83 self
.log
.error(err_msg
)
84 raise ValidationError(message
=err_msg
)
86 err_msg
= (_("{0}, Did not find VNFD memer index {1}").
87 format(self
, vnfd_idx
))
88 self
.log
.error(err_msg
)
89 raise ValidationError(message
=err_msg
)
91 self
.remove_ignored_fields(dic
)
93 self
.log
.warn(_("{0}, Did not process the following for "
95 format(self
, self
.props
, dic
))
96 self
.log
.debug(_("{0}, VLD: {1}").format(self
, self
.props
))
98 def generate_tosca_type(self
, tosca
):
99 self
.log
.debug(_("{0} Generate tosa types").
102 if self
.T_VL1
not in tosca
[self
.NODE_TYPES
]:
103 tosca
[self
.NODE_TYPES
][self
.T_VL1
] = {
104 self
.DERIVED_FROM
: 'tosca.nodes.nfv.VL.ELAN',
107 {self
.TYPE
: self
.STRING
},
113 def generate_tosca_template(self
, tosca
):
114 self
.log
.debug(_("{0} Generate tosa types").
118 node
[self
.TYPE
] = self
.VLD_TYPE_MAP
[self
.props
.pop(self
.TYPE
)]
121 self
.props
.pop(self
.ID
)
122 self
.props
.pop(self
.VERSION
)
123 node
[self
.PROPERTIES
] = self
.props
125 tosca
[self
.TOPOLOGY_TMPL
][self
.NODE_TMPL
][self
.name
] = node