3d675f6aff3d9bf7e6914e0192f448093465df65
[osm/NBI.git] / osm_nbi / validation.py
1 # -*- coding: utf-8 -*-
2
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
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
16 from jsonschema import validate as js_v, exceptions as js_e
17 from http import HTTPStatus
18 from copy import deepcopy
19 from uuid import UUID # To test for valid UUID
20
21 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
22 __version__ = "0.1"
23 version_date = "Mar 2018"
24
25 """
26 Validator of input data using JSON schemas for those items that not contains an OSM yang information model
27 """
28
29 # Basis schemas
30 patern_name = "^[ -~]+$"
31 shortname_schema = {
32 "type": "string",
33 "minLength": 1,
34 "maxLength": 60,
35 "pattern": "^[^,;()\\.\\$'\"]+$",
36 }
37 passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
38 name_schema = {
39 "type": "string",
40 "minLength": 1,
41 "maxLength": 255,
42 "pattern": "^[^,;()'\"]+$",
43 }
44 string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
45 xml_text_schema = {
46 "type": "string",
47 "minLength": 1,
48 "maxLength": 1000,
49 "pattern": "^[^']+$",
50 }
51 description_schema = {
52 "type": ["string", "null"],
53 "maxLength": 255,
54 "pattern": "^[^'\"]+$",
55 }
56 long_description_schema = {
57 "type": ["string", "null"],
58 "maxLength": 3000,
59 "pattern": "^[^'\"]+$",
60 }
61 id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
62 bool_schema = {"type": "boolean"}
63 null_schema = {"type": "null"}
64 # "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}$"
65 id_schema = {
66 "type": "string",
67 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
68 }
69 time_schema = {
70 "type": "string",
71 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}",
72 }
73 pci_schema = {
74 "type": "string",
75 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$",
76 }
77 # allows [] for wildcards. For that reason huge length limit is set
78 pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
79 http_schema = {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
80 bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
81 memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
82 integer0_schema = {"type": "integer", "minimum": 0}
83 integer1_schema = {"type": "integer", "minimum": 1}
84 path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
85 vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
86 vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
87 mac_schema = {
88 "type": "string",
89 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$",
90 } # must be unicast: LSB bit of MSB byte ==0
91 dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
92 # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
93 ip_schema = {
94 "type": "string",
95 "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]?)$",
96 }
97 ipv6_schema = {
98 "type": "string",
99 "pattern": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))",
100 }
101 ip_prefix_schema = {
102 "type": "string",
103 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
104 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
105 }
106 port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
107 object_schema = {"type": "object"}
108 schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
109 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
110 log_level_schema = {
111 "type": "string",
112 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
113 }
114 checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
115 size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
116 array_edition_schema = {
117 "type": "object",
118 "patternProperties": {"^\\$": {}},
119 "additionalProperties": False,
120 "minProperties": 1,
121 }
122 nameshort_list_schema = {
123 "type": "array",
124 "minItems": 1,
125 "items": shortname_schema,
126 }
127
128 description_list_schema = {
129 "type": "array",
130 "minItems": 1,
131 "items": description_schema,
132 }
133
134 ns_instantiate_vdu = {
135 "title": "ns action instantiate input schema for vdu",
136 "$schema": "http://json-schema.org/draft-04/schema#",
137 "type": "object",
138 "properties": {
139 "id": name_schema,
140 "volume": {
141 "type": "array",
142 "minItems": 1,
143 "items": {
144 "type": "object",
145 "properties": {
146 "name": name_schema,
147 "vim-volume-id": name_schema,
148 },
149 "required": ["name", "vim-volume-id"],
150 "additionalProperties": False,
151 },
152 },
153 "interface": {
154 "type": "array",
155 "minItems": 1,
156 "items": {
157 "type": "object",
158 "properties": {
159 "name": name_schema,
160 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
161 "mac-address": mac_schema,
162 "floating-ip-required": bool_schema,
163 },
164 "required": ["name"],
165 "additionalProperties": False,
166 },
167 },
168 },
169 "required": ["id"],
170 "additionalProperties": False,
171 }
172
173 ip_profile_dns_schema = {
174 "type": "array",
175 "minItems": 1,
176 "items": {
177 "type": "object",
178 "properties": {
179 "address": {"oneOf": [ip_schema, ipv6_schema]},
180 },
181 "required": ["address"],
182 "additionalProperties": False,
183 },
184 }
185
186 ip_profile_dhcp_schema = {
187 "type": "object",
188 "properties": {
189 "enabled": {"type": "boolean"},
190 "count": integer1_schema,
191 "start-address": ip_schema,
192 },
193 "additionalProperties": False,
194 }
195
196 ip_profile_schema = {
197 "title": "ip profile validation schema",
198 "$schema": "http://json-schema.org/draft-04/schema#",
199 "type": "object",
200 "properties": {
201 "ip-version": {"enum": ["ipv4", "ipv6"]},
202 "subnet-address": ip_prefix_schema,
203 "gateway-address": ip_schema,
204 "dns-server": ip_profile_dns_schema,
205 "dhcp-params": ip_profile_dhcp_schema,
206 },
207 }
208
209 ip_profile_update_schema = {
210 "title": "ip profile validation schema",
211 "$schema": "http://json-schema.org/draft-04/schema#",
212 "type": "object",
213 "properties": {
214 "ip-version": {"enum": ["ipv4", "ipv6"]},
215 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
216 "gateway-address": {"oneOf": [null_schema, ip_schema]},
217 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
218 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
219 },
220 "additionalProperties": False,
221 }
222
223 provider_network_schema = {
224 "title": "provider network validation schema",
225 "$schema": "http://json-schema.org/draft-04/schema#",
226 "type": "object",
227 "properties": {
228 "physical-network": name_schema,
229 "segmentation-id": name_schema,
230 "sdn-ports": { # external ports to append to the SDN-assist network
231 "type": "array",
232 "items": {
233 "type": "object",
234 "properties": {
235 "switch_id": shortname_schema,
236 "switch_port": shortname_schema,
237 "mac_address": mac_schema,
238 "vlan": vlan_schema,
239 },
240 "additionalProperties": True,
241 },
242 },
243 "network-type": shortname_schema,
244 },
245 "additionalProperties": True,
246 }
247
248 ns_instantiate_internal_vld = {
249 "title": "ns action instantiate input schema for vld",
250 "$schema": "http://json-schema.org/draft-04/schema#",
251 "type": "object",
252 "properties": {
253 "name": name_schema,
254 "vim-network-name": name_schema,
255 "vim-network-id": name_schema,
256 "ip-profile": ip_profile_update_schema,
257 "provider-network": provider_network_schema,
258 "internal-connection-point": {
259 "type": "array",
260 "minItems": 1,
261 "items": {
262 "type": "object",
263 "properties": {
264 "id-ref": name_schema,
265 "ip-address": ip_schema,
266 # "mac-address": mac_schema,
267 },
268 "required": ["id-ref"],
269 "minProperties": 2,
270 "additionalProperties": False,
271 },
272 },
273 },
274 "required": ["name"],
275 "minProperties": 2,
276 "additionalProperties": False,
277 }
278
279 additional_params_for_vnf = {
280 "type": "array",
281 "items": {
282 "type": "object",
283 "properties": {
284 "member-vnf-index": name_schema,
285 "additionalParams": object_schema,
286 "k8s-namespace": name_schema,
287 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
288 "additionalParamsForVdu": {
289 "type": "array",
290 "items": {
291 "type": "object",
292 "properties": {
293 "vdu_id": name_schema,
294 "additionalParams": object_schema,
295 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
296 },
297 "required": ["vdu_id"],
298 "minProperties": 2,
299 "additionalProperties": False,
300 },
301 },
302 "additionalParamsForKdu": {
303 "type": "array",
304 "items": {
305 "type": "object",
306 "properties": {
307 "kdu_name": name_schema,
308 "additionalParams": object_schema,
309 "kdu_model": name_schema,
310 "k8s-namespace": name_schema,
311 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
312 "kdu-deployment-name": name_schema,
313 },
314 "required": ["kdu_name"],
315 "minProperties": 2,
316 "additionalProperties": False,
317 },
318 },
319 "affinity-or-anti-affinity-group": {
320 "type": "array",
321 "items": {
322 "type": "object",
323 "properties": {
324 "id": name_schema,
325 "vim-affinity-group-id": name_schema,
326 },
327 "required": ["id"],
328 "minProperties": 2,
329 "additionalProperties": False,
330 },
331 },
332 },
333 "required": ["member-vnf-index"],
334 "minProperties": 2,
335 "additionalProperties": False,
336 },
337 }
338
339 ns_instantiate = {
340 "title": "ns action instantiate input schema",
341 "$schema": "http://json-schema.org/draft-04/schema#",
342 "type": "object",
343 "properties": {
344 "lcmOperationType": string_schema,
345 "nsInstanceId": id_schema,
346 "netsliceInstanceId": id_schema,
347 "nsName": name_schema,
348 "nsDescription": {"oneOf": [description_schema, null_schema]},
349 "nsdId": id_schema,
350 "vimAccountId": {"oneOf": [id_schema, null_schema]},
351 "paasAccountId": {"oneOf": [id_schema, null_schema]},
352 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
353 "placement-engine": string_schema,
354 "placement-constraints": object_schema,
355 "additionalParamsForNs": object_schema,
356 "additionalParamsForVnf": additional_params_for_vnf,
357 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
358 "k8s-namespace": name_schema,
359 "ssh_keys": {"type": "array", "items": {"type": "string"}},
360 "timeout_ns_deploy": integer1_schema,
361 "nsr_id": id_schema,
362 "vduImage": name_schema,
363 "vnf": {
364 "type": "array",
365 "minItems": 1,
366 "items": {
367 "type": "object",
368 "properties": {
369 "member-vnf-index": name_schema,
370 "vimAccountId": {"oneOf": [id_schema, null_schema]},
371 "paasAccountId": {"oneOf": [id_schema, null_schema]},
372 "vdu": {
373 "type": "array",
374 "minItems": 1,
375 "items": ns_instantiate_vdu,
376 },
377 "internal-vld": {
378 "type": "array",
379 "minItems": 1,
380 "items": ns_instantiate_internal_vld,
381 },
382 },
383 "required": ["member-vnf-index"],
384 "minProperties": 2,
385 "additionalProperties": False,
386 },
387 },
388 "vld": {
389 "type": "array",
390 "minItems": 1,
391 "items": {
392 "type": "object",
393 "properties": {
394 "name": string_schema,
395 "vim-network-name": {"oneOf": [string_schema, object_schema]},
396 "vim-network-id": {"oneOf": [string_schema, object_schema]},
397 "ns-net": object_schema,
398 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
399 "ip-profile": object_schema,
400 "provider-network": provider_network_schema,
401 "vnfd-connection-point-ref": {
402 "type": "array",
403 "minItems": 1,
404 "items": {
405 "type": "object",
406 "properties": {
407 "member-vnf-index-ref": name_schema,
408 "vnfd-connection-point-ref": name_schema,
409 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
410 # "mac-address": mac_schema,
411 },
412 "required": [
413 "member-vnf-index-ref",
414 "vnfd-connection-point-ref",
415 ],
416 "minProperties": 3,
417 "additionalProperties": False,
418 },
419 },
420 },
421 "required": ["name"],
422 "additionalProperties": False,
423 },
424 },
425 },
426 "required": ["nsName", "nsdId"],
427 "additionalProperties": False,
428 }
429
430 ns_terminate = {
431 "title": "ns terminate input schema",
432 "$schema": "http://json-schema.org/draft-04/schema#",
433 "type": "object",
434 "properties": {
435 "lcmOperationType": string_schema,
436 "nsInstanceId": id_schema,
437 "autoremove": bool_schema,
438 "timeout_ns_terminate": integer1_schema,
439 "skip_terminate_primitives": bool_schema,
440 "netsliceInstanceId": id_schema,
441 },
442 "additionalProperties": False,
443 }
444
445 ns_update = {
446 "title": "ns update input schema",
447 "$schema": "http://json-schema.org/draft-04/schema#",
448 "type": "object",
449 "properties": {
450 "lcmOperationType": string_schema,
451 "nsInstanceId": id_schema,
452 "timeout_ns_update": integer1_schema,
453 "updateType": {
454 "enum": [
455 "CHANGE_VNFPKG",
456 "REMOVE_VNF",
457 "MODIFY_VNF_INFORMATION",
458 "OPERATE_VNF",
459 ]
460 },
461 "modifyVnfInfoData": {
462 "type": "object",
463 "properties": {
464 "vnfInstanceId": id_schema,
465 "vnfdId": id_schema,
466 },
467 "required": ["vnfInstanceId", "vnfdId"],
468 },
469 "removeVnfInstanceId": id_schema,
470 "changeVnfPackageData": {
471 "type": "object",
472 "properties": {
473 "vnfInstanceId": id_schema,
474 "vnfdId": id_schema,
475 },
476 "required": ["vnfInstanceId", "vnfdId"],
477 },
478 "operateVnfData": {
479 "type": "object",
480 "properties": {
481 "vnfInstanceId": id_schema,
482 "changeStateTo": name_schema,
483 "additionalParam": {
484 "type": "object",
485 "properties": {
486 "run-day1": bool_schema,
487 "vdu_id": name_schema,
488 "count-index": integer0_schema,
489 },
490 "required": ["vdu_id", "count-index"],
491 "additionalProperties": False,
492 },
493 },
494 "required": ["vnfInstanceId", "changeStateTo"],
495 },
496 },
497 "required": ["updateType"],
498 "additionalProperties": False,
499 }
500
501 ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
502 "title": "ns action input schema",
503 "$schema": "http://json-schema.org/draft-04/schema#",
504 "type": "object",
505 "properties": {
506 "lcmOperationType": string_schema,
507 "nsInstanceId": id_schema,
508 "member_vnf_index": name_schema,
509 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
510 "vdu_id": name_schema,
511 "vdu_count_index": integer0_schema,
512 "kdu_name": name_schema,
513 "primitive": name_schema,
514 "timeout_ns_action": integer1_schema,
515 "primitive_params": {"type": "object"},
516 },
517 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
518 "additionalProperties": False,
519 }
520
521 ns_scale = { # TODO for the moment it is only VDU-scaling
522 "title": "ns scale input schema",
523 "$schema": "http://json-schema.org/draft-04/schema#",
524 "type": "object",
525 "properties": {
526 "lcmOperationType": string_schema,
527 "nsInstanceId": id_schema,
528 "scaleType": {"enum": ["SCALE_VNF"]},
529 "timeout_ns_scale": integer1_schema,
530 "scaleVnfData": {
531 "type": "object",
532 "properties": {
533 "vnfInstanceId": name_schema,
534 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
535 "scaleByStepData": {
536 "type": "object",
537 "properties": {
538 "scaling-group-descriptor": name_schema,
539 "member-vnf-index": name_schema,
540 "scaling-policy": name_schema,
541 },
542 "required": ["scaling-group-descriptor", "member-vnf-index"],
543 "additionalProperties": False,
544 },
545 },
546 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
547 "additionalProperties": False,
548 },
549 "scaleTime": time_schema,
550 },
551 "required": ["scaleType", "scaleVnfData"],
552 "additionalProperties": False,
553 }
554
555 ns_migrate = {
556 "title": "ns migrate input schema",
557 "$schema": "http://json-schema.org/draft-04/schema#",
558 "type": "object",
559 "properties": {
560 "lcmOperationType": string_schema,
561 "nsInstanceId": id_schema,
562 "vnfInstanceId": id_schema,
563 "migrateToHost": string_schema,
564 "vdu": {
565 "type": "object",
566 "properties": {
567 "vduId": name_schema,
568 "vduCountIndex": integer0_schema,
569 },
570 "required": ["vduId"],
571 "additionalProperties": False,
572 },
573 },
574 "required": ["vnfInstanceId"],
575 "additionalProperties": False,
576 }
577
578 ns_heal = {
579 "title": "ns heal input schema",
580 "$schema": "http://json-schema.org/draft-04/schema#",
581 "type": "object",
582 "properties": {
583 "lcmOperationType": string_schema,
584 "nsInstanceId": id_schema,
585 "timeout_ns_heal": integer1_schema,
586 "healVnfData": {
587 "type": "array",
588 "items": {
589 "type": "object",
590 "properties": {
591 "vnfInstanceId": id_schema,
592 "cause": description_schema,
593 "additionalParams": {
594 "type": "object",
595 "properties": {
596 "run-day1": bool_schema,
597 "vdu": {
598 "type": "array",
599 "items": {
600 "type": "object",
601 "properties": {
602 "run-day1": bool_schema,
603 "vdu-id": name_schema,
604 "count-index": integer0_schema,
605 },
606 "required": ["vdu-id"],
607 "additionalProperties": False,
608 },
609 },
610 },
611 "additionalProperties": False,
612 },
613 },
614 "required": ["vnfInstanceId"],
615 "additionalProperties": False,
616 },
617 },
618 },
619 "required": ["healVnfData"],
620 "additionalProperties": False,
621 }
622
623 ns_verticalscale = {
624 "title": "vertial scale input schema",
625 "$schema": "http://json-schema.org/draft-04/schema#",
626 "type": "object",
627 "properties": {
628 "lcmOperationType": string_schema,
629 "verticalScale": string_schema,
630 "nsInstanceId": id_schema,
631 "changeVnfFlavorData": {
632 "type": "object",
633 "properties": {
634 "vnfInstanceId": id_schema,
635 "additionalParams": {
636 "type": "object",
637 "properties": {
638 "vduid": string_schema,
639 "vduCountIndex": integer0_schema,
640 "virtualMemory": integer1_schema,
641 "sizeOfStorage": integer0_schema,
642 "numVirtualCpu": integer1_schema,
643 },
644 },
645 },
646 "required": ["vnfInstanceId", "additionalParams"],
647 "additionalProperties": False,
648 },
649 },
650 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
651 "additionalProperties": False,
652 }
653
654 schema_version = {"type": "string", "enum": ["1.0"]}
655 schema_type = {"type": "string"}
656 vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
657
658 vim_account_edit_schema = {
659 "title": "vim_account edit input schema",
660 "$schema": "http://json-schema.org/draft-04/schema#",
661 "type": "object",
662 "properties": {
663 "name": name_schema,
664 "description": description_schema,
665 "vim": name_schema,
666 "datacenter": name_schema,
667 "vim_type": vim_type,
668 "vim_url": description_schema,
669 # "vim_url_admin": description_schema,
670 # "vim_tenant": name_schema,
671 "vim_tenant_name": name_schema,
672 "vim_user": string_schema,
673 "vim_password": passwd_schema,
674 "vca": id_schema,
675 "config": {"type": "object"},
676 "prometheus-config": {"type": "object"},
677 },
678 "additionalProperties": False,
679 }
680
681 vim_account_new_schema = {
682 "title": "vim_account creation input schema",
683 "$schema": "http://json-schema.org/draft-04/schema#",
684 "type": "object",
685 "properties": {
686 "schema_version": schema_version,
687 "schema_type": schema_type,
688 "name": name_schema,
689 "description": description_schema,
690 "vim": name_schema,
691 "datacenter": name_schema,
692 "vim_type": vim_type,
693 "vim_url": description_schema,
694 # "vim_url_admin": description_schema,
695 # "vim_tenant": name_schema,
696 "vim_tenant_name": name_schema,
697 "vim_user": string_schema,
698 "vim_password": passwd_schema,
699 "vca": id_schema,
700 "config": {"type": "object"},
701 "prometheus-config": {"type": "object"},
702 },
703 "required": [
704 "name",
705 "vim_url",
706 "vim_type",
707 "vim_user",
708 "vim_password",
709 "vim_tenant_name",
710 ],
711 "additionalProperties": False,
712 }
713
714 wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
715
716 wim_account_edit_schema = {
717 "title": "wim_account edit input schema",
718 "$schema": "http://json-schema.org/draft-04/schema#",
719 "type": "object",
720 "properties": {
721 "name": name_schema,
722 "description": description_schema,
723 "wim": name_schema,
724 "wim_type": wim_type,
725 "wim_url": description_schema,
726 "user": string_schema,
727 "password": passwd_schema,
728 "config": {"type": "object"},
729 },
730 "additionalProperties": False,
731 }
732
733 wim_account_new_schema = {
734 "title": "wim_account creation input schema",
735 "$schema": "http://json-schema.org/draft-04/schema#",
736 "type": "object",
737 "properties": {
738 "schema_version": schema_version,
739 "schema_type": schema_type,
740 "name": name_schema,
741 "description": description_schema,
742 "wim": name_schema,
743 "wim_type": wim_type,
744 "wim_url": description_schema,
745 "user": string_schema,
746 "password": passwd_schema,
747 "config": {
748 "type": "object",
749 "patternProperties": {".": {"not": {"type": "null"}}},
750 },
751 },
752 "required": ["name", "wim_url", "wim_type"],
753 "additionalProperties": False,
754 }
755
756 sdn_properties = {
757 "name": name_schema,
758 "type": {"type": "string"},
759 "url": {"type": "string"},
760 "user": string_schema,
761 "password": passwd_schema,
762 "config": {"type": "object"},
763 "description": description_schema,
764 # The folowing are deprecated. Maintanied for backward compatibility
765 "dpid": dpid_Schema,
766 "ip": ip_schema,
767 "port": port_schema,
768 "version": {"type": "string", "minLength": 1, "maxLength": 12},
769 }
770 sdn_new_schema = {
771 "title": "sdn controller information schema",
772 "$schema": "http://json-schema.org/draft-04/schema#",
773 "type": "object",
774 "properties": sdn_properties,
775 "required": ["name", "type"],
776 "additionalProperties": False,
777 }
778 sdn_edit_schema = {
779 "title": "sdn controller update information schema",
780 "$schema": "http://json-schema.org/draft-04/schema#",
781 "type": "object",
782 "properties": sdn_properties,
783 # "required": ["name", "port", 'ip', 'dpid', 'type'],
784 "additionalProperties": False,
785 }
786 sdn_port_mapping_schema = {
787 "$schema": "http://json-schema.org/draft-04/schema#",
788 "title": "sdn port mapping information schema",
789 "type": "array",
790 "items": {
791 "type": "object",
792 "properties": {
793 "compute_node": shortname_schema,
794 "ports": {
795 "type": "array",
796 "items": {
797 "type": "object",
798 "properties": {
799 "pci": pci_extended_schema,
800 "switch_port": shortname_schema,
801 "switch_mac": mac_schema,
802 },
803 "required": ["pci"],
804 },
805 },
806 },
807 "required": ["compute_node", "ports"],
808 },
809 }
810 sdn_external_port_schema = {
811 "$schema": "http://json-schema.org/draft-04/schema#",
812 "title": "External port information",
813 "type": "object",
814 "properties": {
815 "port": {"type": "string", "minLength": 1, "maxLength": 60},
816 "vlan": vlan_schema,
817 "mac": mac_schema,
818 },
819 "required": ["port"],
820 }
821
822 # K8s Clusters
823 k8scluster_deploy_method_schema = {
824 "$schema": "http://json-schema.org/draft-04/schema#",
825 "title": "Deployment methods for K8s cluster",
826 "type": "object",
827 "properties": {
828 "helm-chart": {"type": "boolean"},
829 "juju-bundle": {"type": "boolean"},
830 "helm-chart-v3": {"type": "boolean"},
831 },
832 "additionalProperties": False,
833 "minProperties": 3,
834 }
835 k8scluster_nets_schema = {
836 "title": "k8scluster nets input schema",
837 "$schema": "http://json-schema.org/draft-04/schema#",
838 "type": "object",
839 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
840 "minProperties": 1,
841 "additionalProperties": False,
842 }
843 k8scluster_new_schema = {
844 "title": "k8scluster creation input schema",
845 "$schema": "http://json-schema.org/draft-04/schema#",
846 "type": "object",
847 "properties": {
848 "schema_version": schema_version,
849 "schema_type": schema_type,
850 "name": name_schema,
851 "description": description_schema,
852 "credentials": object_schema,
853 "vim_account": id_schema,
854 "vca_id": id_schema,
855 "k8s_version": string_schema,
856 "nets": k8scluster_nets_schema,
857 "deployment_methods": k8scluster_deploy_method_schema,
858 "namespace": name_schema,
859 "cni": nameshort_list_schema,
860 },
861 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
862 "additionalProperties": False,
863 }
864 k8scluster_edit_schema = {
865 "title": "vim_account edit input schema",
866 "$schema": "http://json-schema.org/draft-04/schema#",
867 "type": "object",
868 "properties": {
869 "name": name_schema,
870 "description": description_schema,
871 "credentials": object_schema,
872 "vim_account": id_schema,
873 "vca_id": id_schema,
874 "k8s_version": string_schema,
875 "nets": k8scluster_nets_schema,
876 "namespace": name_schema,
877 "cni": nameshort_list_schema,
878 },
879 "additionalProperties": False,
880 }
881
882 # VCA
883 vca_new_schema = {
884 "title": "vca creation input schema",
885 "$schema": "http://json-schema.org/draft-04/schema#",
886 "type": "object",
887 "properties": {
888 "schema_version": schema_version,
889 "schema_type": schema_type,
890 "name": name_schema,
891 "description": description_schema,
892 "endpoints": description_list_schema,
893 "user": string_schema,
894 "secret": passwd_schema,
895 "cacert": long_description_schema,
896 "lxd-cloud": shortname_schema,
897 "lxd-credentials": shortname_schema,
898 "k8s-cloud": shortname_schema,
899 "k8s-credentials": shortname_schema,
900 "model-config": object_schema,
901 },
902 "required": [
903 "name",
904 "endpoints",
905 "user",
906 "secret",
907 "cacert",
908 "lxd-cloud",
909 "lxd-credentials",
910 "k8s-cloud",
911 "k8s-credentials",
912 ],
913 "additionalProperties": False,
914 }
915 vca_edit_schema = {
916 "title": "vca creation input schema",
917 "$schema": "http://json-schema.org/draft-04/schema#",
918 "type": "object",
919 "properties": {
920 "name": name_schema,
921 "description": description_schema,
922 "endpoints": description_list_schema,
923 "port": integer1_schema,
924 "user": string_schema,
925 "secret": passwd_schema,
926 "cacert": long_description_schema,
927 "lxd-cloud": shortname_schema,
928 "lxd-credentials": shortname_schema,
929 "k8s-cloud": shortname_schema,
930 "k8s-credentials": shortname_schema,
931 "model-config": object_schema,
932 },
933 "additionalProperties": False,
934 }
935
936 # PAAS
937 paas_types = {"enum": ["juju"]}
938 paas_new_schema = {
939 "title": "paas creation input schema",
940 "$schema": "http://json-schema.org/draft-04/schema#",
941 "type": "object",
942 "properties": {
943 "schema_version": schema_version,
944 "schema_type": schema_type,
945 "name": name_schema,
946 "paas_type": paas_types,
947 "description": description_schema,
948 "endpoints": description_list_schema,
949 "user": string_schema,
950 "secret": passwd_schema,
951 "config": object_schema,
952 },
953 "required": [
954 "name",
955 "paas_type",
956 "endpoints",
957 "user",
958 "secret",
959 ],
960 "additionalProperties": False,
961 }
962 paas_edit_schema = {
963 "title": "paas edition input schema",
964 "$schema": "http://json-schema.org/draft-04/schema#",
965 "type": "object",
966 "properties": {
967 "name": name_schema,
968 "paas_type": paas_types,
969 "description": description_schema,
970 "endpoints": description_list_schema,
971 "user": string_schema,
972 "secret": passwd_schema,
973 "config": object_schema,
974 },
975 "additionalProperties": False,
976 }
977
978 # K8s Repos
979 k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
980 k8srepo_properties = {
981 "name": name_schema,
982 "description": description_schema,
983 "type": k8srepo_types,
984 "url": description_schema,
985 }
986 k8srepo_new_schema = {
987 "title": "k8scluster creation input schema",
988 "$schema": "http://json-schema.org/draft-04/schema#",
989 "type": "object",
990 "properties": k8srepo_properties,
991 "required": ["name", "type", "url"],
992 "additionalProperties": False,
993 }
994 k8srepo_edit_schema = {
995 "title": "vim_account edit input schema",
996 "$schema": "http://json-schema.org/draft-04/schema#",
997 "type": "object",
998 "properties": k8srepo_properties,
999 "additionalProperties": False,
1000 }
1001
1002 # OSM Repos
1003 osmrepo_types = {"enum": ["osm"]}
1004 osmrepo_properties = {
1005 "name": name_schema,
1006 "description": description_schema,
1007 "type": osmrepo_types,
1008 "url": description_schema
1009 # "user": string_schema,
1010 # "password": passwd_schema
1011 }
1012 osmrepo_new_schema = {
1013 "title": "osm repo creation input schema",
1014 "$schema": "http://json-schema.org/draft-04/schema#",
1015 "type": "object",
1016 "properties": osmrepo_properties,
1017 "required": ["name", "type", "url"],
1018 "additionalProperties": False,
1019 }
1020 osmrepo_edit_schema = {
1021 "title": "osm repo edit input schema",
1022 "$schema": "http://json-schema.org/draft-04/schema#",
1023 "type": "object",
1024 "properties": osmrepo_properties,
1025 "additionalProperties": False,
1026 }
1027
1028 # PDUs
1029 pdu_interface = {
1030 "type": "object",
1031 "properties": {
1032 "name": shortname_schema,
1033 "mgmt": bool_schema,
1034 "type": {"enum": ["overlay", "underlay"]},
1035 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
1036 # TODO, add user, password, ssh-key
1037 "mac-address": mac_schema,
1038 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
1039 "vim-network-id": shortname_schema,
1040 # # provide this in case SDN assist must deal with this interface
1041 # "switch-dpid": dpid_Schema,
1042 # "switch-port": shortname_schema,
1043 # "switch-mac": shortname_schema,
1044 # "switch-vlan": vlan_schema,
1045 },
1046 "required": ["name", "mgmt", "ip-address"],
1047 "additionalProperties": False,
1048 }
1049 pdu_new_schema = {
1050 "title": "pdu creation input schema",
1051 "$schema": "http://json-schema.org/draft-04/schema#",
1052 "type": "object",
1053 "properties": {
1054 "name": shortname_schema,
1055 "type": shortname_schema,
1056 "description": description_schema,
1057 "shared": bool_schema,
1058 "vims": nameshort_list_schema,
1059 "vim_accounts": nameshort_list_schema,
1060 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
1061 },
1062 "required": ["name", "type", "interfaces"],
1063 "additionalProperties": False,
1064 }
1065 pdu_edit_schema = {
1066 "title": "pdu edit input schema",
1067 "$schema": "http://json-schema.org/draft-04/schema#",
1068 "type": "object",
1069 "properties": {
1070 "name": shortname_schema,
1071 "type": shortname_schema,
1072 "description": description_schema,
1073 "shared": bool_schema,
1074 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1075 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1076 "interfaces": {
1077 "oneOf": [
1078 array_edition_schema,
1079 {"type": "array", "items": pdu_interface, "minItems": 1},
1080 ]
1081 },
1082 },
1083 "additionalProperties": False,
1084 "minProperties": 1,
1085 }
1086
1087 # VNF PKG OPERATIONS
1088 vnfpkgop_new_schema = {
1089 "title": "VNF PKG operation creation input schema",
1090 "$schema": "http://json-schema.org/draft-04/schema#",
1091 "type": "object",
1092 "properties": {
1093 "lcmOperationType": string_schema,
1094 "vnfPkgId": id_schema,
1095 "kdu_name": name_schema,
1096 "primitive": name_schema,
1097 "primitive_params": {"type": "object"},
1098 },
1099 "required": [
1100 "lcmOperationType",
1101 "vnfPkgId",
1102 "kdu_name",
1103 "primitive",
1104 "primitive_params",
1105 ],
1106 "additionalProperties": False,
1107 }
1108
1109 # USERS
1110 project_role_mappings = {
1111 "title": "list pf projects/roles",
1112 "$schema": "http://json-schema.org/draft-04/schema#",
1113 "type": "array",
1114 "items": {
1115 "type": "object",
1116 "properties": {"project": shortname_schema, "role": shortname_schema},
1117 "required": ["project", "role"],
1118 "additionalProperties": False,
1119 },
1120 "minItems": 1,
1121 }
1122 project_role_mappings_optional = {
1123 "title": "list of projects/roles or projects only",
1124 "$schema": "http://json-schema.org/draft-04/schema#",
1125 "type": "array",
1126 "items": {
1127 "type": "object",
1128 "properties": {"project": shortname_schema, "role": shortname_schema},
1129 "required": ["project"],
1130 "additionalProperties": False,
1131 },
1132 "minItems": 1,
1133 }
1134 user_new_schema = {
1135 "$schema": "http://json-schema.org/draft-04/schema#",
1136 "title": "New user schema",
1137 "type": "object",
1138 "properties": {
1139 "username": string_schema,
1140 "domain_name": shortname_schema,
1141 "password": passwd_schema,
1142 "projects": nameshort_list_schema,
1143 "project_role_mappings": project_role_mappings,
1144 },
1145 "required": ["username", "password"],
1146 "additionalProperties": False,
1147 }
1148 user_edit_schema = {
1149 "$schema": "http://json-schema.org/draft-04/schema#",
1150 "title": "User edit schema for administrators",
1151 "type": "object",
1152 "properties": {
1153 "password": passwd_schema,
1154 "old_password": passwd_schema,
1155 "username": string_schema, # To allow User Name modification
1156 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
1157 "project_role_mappings": project_role_mappings,
1158 "add_project_role_mappings": project_role_mappings,
1159 "remove_project_role_mappings": project_role_mappings_optional,
1160 },
1161 "minProperties": 1,
1162 "additionalProperties": False,
1163 }
1164
1165 # PROJECTS
1166 topics_with_quota = [
1167 "vnfds",
1168 "nsds",
1169 "slice_templates",
1170 "pduds",
1171 "ns_instances",
1172 "slice_instances",
1173 "vim_accounts",
1174 "wim_accounts",
1175 "sdn_controllers",
1176 "k8sclusters",
1177 "vca",
1178 "paas",
1179 "k8srepos",
1180 "osmrepos",
1181 "ns_subscriptions",
1182 ]
1183 project_new_schema = {
1184 "$schema": "http://json-schema.org/draft-04/schema#",
1185 "title": "New project schema for administrators",
1186 "type": "object",
1187 "properties": {
1188 "name": shortname_schema,
1189 "admin": bool_schema,
1190 "domain_name": shortname_schema,
1191 "quotas": {
1192 "type": "object",
1193 "properties": {topic: integer0_schema for topic in topics_with_quota},
1194 "additionalProperties": False,
1195 },
1196 },
1197 "required": ["name"],
1198 "additionalProperties": False,
1199 }
1200 project_edit_schema = {
1201 "$schema": "http://json-schema.org/draft-04/schema#",
1202 "title": "Project edit schema for administrators",
1203 "type": "object",
1204 "properties": {
1205 "admin": bool_schema,
1206 "name": shortname_schema, # To allow Project Name modification
1207 "quotas": {
1208 "type": "object",
1209 "properties": {
1210 topic: {"oneOf": [integer0_schema, null_schema]}
1211 for topic in topics_with_quota
1212 },
1213 "additionalProperties": False,
1214 },
1215 },
1216 "additionalProperties": False,
1217 "minProperties": 1,
1218 }
1219
1220 # ROLES
1221 roles_new_schema = {
1222 "$schema": "http://json-schema.org/draft-04/schema#",
1223 "title": "New role schema for administrators",
1224 "type": "object",
1225 "properties": {
1226 "name": shortname_schema,
1227 "permissions": {
1228 "type": "object",
1229 "patternProperties": {
1230 ".": bool_schema,
1231 },
1232 # "minProperties": 1,
1233 },
1234 },
1235 "required": ["name"],
1236 "additionalProperties": False,
1237 }
1238 roles_edit_schema = {
1239 "$schema": "http://json-schema.org/draft-04/schema#",
1240 "title": "Roles edit schema for administrators",
1241 "type": "object",
1242 "properties": {
1243 "name": shortname_schema,
1244 "permissions": {
1245 "type": "object",
1246 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
1247 # "minProperties": 1,
1248 },
1249 },
1250 "additionalProperties": False,
1251 "minProperties": 1,
1252 }
1253
1254 # GLOBAL SCHEMAS
1255
1256 nbi_new_input_schemas = {
1257 "users": user_new_schema,
1258 "projects": project_new_schema,
1259 "vim_accounts": vim_account_new_schema,
1260 "sdns": sdn_new_schema,
1261 "ns_instantiate": ns_instantiate,
1262 "ns_action": ns_action,
1263 "ns_scale": ns_scale,
1264 "ns_update": ns_update,
1265 "ns_heal": ns_heal,
1266 "pdus": pdu_new_schema,
1267 }
1268
1269 nbi_edit_input_schemas = {
1270 "users": user_edit_schema,
1271 "projects": project_edit_schema,
1272 "vim_accounts": vim_account_edit_schema,
1273 "sdns": sdn_edit_schema,
1274 "pdus": pdu_edit_schema,
1275 }
1276
1277 # NETSLICE SCHEMAS
1278 nsi_subnet_instantiate = deepcopy(ns_instantiate)
1279 nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1280 nsi_subnet_instantiate["properties"]["id"] = name_schema
1281 del nsi_subnet_instantiate["required"]
1282
1283 nsi_vld_instantiate = {
1284 "title": "netslice vld instantiation params input schema",
1285 "$schema": "http://json-schema.org/draft-04/schema#",
1286 "type": "object",
1287 "properties": {
1288 "name": string_schema,
1289 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1290 "vim-network-id": {"oneOf": [string_schema, object_schema]},
1291 "ip-profile": object_schema,
1292 },
1293 "required": ["name"],
1294 "additionalProperties": False,
1295 }
1296
1297 nsi_instantiate = {
1298 "title": "netslice action instantiate input schema",
1299 "$schema": "http://json-schema.org/draft-04/schema#",
1300 "type": "object",
1301 "properties": {
1302 "lcmOperationType": string_schema,
1303 "netsliceInstanceId": id_schema,
1304 "nsiName": name_schema,
1305 "nsiDescription": {"oneOf": [description_schema, null_schema]},
1306 "nstId": string_schema,
1307 "vimAccountId": id_schema,
1308 "timeout_nsi_deploy": integer1_schema,
1309 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1310 "nsi_id": id_schema,
1311 "additionalParamsForNsi": object_schema,
1312 "netslice-subnet": {
1313 "type": "array",
1314 "minItems": 1,
1315 "items": nsi_subnet_instantiate,
1316 },
1317 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
1318 },
1319 "required": ["nsiName", "nstId", "vimAccountId"],
1320 "additionalProperties": False,
1321 }
1322
1323 nsi_action = {}
1324
1325 nsi_terminate = {}
1326
1327 nsinstancesubscriptionfilter_schema = {
1328 "title": "instance identifier schema",
1329 "$schema": "http://json-schema.org/draft-07/schema#",
1330 "type": "object",
1331 "properties": {
1332 "nsdIds": {"type": "array"},
1333 "vnfdIds": {"type": "array"},
1334 "pnfdIds": {"type": "array"},
1335 "nsInstanceIds": {"type": "array"},
1336 "nsInstanceNames": {"type": "array"},
1337 },
1338 }
1339
1340 nslcmsub_schema = {
1341 "title": "nslcmsubscription input schema",
1342 "$schema": "http://json-schema.org/draft-07/schema#",
1343 "type": "object",
1344 "properties": {
1345 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1346 "notificationTypes": {
1347 "type": "array",
1348 "items": {
1349 "enum": [
1350 "NsLcmOperationOccurrenceNotification",
1351 "NsChangeNotification",
1352 "NsIdentifierCreationNotification",
1353 "NsIdentifierDeletionNotification",
1354 ]
1355 },
1356 },
1357 "operationTypes": {
1358 "type": "array",
1359 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1360 },
1361 "operationStates": {
1362 "type": "array",
1363 "items": {
1364 "enum": [
1365 "PROCESSING",
1366 "COMPLETED",
1367 "PARTIALLY_COMPLETED",
1368 "FAILED",
1369 "FAILED_TEMP",
1370 "ROLLING_BACK",
1371 "ROLLED_BACK",
1372 ]
1373 },
1374 },
1375 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1376 "lcmOpNameImpactingNsComponent": {
1377 "type": "array",
1378 "items": {
1379 "enum": [
1380 "VNF_INSTANTIATE",
1381 "VNF_SCALE",
1382 "VNF_SCALE_TO_LEVEL",
1383 "VNF_CHANGE_FLAVOUR",
1384 "VNF_TERMINATE",
1385 "VNF_HEAL",
1386 "VNF_OPERATE",
1387 "VNF_CHANGE_EXT_CONN",
1388 "VNF_MODIFY_INFO",
1389 "NS_INSTANTIATE",
1390 "NS_SCALE",
1391 "NS_UPDATE",
1392 "NS_TERMINATE",
1393 "NS_HEAL",
1394 ]
1395 },
1396 },
1397 "lcmOpOccStatusImpactingNsComponent": {
1398 "type": "array",
1399 "items": {
1400 "enum": [
1401 "START",
1402 "COMPLETED",
1403 "PARTIALLY_COMPLETED",
1404 "FAILED",
1405 "ROLLED_BACK",
1406 ]
1407 },
1408 },
1409 },
1410 "allOf": [
1411 {
1412 "if": {
1413 "properties": {
1414 "notificationTypes": {
1415 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1416 }
1417 },
1418 },
1419 "then": {
1420 "anyOf": [
1421 {"required": ["operationTypes"]},
1422 {"required": ["operationStates"]},
1423 ]
1424 },
1425 },
1426 {
1427 "if": {
1428 "properties": {
1429 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1430 },
1431 },
1432 "then": {
1433 "anyOf": [
1434 {"required": ["nsComponentTypes"]},
1435 {"required": ["lcmOpNameImpactingNsComponent"]},
1436 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1437 ]
1438 },
1439 },
1440 ],
1441 }
1442
1443 authentication_schema = {
1444 "title": "authentication schema for subscription",
1445 "$schema": "http://json-schema.org/draft-07/schema#",
1446 "type": "object",
1447 "properties": {
1448 "authType": {"enum": ["basic"]},
1449 "paramsBasic": {
1450 "type": "object",
1451 "properties": {
1452 "userName": string_schema,
1453 "password": passwd_schema,
1454 },
1455 },
1456 },
1457 }
1458
1459 subscription = {
1460 "title": "subscription input schema",
1461 "$schema": "http://json-schema.org/draft-07/schema#",
1462 "type": "object",
1463 "properties": {
1464 "filter": nslcmsub_schema,
1465 "CallbackUri": description_schema,
1466 "authentication": authentication_schema,
1467 },
1468 "required": ["CallbackUri"],
1469 }
1470
1471 vnflcmsub_schema = {
1472 "title": "vnflcmsubscription input schema",
1473 "$schema": "http://json-schema.org/draft-07/schema#",
1474 "type": "object",
1475 "properties": {
1476 "VnfInstanceSubscriptionFilter": {
1477 "type": "object",
1478 "properties": {
1479 "vnfdIds": {"type": "array"},
1480 "vnfInstanceIds": {"type": "array"},
1481 },
1482 },
1483 "notificationTypes": {
1484 "type": "array",
1485 "items": {
1486 "enum": [
1487 "VnfIdentifierCreationNotification",
1488 "VnfLcmOperationOccurrenceNotification",
1489 "VnfIdentifierDeletionNotification",
1490 ]
1491 },
1492 },
1493 "operationTypes": {
1494 "type": "array",
1495 "items": {
1496 "enum": [
1497 "INSTANTIATE",
1498 "SCALE",
1499 "SCALE_TO_LEVEL",
1500 "CHANGE_FLAVOUR",
1501 "TERMINATE",
1502 "HEAL",
1503 "OPERATE",
1504 "CHANGE_EXT_CONN",
1505 "MODIFY_INFO",
1506 "CREATE_SNAPSHOT",
1507 "REVERT_TO_SNAPSHOT",
1508 "CHANGE_VNFPKG",
1509 ]
1510 },
1511 },
1512 "operationStates": {
1513 "type": "array",
1514 "items": {
1515 "enum": [
1516 "STARTING",
1517 "PROCESSING",
1518 "COMPLETED",
1519 "FAILED_TEMP",
1520 "FAILED",
1521 "ROLLING_BACK",
1522 "ROLLED_BACK",
1523 ]
1524 },
1525 },
1526 },
1527 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1528 }
1529
1530 vnf_subscription = {
1531 "title": "vnf subscription input schema",
1532 "$schema": "http://json-schema.org/draft-07/schema#",
1533 "type": "object",
1534 "properties": {
1535 "filter": vnflcmsub_schema,
1536 "CallbackUri": description_schema,
1537 "authentication": authentication_schema,
1538 },
1539 "required": ["filter", "CallbackUri"],
1540 }
1541
1542
1543 class ValidationError(Exception):
1544 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1545 self.http_code = http_code
1546 Exception.__init__(self, message)
1547
1548
1549 def validate_input(indata, schema_to_use):
1550 """
1551 Validates input data against json schema
1552 :param indata: user input data. Should be a dictionary
1553 :param schema_to_use: jsonschema to test
1554 :return: None if ok, raises ValidationError exception on error
1555 """
1556 try:
1557 if schema_to_use:
1558 js_v(indata, schema_to_use)
1559 return None
1560 except js_e.ValidationError as e:
1561 if e.path:
1562 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
1563 else:
1564 error_pos = ""
1565 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
1566 except js_e.SchemaError:
1567 raise ValidationError(
1568 "Bad json schema {}".format(schema_to_use),
1569 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1570 )
1571
1572
1573 def is_valid_uuid(x):
1574 """
1575 Test for a valid UUID
1576 :param x: string to test
1577 :return: True if x is a valid uuid, False otherwise
1578 """
1579 try:
1580 if UUID(x):
1581 return True
1582 except (TypeError, ValueError, AttributeError):
1583 return False