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