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