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