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