blob: e4b10ceb5814043be96bb57ec4684cc5e93c1429 [file] [log] [blame]
tierno0f98af52018-03-19 10:28:22 +01001# -*- coding: utf-8 -*-
2
tiernod125caf2018-11-22 16:05:54 +00003# 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
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
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
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
tierno0f98af52018-03-19 10:28:22 +010016from jsonschema import validate as js_v, exceptions as js_e
tierno36ec8602018-11-02 17:27:11 +010017from http import HTTPStatus
garciadeblasdaf8cc52018-11-30 14:17:20 +010018from copy import deepcopy
delacruzramoc061f562019-04-05 11:00:02 +020019from uuid import UUID # To test for valid UUID
tierno0f98af52018-03-19 10:28:22 +010020
21__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
22__version__ = "0.1"
23version_date = "Mar 2018"
24
25"""
26Validator of input data using JSON schemas for those items that not contains an OSM yang information model
27"""
28
29# Basis schemas
30patern_name = "^[ -~]+$"
tiernofd160572019-01-21 10:41:37 +000031shortname_schema = {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()\\.\\$'\"]+$"}
tierno0f98af52018-03-19 10:28:22 +010032passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
tierno0f98af52018-03-19 10:28:22 +010033name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
tierno0da52252018-06-27 15:47:22 +020034string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
tierno0f98af52018-03-19 10:28:22 +010035xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
36description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
tierno441dbbf2018-07-10 12:52:48 +020037id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
38bool_schema = {"type": "boolean"}
39null_schema = {"type": "null"}
tierno2236d202018-05-16 19:05:16 +020040# "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
tierno0f98af52018-03-19 10:28:22 +010041id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
tiernof759d822018-06-11 18:54:54 +020042time_schema = {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"}
tierno87006042018-10-24 12:50:20 +020043pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"}
tierno42fce592018-11-02 09:23:43 +010044# allows [] for wildcards. For that reason huge length limit is set
45pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
K Sai Kiran990ac462020-05-20 12:25:12 +053046http_schema = {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
tierno0f98af52018-03-19 10:28:22 +010047bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
48memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
49integer0_schema = {"type": "integer", "minimum": 0}
50integer1_schema = {"type": "integer", "minimum": 1}
tierno87006042018-10-24 12:50:20 +020051path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
tierno0f98af52018-03-19 10:28:22 +010052vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
53vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
54mac_schema = {"type": "string",
55 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0
tiernocb83c942018-09-24 17:28:13 +020056dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
tierno0f98af52018-03-19 10:28:22 +010057# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
58ip_schema = {"type": "string",
tierno87006042018-10-24 12:50:20 +020059 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"}
tierno0f98af52018-03-19 10:28:22 +010060ip_prefix_schema = {"type": "string",
tierno87006042018-10-24 12:50:20 +020061 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
tierno2236d202018-05-16 19:05:16 +020062 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
tierno0f98af52018-03-19 10:28:22 +010063port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
64object_schema = {"type": "object"}
65schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
66# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
67log_level_schema = {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
68checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
69size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +020070array_edition_schema = {
71 "type": "object",
72 "patternProperties": {
tiernofd160572019-01-21 10:41:37 +000073 "^\\$": {}
tiernocd54a4a2018-09-12 16:40:35 +020074 },
75 "additionalProperties": False,
76 "minProperties": 1,
77}
tiernocb83c942018-09-24 17:28:13 +020078nameshort_list_schema = {
79 "type": "array",
80 "minItems": 1,
tiernofd160572019-01-21 10:41:37 +000081 "items": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +020082}
tiernocd54a4a2018-09-12 16:40:35 +020083
tierno0f98af52018-03-19 10:28:22 +010084
tierno441dbbf2018-07-10 12:52:48 +020085ns_instantiate_vdu = {
86 "title": "ns action instantiate input schema for vdu",
87 "$schema": "http://json-schema.org/draft-04/schema#",
88 "type": "object",
89 "properties": {
90 "id": name_schema,
91 "volume": {
92 "type": "array",
93 "minItems": 1,
94 "items": {
95 "type": "object",
96 "properties": {
97 "name": name_schema,
98 "vim-volume-id": name_schema,
99 },
100 "required": ["name", "vim-volume-id"],
101 "additionalProperties": False
102 }
103 },
104 "interface": {
105 "type": "array",
106 "minItems": 1,
107 "items": {
108 "type": "object",
109 "properties": {
110 "name": name_schema,
111 "ip-address": ip_schema,
112 "mac-address": mac_schema,
113 "floating-ip-required": bool_schema,
114 },
115 "required": ["name"],
116 "additionalProperties": False
117 }
118 }
119 },
120 "required": ["id"],
121 "additionalProperties": False
122}
123
124ip_profile_dns_schema = {
125 "type": "array",
126 "minItems": 1,
127 "items": {
128 "type": "object",
129 "properties": {
130 "address": ip_schema,
131 },
132 "required": ["address"],
133 "additionalProperties": False
134 }
135}
136
137ip_profile_dhcp_schema = {
138 "type": "object",
139 "properties": {
140 "enabled": {"type": "boolean"},
141 "count": integer1_schema,
142 "start-address": ip_schema
143 },
144 "additionalProperties": False,
145}
146
147ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000148 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200149 "$schema": "http://json-schema.org/draft-04/schema#",
150 "type": "object",
151 "properties": {
152 "ip-version": {"enum": ["ipv4", "ipv6"]},
153 "subnet-address": ip_prefix_schema,
154 "gateway-address": ip_schema,
155 "dns-server": ip_profile_dns_schema,
156 "dhcp-params": ip_profile_dhcp_schema,
157 }
158}
159
160ip_profile_update_schema = {
tierno2a929042020-03-10 16:34:25 +0000161 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200162 "$schema": "http://json-schema.org/draft-04/schema#",
163 "type": "object",
164 "properties": {
165 "ip-version": {"enum": ["ipv4", "ipv6"]},
166 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
167 "gateway-address": {"oneOf": [null_schema, ip_schema]},
168 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
169
170 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
171 },
172 "additionalProperties": False
173}
174
kbsub21f03f52019-10-17 16:26:56 +0000175provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000176 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000177 "$schema": "http://json-schema.org/draft-04/schema#",
178 "type": "object",
179 "properties": {
180 "physical-network": name_schema,
181 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000182 "sdn-ports": { # external ports to append to the SDN-assist network
183 "type": "array",
184 "items": {
185 "type": "object",
186 "properties": {
187 "switch_id": shortname_schema,
188 "switch_port": shortname_schema,
189 "mac_address": mac_schema,
190 "vlan": vlan_schema,
191 },
192 "additionalProperties": True
193 }
194 },
195 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000196 },
tierno2a929042020-03-10 16:34:25 +0000197 "additionalProperties": True
kbsub21f03f52019-10-17 16:26:56 +0000198}
199
tierno441dbbf2018-07-10 12:52:48 +0200200ns_instantiate_internal_vld = {
201 "title": "ns action instantiate input schema for vdu",
202 "$schema": "http://json-schema.org/draft-04/schema#",
203 "type": "object",
204 "properties": {
205 "name": name_schema,
206 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100207 "vim-network-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200208 "ip-profile": ip_profile_update_schema,
kbsub21f03f52019-10-17 16:26:56 +0000209 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200210 "internal-connection-point": {
211 "type": "array",
212 "minItems": 1,
213 "items": {
214 "type": "object",
215 "properties": {
216 "id-ref": name_schema,
217 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200218 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200219 },
tiernob7c6f2a2018-09-03 14:32:10 +0200220 "required": ["id-ref"],
221 "minProperties": 2,
tierno441dbbf2018-07-10 12:52:48 +0200222 "additionalProperties": False
223 },
224 }
225 },
226 "required": ["name"],
227 "minProperties": 2,
228 "additionalProperties": False
229}
tierno65acb4d2018-04-06 16:42:40 +0200230
tiernofd160572019-01-21 10:41:37 +0000231additional_params_for_vnf = {
232 "type": "array",
233 "items": {
234 "type": "object",
235 "properties": {
236 "member-vnf-index": name_schema,
237 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000238 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000239 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000240 "additionalParamsForVdu": {
241 "type": "array",
242 "items": {
243 "type": "object",
244 "properties": {
245 "vdu_id": name_schema,
246 "additionalParams": object_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000247 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000248 },
tiernof62ac6a2020-04-29 13:46:13 +0000249 "required": ["vdu_id"],
250 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000251 "additionalProperties": False,
252 },
253 },
254 "additionalParamsForKdu": {
255 "type": "array",
256 "items": {
257 "type": "object",
258 "properties": {
259 "kdu_name": name_schema,
260 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000261 "kdu_model": name_schema,
262 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000263 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserf949db62021-05-28 10:59:05 +0200264 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000265 },
tierno54db2e42020-04-06 15:29:42 +0000266 "required": ["kdu_name"],
267 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000268 "additionalProperties": False,
269 },
270 },
tiernofd160572019-01-21 10:41:37 +0000271 },
tierno714954e2019-11-29 13:43:26 +0000272 "required": ["member-vnf-index"],
273 "minProperties": 2,
tiernofd160572019-01-21 10:41:37 +0000274 "additionalProperties": False
275 }
tiernofd160572019-01-21 10:41:37 +0000276}
277
tierno65acb4d2018-04-06 16:42:40 +0200278ns_instantiate = {
279 "title": "ns action instantiate input schema",
280 "$schema": "http://json-schema.org/draft-04/schema#",
281 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200282 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200283 "lcmOperationType": string_schema,
284 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100285 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200286 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000287 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200288 "nsdId": id_schema,
289 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000290 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100291 "placement-engine": string_schema,
292 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000293 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000294 "additionalParamsForVnf": additional_params_for_vnf,
tiernof62ac6a2020-04-29 13:46:13 +0000295 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000296 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100297 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000298 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200299 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200300 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200301 "vnf": {
302 "type": "array",
303 "minItems": 1,
304 "items": {
305 "type": "object",
306 "properties": {
307 "member-vnf-index": name_schema,
308 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200309 "vdu": {
310 "type": "array",
311 "minItems": 1,
312 "items": ns_instantiate_vdu,
313 },
314 "internal-vld": {
315 "type": "array",
316 "minItems": 1,
317 "items": ns_instantiate_internal_vld
318 }
tierno0da52252018-06-27 15:47:22 +0200319 },
tierno441dbbf2018-07-10 12:52:48 +0200320 "required": ["member-vnf-index"],
321 "minProperties": 2,
322 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200323 }
324 },
325 "vld": {
326 "type": "array",
327 "minItems": 1,
328 "items": {
329 "type": "object",
330 "properties": {
331 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000332 "vim-network-name": {"oneOf": [string_schema, object_schema]},
333 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100334 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000335 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200336 "ip-profile": object_schema,
kbsub21f03f52019-10-17 16:26:56 +0000337 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200338 "vnfd-connection-point-ref": {
339 "type": "array",
340 "minItems": 1,
341 "items": {
342 "type": "object",
343 "properties": {
344 "member-vnf-index-ref": name_schema,
345 "vnfd-connection-point-ref": name_schema,
346 "ip-address": ip_schema,
347 # "mac-address": mac_schema,
348 },
349 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
350 "minProperties": 3,
351 "additionalProperties": False
352 },
353 }
tierno0da52252018-06-27 15:47:22 +0200354 },
tierno441dbbf2018-07-10 12:52:48 +0200355 "required": ["name"],
356 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200357 }
358 },
359 },
tierno441dbbf2018-07-10 12:52:48 +0200360 "required": ["nsName", "nsdId", "vimAccountId"],
361 "additionalProperties": False
tierno65acb4d2018-04-06 16:42:40 +0200362}
tierno0da52252018-06-27 15:47:22 +0200363
tierno1c38f2f2020-03-24 11:51:39 +0000364ns_terminate = {
365 "title": "ns terminate input schema",
366 "$schema": "http://json-schema.org/draft-04/schema#",
367 "type": "object",
368 "properties": {
369 "lcmOperationType": string_schema,
370 "nsInstanceId": id_schema,
371 "autoremove": bool_schema,
372 "timeout_ns_terminate": integer1_schema,
373 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000374 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000375 },
376 "additionalProperties": False
377}
378
tierno65acb4d2018-04-06 16:42:40 +0200379ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200380 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200381 "$schema": "http://json-schema.org/draft-04/schema#",
382 "type": "object",
383 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200384 "lcmOperationType": string_schema,
385 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200386 "member_vnf_index": name_schema,
387 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200388 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000389 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000390 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200391 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000392 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200393 "primitive_params": {"type": "object"},
394 },
tiernof5298be2018-05-16 14:43:57 +0200395 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
tierno65acb4d2018-04-06 16:42:40 +0200396 "additionalProperties": False
397}
tiernof759d822018-06-11 18:54:54 +0200398ns_scale = { # TODO for the moment it is only VDU-scaling
399 "title": "ns scale input schema",
400 "$schema": "http://json-schema.org/draft-04/schema#",
401 "type": "object",
402 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200403 "lcmOperationType": string_schema,
404 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200405 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000406 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200407 "scaleVnfData": {
408 "type": "object",
409 "properties": {
410 "vnfInstanceId": name_schema,
411 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
412 "scaleByStepData": {
413 "type": "object",
414 "properties": {
415 "scaling-group-descriptor": name_schema,
416 "member-vnf-index": name_schema,
417 "scaling-policy": name_schema,
418 },
419 "required": ["scaling-group-descriptor", "member-vnf-index"],
420 "additionalProperties": False
421 },
422 },
423 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
424 "additionalProperties": False
425 },
426 "scaleTime": time_schema,
427 },
428 "required": ["scaleType", "scaleVnfData"],
429 "additionalProperties": False
430}
tierno65acb4d2018-04-06 16:42:40 +0200431
432
tierno0f98af52018-03-19 10:28:22 +0100433schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000434schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000435vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200436
tierno09c073e2018-04-26 13:36:48 +0200437vim_account_edit_schema = {
438 "title": "vim_account edit input schema",
439 "$schema": "http://json-schema.org/draft-04/schema#",
440 "type": "object",
441 "properties": {
442 "name": name_schema,
443 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200444 "vim": name_schema,
445 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200446 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200447 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200448 # "vim_url_admin": description_schema,
449 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200450 "vim_tenant_name": name_schema,
sousaedu28a6c4d2021-07-12 10:21:06 +0200451 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200452 "vim_password": passwd_schema,
tierno09c073e2018-04-26 13:36:48 +0200453 "config": {"type": "object"}
454 },
455 "additionalProperties": False
456}
tierno0f98af52018-03-19 10:28:22 +0100457
tierno09c073e2018-04-26 13:36:48 +0200458vim_account_new_schema = {
459 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100460 "$schema": "http://json-schema.org/draft-04/schema#",
461 "type": "object",
462 "properties": {
463 "schema_version": schema_version,
464 "schema_type": schema_type,
465 "name": name_schema,
466 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200467 "vim": name_schema,
468 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200469 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100470 "vim_url": description_schema,
471 # "vim_url_admin": description_schema,
472 # "vim_tenant": name_schema,
473 "vim_tenant_name": name_schema,
sousaedu28a6c4d2021-07-12 10:21:06 +0200474 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200475 "vim_password": passwd_schema,
tierno0f98af52018-03-19 10:28:22 +0100476 "config": {"type": "object"}
477 },
478 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
479 "additionalProperties": False
480}
tierno0f98af52018-03-19 10:28:22 +0100481
tierno85807722019-12-20 14:11:35 +0000482wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200483
tierno55ba2e62018-12-11 17:22:22 +0000484wim_account_edit_schema = {
485 "title": "wim_account edit input schema",
486 "$schema": "http://json-schema.org/draft-04/schema#",
487 "type": "object",
488 "properties": {
489 "name": name_schema,
490 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000491 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200492 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000493 "wim_url": description_schema,
sousaedud672fd42021-10-07 15:27:21 +0100494 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000495 "password": passwd_schema,
496 "config": {"type": "object"}
497 },
498 "additionalProperties": False
499}
500
501wim_account_new_schema = {
502 "title": "wim_account creation input schema",
503 "$schema": "http://json-schema.org/draft-04/schema#",
504 "type": "object",
505 "properties": {
506 "schema_version": schema_version,
507 "schema_type": schema_type,
508 "name": name_schema,
509 "description": description_schema,
510 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200511 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000512 "wim_url": description_schema,
sousaedud672fd42021-10-07 15:27:21 +0100513 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000514 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000515 "config": {
516 "type": "object",
517 "patternProperties": {
518 ".": {"not": {"type": "null"}}
519 }
520 }
tierno55ba2e62018-12-11 17:22:22 +0000521 },
522 "required": ["name", "wim_url", "wim_type"],
523 "additionalProperties": False
524}
tierno0f98af52018-03-19 10:28:22 +0100525
526sdn_properties = {
527 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000528 "type": {"type": "string"},
529 "url": {"type": "string"},
sousaedud672fd42021-10-07 15:27:21 +0100530 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000531 "password": passwd_schema,
532 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200533 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000534 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200535 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100536 "ip": ip_schema,
537 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100538 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100539}
540sdn_new_schema = {
541 "title": "sdn controller information schema",
542 "$schema": "http://json-schema.org/draft-04/schema#",
543 "type": "object",
544 "properties": sdn_properties,
tierno7adaeb02019-12-17 16:46:12 +0000545 "required": ["name", 'type'],
tierno0f98af52018-03-19 10:28:22 +0100546 "additionalProperties": False
547}
548sdn_edit_schema = {
549 "title": "sdn controller update information schema",
550 "$schema": "http://json-schema.org/draft-04/schema#",
551 "type": "object",
552 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200553 # "required": ["name", "port", 'ip', 'dpid', 'type'],
tierno0f98af52018-03-19 10:28:22 +0100554 "additionalProperties": False
555}
556sdn_port_mapping_schema = {
557 "$schema": "http://json-schema.org/draft-04/schema#",
558 "title": "sdn port mapping information schema",
559 "type": "array",
560 "items": {
561 "type": "object",
562 "properties": {
tiernofd160572019-01-21 10:41:37 +0000563 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100564 "ports": {
565 "type": "array",
566 "items": {
567 "type": "object",
568 "properties": {
tierno42fce592018-11-02 09:23:43 +0100569 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000570 "switch_port": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100571 "switch_mac": mac_schema
572 },
573 "required": ["pci"]
574 }
575 }
576 },
577 "required": ["compute_node", "ports"]
578 }
579}
580sdn_external_port_schema = {
581 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200582 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100583 "type": "object",
584 "properties": {
585 "port": {"type": "string", "minLength": 1, "maxLength": 60},
586 "vlan": vlan_schema,
587 "mac": mac_schema
588 },
589 "required": ["port"]
590}
591
delacruzramofe598fe2019-10-23 18:25:11 +0200592# K8s Clusters
593k8scluster_nets_schema = {
594 "title": "k8scluster nets input schema",
595 "$schema": "http://json-schema.org/draft-04/schema#",
596 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000597 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200598 "minProperties": 1,
599 "additionalProperties": False
600}
601k8scluster_new_schema = {
602 "title": "k8scluster creation input schema",
603 "$schema": "http://json-schema.org/draft-04/schema#",
604 "type": "object",
605 "properties": {
606 "schema_version": schema_version,
607 "schema_type": schema_type,
608 "name": name_schema,
609 "description": description_schema,
610 "credentials": object_schema,
611 "vim_account": id_schema,
612 "k8s_version": string_schema,
613 "nets": k8scluster_nets_schema,
614 "namespace": name_schema,
615 "cni": nameshort_list_schema,
616 },
617 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
618 "additionalProperties": False
619}
620k8scluster_edit_schema = {
621 "title": "vim_account edit input schema",
622 "$schema": "http://json-schema.org/draft-04/schema#",
623 "type": "object",
624 "properties": {
625 "name": name_schema,
626 "description": description_schema,
627 "credentials": object_schema,
628 "vim_account": id_schema,
629 "k8s_version": string_schema,
630 "nets": k8scluster_nets_schema,
631 "namespace": name_schema,
632 "cni": nameshort_list_schema,
633 },
634 "additionalProperties": False
635}
636
637# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000638k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200639k8srepo_properties = {
640 "name": name_schema,
641 "description": description_schema,
642 "type": k8srepo_types,
643 "url": description_schema,
644}
645k8srepo_new_schema = {
646 "title": "k8scluster creation input schema",
647 "$schema": "http://json-schema.org/draft-04/schema#",
648 "type": "object",
649 "properties": k8srepo_properties,
650 "required": ["name", "type", "url"],
651 "additionalProperties": False
652}
653k8srepo_edit_schema = {
654 "title": "vim_account edit input schema",
655 "$schema": "http://json-schema.org/draft-04/schema#",
656 "type": "object",
657 "properties": k8srepo_properties,
658 "additionalProperties": False
659}
660
Felipe Vicensb66b0412020-05-06 10:11:00 +0200661# OSM Repos
662osmrepo_types = {"enum": ["osm"]}
663osmrepo_properties = {
664 "name": name_schema,
665 "description": description_schema,
666 "type": osmrepo_types,
667 "url": description_schema
sousaedud672fd42021-10-07 15:27:21 +0100668 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200669 # "password": passwd_schema
670}
671osmrepo_new_schema = {
672 "title": "osm repo creation input schema",
673 "$schema": "http://json-schema.org/draft-04/schema#",
674 "type": "object",
675 "properties": osmrepo_properties,
676 "required": ["name", "type", "url"],
677 "additionalProperties": False
678}
679osmrepo_edit_schema = {
680 "title": "osm repo edit input schema",
681 "$schema": "http://json-schema.org/draft-04/schema#",
682 "type": "object",
683 "properties": osmrepo_properties,
684 "additionalProperties": False
685}
686
tiernocb83c942018-09-24 17:28:13 +0200687# PDUs
688pdu_interface = {
689 "type": "object",
690 "properties": {
tiernofd160572019-01-21 10:41:37 +0000691 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200692 "mgmt": bool_schema,
693 "type": {"enum": ["overlay", 'underlay']},
tierno36ec8602018-11-02 17:27:11 +0100694 "ip-address": ip_schema,
tiernocb83c942018-09-24 17:28:13 +0200695 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100696 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000697 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
698 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100699 # # provide this in case SDN assist must deal with this interface
700 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000701 # "switch-port": shortname_schema,
702 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100703 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200704 },
tierno36ec8602018-11-02 17:27:11 +0100705 "required": ["name", "mgmt", "ip-address"],
tiernocb83c942018-09-24 17:28:13 +0200706 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200707}
tiernocb83c942018-09-24 17:28:13 +0200708pdu_new_schema = {
709 "title": "pdu creation input schema",
710 "$schema": "http://json-schema.org/draft-04/schema#",
711 "type": "object",
712 "properties": {
tiernofd160572019-01-21 10:41:37 +0000713 "name": shortname_schema,
714 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200715 "description": description_schema,
716 "shared": bool_schema,
717 "vims": nameshort_list_schema,
718 "vim_accounts": nameshort_list_schema,
719 "interfaces": {
720 "type": "array",
tierno36ec8602018-11-02 17:27:11 +0100721 "items": pdu_interface,
tiernocb83c942018-09-24 17:28:13 +0200722 "minItems": 1
723 }
724 },
725 "required": ["name", "type", "interfaces"],
726 "additionalProperties": False
727}
tiernocb83c942018-09-24 17:28:13 +0200728pdu_edit_schema = {
729 "title": "pdu edit input schema",
730 "$schema": "http://json-schema.org/draft-04/schema#",
731 "type": "object",
732 "properties": {
tiernofd160572019-01-21 10:41:37 +0000733 "name": shortname_schema,
734 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200735 "description": description_schema,
736 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +0100737 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
738 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
739 "interfaces": {"oneOf": [
tiernocb83c942018-09-24 17:28:13 +0200740 array_edition_schema,
741 {
742 "type": "array",
tierno36ec8602018-11-02 17:27:11 +0100743 "items": pdu_interface,
tiernocb83c942018-09-24 17:28:13 +0200744 "minItems": 1
745 }
746 ]}
747 },
748 "additionalProperties": False,
749 "minProperties": 1
750}
751
delacruzramo271d2002019-12-02 21:00:37 +0100752# VNF PKG OPERATIONS
753vnfpkgop_new_schema = {
754 "title": "VNF PKG operation creation input schema",
755 "$schema": "http://json-schema.org/draft-04/schema#",
756 "type": "object",
757 "properties": {
758 "lcmOperationType": string_schema,
759 "vnfPkgId": id_schema,
760 "kdu_name": name_schema,
761 "primitive": name_schema,
762 "primitive_params": {"type": "object"},
763 },
764 "required": ["lcmOperationType", "vnfPkgId", "kdu_name", "primitive", "primitive_params"],
765 "additionalProperties": False
766}
767
tiernocb83c942018-09-24 17:28:13 +0200768# USERS
tiernocf042d32019-06-13 09:06:40 +0000769project_role_mappings = {
770 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100771 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +0000772 "type": "array",
773 "items": {
774 "type": "object",
775 "properties": {
776 "project": shortname_schema,
777 "role": shortname_schema
778 },
779 "required": ["project", "role"],
780 "additionalProperties": False
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100781 },
tiernocf042d32019-06-13 09:06:40 +0000782 "minItems": 1
783}
784project_role_mappings_optional = {
785 "title": "list of projects/roles or projects only",
786 "$schema": "http://json-schema.org/draft-04/schema#",
787 "type": "array",
788 "items": {
789 "type": "object",
790 "properties": {
791 "project": shortname_schema,
792 "role": shortname_schema
793 },
794 "required": ["project"],
795 "additionalProperties": False
796 },
797 "minItems": 1
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100798}
tiernocd54a4a2018-09-12 16:40:35 +0200799user_new_schema = {
800 "$schema": "http://json-schema.org/draft-04/schema#",
801 "title": "New user schema",
802 "type": "object",
803 "properties": {
sousaedud672fd42021-10-07 15:27:21 +0100804 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +0000805 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200806 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200807 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +0000808 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +0200809 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100810 "required": ["username", "password"],
tiernocd54a4a2018-09-12 16:40:35 +0200811 "additionalProperties": False
812}
813user_edit_schema = {
814 "$schema": "http://json-schema.org/draft-04/schema#",
815 "title": "User edit schema for administrators",
816 "type": "object",
817 "properties": {
818 "password": passwd_schema,
sousaedud672fd42021-10-07 15:27:21 +0100819 "username": string_schema, # To allow User Name modification
tiernocd54a4a2018-09-12 16:40:35 +0200820 "projects": {
garciadeblas84bdd552018-11-30 22:59:45 +0100821 "oneOf": [
tiernocb83c942018-09-24 17:28:13 +0200822 nameshort_list_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200823 array_edition_schema
824 ]
825 },
tiernocf042d32019-06-13 09:06:40 +0000826 "project_role_mappings": project_role_mappings,
827 "add_project_role_mappings": project_role_mappings,
828 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +0200829 },
830 "minProperties": 1,
831 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200832}
833
834# PROJECTS
tierno6b02b052020-06-02 10:07:41 +0000835topics_with_quota = ["vnfds", "nsds", "slice_templates", "pduds", "ns_instances", "slice_instances", "vim_accounts",
preethika.p329b8182020-04-22 12:25:39 +0530836 "wim_accounts", "sdn_controllers", "k8sclusters", "k8srepos", "osmrepos", "ns_subscriptions"]
tiernocd54a4a2018-09-12 16:40:35 +0200837project_new_schema = {
838 "$schema": "http://json-schema.org/draft-04/schema#",
839 "title": "New project schema for administrators",
840 "type": "object",
841 "properties": {
tiernofd160572019-01-21 10:41:37 +0000842 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200843 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +0000844 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +0200845 "quotas": {
846 "type": "object",
847 "properties": {topic: integer0_schema for topic in topics_with_quota},
848 "additionalProperties": False
849 },
tiernocd54a4a2018-09-12 16:40:35 +0200850 },
851 "required": ["name"],
852 "additionalProperties": False
853}
854project_edit_schema = {
855 "$schema": "http://json-schema.org/draft-04/schema#",
856 "title": "Project edit schema for administrators",
857 "type": "object",
858 "properties": {
859 "admin": bool_schema,
delacruzramoc061f562019-04-05 11:00:02 +0200860 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +0200861 "quotas": {
862 "type": "object",
863 "properties": {topic: {"oneOf": [integer0_schema, null_schema]} for topic in topics_with_quota},
864 "additionalProperties": False
865 },
tiernocd54a4a2018-09-12 16:40:35 +0200866 },
867 "additionalProperties": False,
868 "minProperties": 1
869}
870
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100871# ROLES
872roles_new_schema = {
873 "$schema": "http://json-schema.org/draft-04/schema#",
874 "title": "New role schema for administrators",
875 "type": "object",
876 "properties": {
877 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +0000878 "permissions": {
879 "type": "object",
880 "patternProperties": {
881 ".": bool_schema,
882 },
883 # "minProperties": 1,
884 }
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100885 },
tierno1f029d82019-06-13 22:37:04 +0000886 "required": ["name"],
887 "additionalProperties": False
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100888}
889roles_edit_schema = {
890 "$schema": "http://json-schema.org/draft-04/schema#",
891 "title": "Roles edit schema for administrators",
892 "type": "object",
893 "properties": {
tierno1f029d82019-06-13 22:37:04 +0000894 "name": shortname_schema,
895 "permissions": {
896 "type": "object",
897 "patternProperties": {
898 ".": {
899 "oneOf": [bool_schema, null_schema]
900 }
901 },
902 # "minProperties": 1,
903 }
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100904 },
tierno1f029d82019-06-13 22:37:04 +0000905 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100906 "minProperties": 1
907}
908
tiernocd54a4a2018-09-12 16:40:35 +0200909# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +0100910
911nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200912 "users": user_new_schema,
913 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +0200914 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +0200915 "sdns": sdn_new_schema,
916 "ns_instantiate": ns_instantiate,
917 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +0200918 "ns_scale": ns_scale,
919 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +0100920}
921
922nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200923 "users": user_edit_schema,
924 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +0200925 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +0200926 "sdns": sdn_edit_schema,
927 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +0100928}
929
Felipe Vicens07f31722018-10-29 15:16:44 +0100930# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +0000931nsi_subnet_instantiate = deepcopy(ns_instantiate)
932nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
933nsi_subnet_instantiate["properties"]["id"] = name_schema
934del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +0100935
936nsi_vld_instantiate = {
937 "title": "netslice vld instantiation params input schema",
938 "$schema": "http://json-schema.org/draft-04/schema#",
939 "type": "object",
940 "properties": {
941 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000942 "vim-network-name": {"oneOf": [string_schema, object_schema]},
943 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +0100944 "ip-profile": object_schema,
945 },
delacruzramoc061f562019-04-05 11:00:02 +0200946 "required": ["name"],
garciadeblasdaf8cc52018-11-30 14:17:20 +0100947 "additionalProperties": False
948}
949
Felipe Vicens07f31722018-10-29 15:16:44 +0100950nsi_instantiate = {
951 "title": "netslice action instantiate input schema",
952 "$schema": "http://json-schema.org/draft-04/schema#",
953 "type": "object",
954 "properties": {
955 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +0200956 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100957 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000958 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +0000959 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100960 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +0000961 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +0200962 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +0100963 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +0000964 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +0100965 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +0100966 "type": "array",
967 "minItems": 1,
tierno032916c2019-03-22 13:27:12 +0000968 "items": nsi_subnet_instantiate
garciadeblasdaf8cc52018-11-30 14:17:20 +0100969 },
970 "netslice-vld": {
971 "type": "array",
972 "minItems": 1,
973 "items": nsi_vld_instantiate
Felipe Vicens07f31722018-10-29 15:16:44 +0100974 },
975 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +0100976 "required": ["nsiName", "nstId", "vimAccountId"],
Felipe Vicens07f31722018-10-29 15:16:44 +0100977 "additionalProperties": False
978}
979
980nsi_action = {
981
982}
983
984nsi_terminate = {
delacruzramoc061f562019-04-05 11:00:02 +0200985
Felipe Vicens07f31722018-10-29 15:16:44 +0100986}
987
preethika.p329b8182020-04-22 12:25:39 +0530988nsinstancesubscriptionfilter_schema = {
989 "title": "instance identifier schema",
990 "$schema": "http://json-schema.org/draft-07/schema#",
991 "type": "object",
992 "properties": {
993 "nsdIds": {"type": "array"},
994 "vnfdIds": {"type": "array"},
995 "pnfdIds": {"type": "array"},
996 "nsInstanceIds": {"type": "array"},
997 "nsInstanceNames": {"type": "array"},
998 },
999}
1000
1001nslcmsub_schema = {
1002 "title": "nslcmsubscription input schema",
1003 "$schema": "http://json-schema.org/draft-07/schema#",
1004 "type": "object",
1005 "properties": {
1006 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1007 "notificationTypes": {
1008 "type": "array",
1009 "items": {
1010 "enum": ['NsLcmOperationOccurrenceNotification', 'NsChangeNotification',
1011 'NsIdentifierCreationNotification', 'NsIdentifierDeletionNotification']
1012 }
1013 },
1014 "operationTypes": {
1015 "type": "array",
1016 "items": {
1017 "enum": ['INSTANTIATE', 'SCALE', 'TERMINATE', 'UPDATE', 'HEAL']
1018 }
1019 },
1020 "operationStates": {
1021 "type": "array",
1022 "items": {
1023 "enum": ['PROCESSING', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED',
1024 'FAILED_TEMP', 'ROLLING_BACK', 'ROLLED_BACK']
1025 }
1026 },
1027 "nsComponentTypes": {
1028 "type": "array",
1029 "items": {
1030 "enum": ['VNF', 'NS', 'PNF']
1031 }
1032 },
1033 "lcmOpNameImpactingNsComponent": {
1034 "type": "array",
1035 "items": {
1036 "enum": ['VNF_INSTANTIATE', 'VNF_SCALE', 'VNF_SCALE_TO_LEVEL', 'VNF_CHANGE_FLAVOUR',
1037 'VNF_TERMINATE', 'VNF_HEAL', 'VNF_OPERATE', 'VNF_CHANGE_EXT_CONN', 'VNF_MODIFY_INFO',
1038 'NS_INSTANTIATE', 'NS_SCALE', 'NS_UPDATE', 'NS_TERMINATE', 'NS_HEAL']
1039 }
1040 },
1041 "lcmOpOccStatusImpactingNsComponent": {
1042 "type": "array",
1043 "items": {
1044 "enum": ['START', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED', 'ROLLED_BACK']
1045 }
1046 },
1047 },
1048 "allOf": [
1049 {
1050 "if": {
1051 "properties": {
1052 "notificationTypes": {
1053 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1054 }
1055 },
1056 },
1057 "then": {
1058 "anyOf": [
1059 {"required": ["operationTypes"]},
1060 {"required": ["operationStates"]},
1061 ]
1062 }
1063 },
1064 {
1065 "if": {
1066 "properties": {
1067 "notificationTypes": {
1068 "contains": {"const": "NsChangeNotification"}
1069 }
1070 },
1071 },
1072 "then": {
1073 "anyOf": [
1074 {"required": ["nsComponentTypes"]},
1075 {"required": ["lcmOpNameImpactingNsComponent"]},
1076 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1077 ]
1078 }
1079 }
1080 ]
1081}
1082
1083authentication_schema = {
1084 "title": "authentication schema for subscription",
1085 "$schema": "http://json-schema.org/draft-07/schema#",
1086 "type": "object",
1087 "properties": {
1088 "authType": {"enum": ["basic"]},
1089 "paramsBasic": {
1090 "type": "object",
1091 "properties": {
sousaedud672fd42021-10-07 15:27:21 +01001092 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301093 "password": passwd_schema,
1094 },
1095 },
1096 },
1097}
1098
1099subscription = {
1100 "title": "subscription input schema",
1101 "$schema": "http://json-schema.org/draft-07/schema#",
1102 "type": "object",
1103 "properties": {
1104 "filter": nslcmsub_schema,
1105 "CallbackUri": description_schema,
1106 "authentication": authentication_schema
1107 },
1108 "required": ["CallbackUri"],
1109}
1110
tierno0f98af52018-03-19 10:28:22 +01001111
1112class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001113 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1114 self.http_code = http_code
1115 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001116
1117
tiernob24258a2018-10-04 18:39:49 +02001118def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001119 """
tiernocd54a4a2018-09-12 16:40:35 +02001120 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001121 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001122 :param schema_to_use: jsonschema to test
1123 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001124 """
1125 try:
tierno0f98af52018-03-19 10:28:22 +01001126 if schema_to_use:
1127 js_v(indata, schema_to_use)
1128 return None
1129 except js_e.ValidationError as e:
1130 if e.path:
tierno0da52252018-06-27 15:47:22 +02001131 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001132 else:
1133 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001134 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001135 except js_e.SchemaError:
1136 raise ValidationError("Bad json schema {}".format(schema_to_use), http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
delacruzramoc061f562019-04-05 11:00:02 +02001137
1138
1139def is_valid_uuid(x):
1140 """
1141 Test for a valid UUID
1142 :param x: string to test
1143 :return: True if x is a valid uuid, False otherwise
1144 """
1145 try:
1146 if UUID(x):
1147 return True
tiernobdebce92019-07-01 15:36:49 +00001148 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001149 return False