Feature 10922: Stop, start and rebuild
[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": ["CHANGE_VNFPKG", "REMOVE_VNF", "MODIFY_VNF_INFORMATION", "OPERATE_VNF"]
453 },
454 "modifyVnfInfoData": {
455 "type": "object",
456 "properties": {
457 "vnfInstanceId": id_schema,
458 "vnfdId": id_schema,
459 },
460 "required": ["vnfInstanceId", "vnfdId"],
461 },
462 "removeVnfInstanceId": id_schema,
463 "changeVnfPackageData": {
464 "type": "object",
465 "properties": {
466 "vnfInstanceId": id_schema,
467 "vnfdId": id_schema,
468 },
469 "required": ["vnfInstanceId", "vnfdId"],
470 },
471 "operateVnfData": {
472 "type": "object",
473 "properties": {
474 "vnfInstanceId": id_schema,
475 "changeStateTo": name_schema,
476 "additionalParam": {
477 "type": "object",
478 "properties": {
479 "run-day1": bool_schema,
480 "vdu_id": name_schema,
481 "count-index": integer0_schema,
482 },
483 "required": ["vdu_id", "count-index"],
484 "additionalProperties": False,
485 }
486 },
487 "required": ["vnfInstanceId", "changeStateTo"],
488 }
489 },
490 "required": ["updateType"],
491 "additionalProperties": False,
492 }
493
494 ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
495 "title": "ns action input schema",
496 "$schema": "http://json-schema.org/draft-04/schema#",
497 "type": "object",
498 "properties": {
499 "lcmOperationType": string_schema,
500 "nsInstanceId": id_schema,
501 "member_vnf_index": name_schema,
502 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
503 "vdu_id": name_schema,
504 "vdu_count_index": integer0_schema,
505 "kdu_name": name_schema,
506 "primitive": name_schema,
507 "timeout_ns_action": integer1_schema,
508 "primitive_params": {"type": "object"},
509 },
510 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
511 "additionalProperties": False,
512 }
513
514 ns_scale = { # TODO for the moment it is only VDU-scaling
515 "title": "ns scale input schema",
516 "$schema": "http://json-schema.org/draft-04/schema#",
517 "type": "object",
518 "properties": {
519 "lcmOperationType": string_schema,
520 "nsInstanceId": id_schema,
521 "scaleType": {"enum": ["SCALE_VNF"]},
522 "timeout_ns_scale": integer1_schema,
523 "scaleVnfData": {
524 "type": "object",
525 "properties": {
526 "vnfInstanceId": name_schema,
527 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
528 "scaleByStepData": {
529 "type": "object",
530 "properties": {
531 "scaling-group-descriptor": name_schema,
532 "member-vnf-index": name_schema,
533 "scaling-policy": name_schema,
534 },
535 "required": ["scaling-group-descriptor", "member-vnf-index"],
536 "additionalProperties": False,
537 },
538 },
539 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
540 "additionalProperties": False,
541 },
542 "scaleTime": time_schema,
543 },
544 "required": ["scaleType", "scaleVnfData"],
545 "additionalProperties": False,
546 }
547
548 ns_migrate = {
549 "title": "ns migrate input schema",
550 "$schema": "http://json-schema.org/draft-04/schema#",
551 "type": "object",
552 "properties": {
553 "lcmOperationType": string_schema,
554 "nsInstanceId": id_schema,
555 "vnfInstanceId": id_schema,
556 "migrateToHost": string_schema,
557 "vdu": {
558 "type": "object",
559 "properties": {
560 "vduId": name_schema,
561 "vduCountIndex": integer0_schema,
562 },
563 "required": ["vduId"],
564 "additionalProperties": False,
565 },
566 },
567 "required": ["vnfInstanceId"],
568 "additionalProperties": False
569 }
570
571 ns_heal = {
572 "title": "ns heal input schema",
573 "$schema": "http://json-schema.org/draft-04/schema#",
574 "type": "object",
575 "properties": {
576 "lcmOperationType": string_schema,
577 "nsInstanceId": id_schema,
578 "timeout_ns_heal": integer1_schema,
579 "healVnfData": {
580 "type": "array",
581 "items": {
582 "type": "object",
583 "properties": {
584 "vnfInstanceId": id_schema,
585 "cause": description_schema,
586 "additionalParams": {
587 "type": "object",
588 "properties": {
589 "run-day1": bool_schema,
590 "vdu": {
591 "type": "array",
592 "items": {
593 "type": "object",
594 "properties": {
595 "run-day1": bool_schema,
596 "vdu-id": name_schema,
597 "count-index": integer0_schema,
598 },
599 "required": ["vdu-id"],
600 "additionalProperties": False,
601 },
602 },
603 },
604 "additionalProperties": False,
605 },
606 },
607 "required": ["vnfInstanceId"],
608 "additionalProperties": False,
609 },
610 },
611 },
612 "required": ["healVnfData"],
613 "additionalProperties": False,
614 }
615
616 schema_version = {"type": "string", "enum": ["1.0"]}
617 schema_type = {"type": "string"}
618 vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
619
620 vim_account_edit_schema = {
621 "title": "vim_account edit input schema",
622 "$schema": "http://json-schema.org/draft-04/schema#",
623 "type": "object",
624 "properties": {
625 "name": name_schema,
626 "description": description_schema,
627 "vim": name_schema,
628 "datacenter": name_schema,
629 "vim_type": vim_type,
630 "vim_url": description_schema,
631 # "vim_url_admin": description_schema,
632 # "vim_tenant": name_schema,
633 "vim_tenant_name": name_schema,
634 "vim_user": string_schema,
635 "vim_password": passwd_schema,
636 "vca": id_schema,
637 "config": {"type": "object"},
638 "prometheus-config": {"type": "object"},
639 },
640 "additionalProperties": False,
641 }
642
643 vim_account_new_schema = {
644 "title": "vim_account creation input schema",
645 "$schema": "http://json-schema.org/draft-04/schema#",
646 "type": "object",
647 "properties": {
648 "schema_version": schema_version,
649 "schema_type": schema_type,
650 "name": name_schema,
651 "description": description_schema,
652 "vim": name_schema,
653 "datacenter": name_schema,
654 "vim_type": vim_type,
655 "vim_url": description_schema,
656 # "vim_url_admin": description_schema,
657 # "vim_tenant": name_schema,
658 "vim_tenant_name": name_schema,
659 "vim_user": string_schema,
660 "vim_password": passwd_schema,
661 "vca": id_schema,
662 "config": {"type": "object"},
663 "prometheus-config": {"type": "object"},
664 },
665 "required": [
666 "name",
667 "vim_url",
668 "vim_type",
669 "vim_user",
670 "vim_password",
671 "vim_tenant_name",
672 ],
673 "additionalProperties": False,
674 }
675
676 wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
677
678 wim_account_edit_schema = {
679 "title": "wim_account edit input schema",
680 "$schema": "http://json-schema.org/draft-04/schema#",
681 "type": "object",
682 "properties": {
683 "name": name_schema,
684 "description": description_schema,
685 "wim": name_schema,
686 "wim_type": wim_type,
687 "wim_url": description_schema,
688 "user": string_schema,
689 "password": passwd_schema,
690 "config": {"type": "object"},
691 },
692 "additionalProperties": False,
693 }
694
695 wim_account_new_schema = {
696 "title": "wim_account creation input schema",
697 "$schema": "http://json-schema.org/draft-04/schema#",
698 "type": "object",
699 "properties": {
700 "schema_version": schema_version,
701 "schema_type": schema_type,
702 "name": name_schema,
703 "description": description_schema,
704 "wim": name_schema,
705 "wim_type": wim_type,
706 "wim_url": description_schema,
707 "user": string_schema,
708 "password": passwd_schema,
709 "config": {
710 "type": "object",
711 "patternProperties": {".": {"not": {"type": "null"}}},
712 },
713 },
714 "required": ["name", "wim_url", "wim_type"],
715 "additionalProperties": False,
716 }
717
718 sdn_properties = {
719 "name": name_schema,
720 "type": {"type": "string"},
721 "url": {"type": "string"},
722 "user": string_schema,
723 "password": passwd_schema,
724 "config": {"type": "object"},
725 "description": description_schema,
726 # The folowing are deprecated. Maintanied for backward compatibility
727 "dpid": dpid_Schema,
728 "ip": ip_schema,
729 "port": port_schema,
730 "version": {"type": "string", "minLength": 1, "maxLength": 12},
731 }
732 sdn_new_schema = {
733 "title": "sdn controller information schema",
734 "$schema": "http://json-schema.org/draft-04/schema#",
735 "type": "object",
736 "properties": sdn_properties,
737 "required": ["name", "type"],
738 "additionalProperties": False,
739 }
740 sdn_edit_schema = {
741 "title": "sdn controller update information schema",
742 "$schema": "http://json-schema.org/draft-04/schema#",
743 "type": "object",
744 "properties": sdn_properties,
745 # "required": ["name", "port", 'ip', 'dpid', 'type'],
746 "additionalProperties": False,
747 }
748 sdn_port_mapping_schema = {
749 "$schema": "http://json-schema.org/draft-04/schema#",
750 "title": "sdn port mapping information schema",
751 "type": "array",
752 "items": {
753 "type": "object",
754 "properties": {
755 "compute_node": shortname_schema,
756 "ports": {
757 "type": "array",
758 "items": {
759 "type": "object",
760 "properties": {
761 "pci": pci_extended_schema,
762 "switch_port": shortname_schema,
763 "switch_mac": mac_schema,
764 },
765 "required": ["pci"],
766 },
767 },
768 },
769 "required": ["compute_node", "ports"],
770 },
771 }
772 sdn_external_port_schema = {
773 "$schema": "http://json-schema.org/draft-04/schema#",
774 "title": "External port information",
775 "type": "object",
776 "properties": {
777 "port": {"type": "string", "minLength": 1, "maxLength": 60},
778 "vlan": vlan_schema,
779 "mac": mac_schema,
780 },
781 "required": ["port"],
782 }
783
784 # K8s Clusters
785 k8scluster_deploy_method_schema = {
786 "$schema": "http://json-schema.org/draft-04/schema#",
787 "title": "Deployment methods for K8s cluster",
788 "type": "object",
789 "properties": {
790 "helm-chart": {"type": "boolean"},
791 "juju-bundle": {"type": "boolean"},
792 "helm-chart-v3": {"type": "boolean"},
793 },
794 "additionalProperties": False,
795 "minProperties": 3,
796 }
797 k8scluster_nets_schema = {
798 "title": "k8scluster nets input schema",
799 "$schema": "http://json-schema.org/draft-04/schema#",
800 "type": "object",
801 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
802 "minProperties": 1,
803 "additionalProperties": False,
804 }
805 k8scluster_new_schema = {
806 "title": "k8scluster creation input schema",
807 "$schema": "http://json-schema.org/draft-04/schema#",
808 "type": "object",
809 "properties": {
810 "schema_version": schema_version,
811 "schema_type": schema_type,
812 "name": name_schema,
813 "description": description_schema,
814 "credentials": object_schema,
815 "vim_account": id_schema,
816 "vca_id": id_schema,
817 "k8s_version": string_schema,
818 "nets": k8scluster_nets_schema,
819 "deployment_methods": k8scluster_deploy_method_schema,
820 "namespace": name_schema,
821 "cni": nameshort_list_schema,
822 },
823 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
824 "additionalProperties": False,
825 }
826 k8scluster_edit_schema = {
827 "title": "vim_account edit input schema",
828 "$schema": "http://json-schema.org/draft-04/schema#",
829 "type": "object",
830 "properties": {
831 "name": name_schema,
832 "description": description_schema,
833 "credentials": object_schema,
834 "vim_account": id_schema,
835 "vca_id": id_schema,
836 "k8s_version": string_schema,
837 "nets": k8scluster_nets_schema,
838 "namespace": name_schema,
839 "cni": nameshort_list_schema,
840 },
841 "additionalProperties": False,
842 }
843
844 # VCA
845 vca_new_schema = {
846 "title": "vca creation input schema",
847 "$schema": "http://json-schema.org/draft-04/schema#",
848 "type": "object",
849 "properties": {
850 "schema_version": schema_version,
851 "schema_type": schema_type,
852 "name": name_schema,
853 "description": description_schema,
854 "endpoints": description_list_schema,
855 "user": string_schema,
856 "secret": passwd_schema,
857 "cacert": long_description_schema,
858 "lxd-cloud": shortname_schema,
859 "lxd-credentials": shortname_schema,
860 "k8s-cloud": shortname_schema,
861 "k8s-credentials": shortname_schema,
862 "model-config": object_schema,
863 },
864 "required": [
865 "name",
866 "endpoints",
867 "user",
868 "secret",
869 "cacert",
870 "lxd-cloud",
871 "lxd-credentials",
872 "k8s-cloud",
873 "k8s-credentials",
874 ],
875 "additionalProperties": False,
876 }
877 vca_edit_schema = {
878 "title": "vca creation input schema",
879 "$schema": "http://json-schema.org/draft-04/schema#",
880 "type": "object",
881 "properties": {
882 "name": name_schema,
883 "description": description_schema,
884 "endpoints": description_list_schema,
885 "port": integer1_schema,
886 "user": string_schema,
887 "secret": passwd_schema,
888 "cacert": long_description_schema,
889 "lxd-cloud": shortname_schema,
890 "lxd-credentials": shortname_schema,
891 "k8s-cloud": shortname_schema,
892 "k8s-credentials": shortname_schema,
893 "model-config": object_schema,
894 },
895 "additionalProperties": False,
896 }
897
898 # K8s Repos
899 k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
900 k8srepo_properties = {
901 "name": name_schema,
902 "description": description_schema,
903 "type": k8srepo_types,
904 "url": description_schema,
905 }
906 k8srepo_new_schema = {
907 "title": "k8scluster creation input schema",
908 "$schema": "http://json-schema.org/draft-04/schema#",
909 "type": "object",
910 "properties": k8srepo_properties,
911 "required": ["name", "type", "url"],
912 "additionalProperties": False,
913 }
914 k8srepo_edit_schema = {
915 "title": "vim_account edit input schema",
916 "$schema": "http://json-schema.org/draft-04/schema#",
917 "type": "object",
918 "properties": k8srepo_properties,
919 "additionalProperties": False,
920 }
921
922 # OSM Repos
923 osmrepo_types = {"enum": ["osm"]}
924 osmrepo_properties = {
925 "name": name_schema,
926 "description": description_schema,
927 "type": osmrepo_types,
928 "url": description_schema
929 # "user": string_schema,
930 # "password": passwd_schema
931 }
932 osmrepo_new_schema = {
933 "title": "osm repo creation input schema",
934 "$schema": "http://json-schema.org/draft-04/schema#",
935 "type": "object",
936 "properties": osmrepo_properties,
937 "required": ["name", "type", "url"],
938 "additionalProperties": False,
939 }
940 osmrepo_edit_schema = {
941 "title": "osm repo edit input schema",
942 "$schema": "http://json-schema.org/draft-04/schema#",
943 "type": "object",
944 "properties": osmrepo_properties,
945 "additionalProperties": False,
946 }
947
948 # PDUs
949 pdu_interface = {
950 "type": "object",
951 "properties": {
952 "name": shortname_schema,
953 "mgmt": bool_schema,
954 "type": {"enum": ["overlay", "underlay"]},
955 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
956 # TODO, add user, password, ssh-key
957 "mac-address": mac_schema,
958 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
959 "vim-network-id": shortname_schema,
960 # # provide this in case SDN assist must deal with this interface
961 # "switch-dpid": dpid_Schema,
962 # "switch-port": shortname_schema,
963 # "switch-mac": shortname_schema,
964 # "switch-vlan": vlan_schema,
965 },
966 "required": ["name", "mgmt", "ip-address"],
967 "additionalProperties": False,
968 }
969 pdu_new_schema = {
970 "title": "pdu creation input schema",
971 "$schema": "http://json-schema.org/draft-04/schema#",
972 "type": "object",
973 "properties": {
974 "name": shortname_schema,
975 "type": shortname_schema,
976 "description": description_schema,
977 "shared": bool_schema,
978 "vims": nameshort_list_schema,
979 "vim_accounts": nameshort_list_schema,
980 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
981 },
982 "required": ["name", "type", "interfaces"],
983 "additionalProperties": False,
984 }
985 pdu_edit_schema = {
986 "title": "pdu edit input schema",
987 "$schema": "http://json-schema.org/draft-04/schema#",
988 "type": "object",
989 "properties": {
990 "name": shortname_schema,
991 "type": shortname_schema,
992 "description": description_schema,
993 "shared": bool_schema,
994 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
995 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
996 "interfaces": {
997 "oneOf": [
998 array_edition_schema,
999 {"type": "array", "items": pdu_interface, "minItems": 1},
1000 ]
1001 },
1002 },
1003 "additionalProperties": False,
1004 "minProperties": 1,
1005 }
1006
1007 # VNF PKG OPERATIONS
1008 vnfpkgop_new_schema = {
1009 "title": "VNF PKG operation creation input schema",
1010 "$schema": "http://json-schema.org/draft-04/schema#",
1011 "type": "object",
1012 "properties": {
1013 "lcmOperationType": string_schema,
1014 "vnfPkgId": id_schema,
1015 "kdu_name": name_schema,
1016 "primitive": name_schema,
1017 "primitive_params": {"type": "object"},
1018 },
1019 "required": [
1020 "lcmOperationType",
1021 "vnfPkgId",
1022 "kdu_name",
1023 "primitive",
1024 "primitive_params",
1025 ],
1026 "additionalProperties": False,
1027 }
1028
1029 # USERS
1030 project_role_mappings = {
1031 "title": "list pf projects/roles",
1032 "$schema": "http://json-schema.org/draft-04/schema#",
1033 "type": "array",
1034 "items": {
1035 "type": "object",
1036 "properties": {"project": shortname_schema, "role": shortname_schema},
1037 "required": ["project", "role"],
1038 "additionalProperties": False,
1039 },
1040 "minItems": 1,
1041 }
1042 project_role_mappings_optional = {
1043 "title": "list of projects/roles or projects only",
1044 "$schema": "http://json-schema.org/draft-04/schema#",
1045 "type": "array",
1046 "items": {
1047 "type": "object",
1048 "properties": {"project": shortname_schema, "role": shortname_schema},
1049 "required": ["project"],
1050 "additionalProperties": False,
1051 },
1052 "minItems": 1,
1053 }
1054 user_new_schema = {
1055 "$schema": "http://json-schema.org/draft-04/schema#",
1056 "title": "New user schema",
1057 "type": "object",
1058 "properties": {
1059 "username": string_schema,
1060 "domain_name": shortname_schema,
1061 "password": passwd_schema,
1062 "projects": nameshort_list_schema,
1063 "project_role_mappings": project_role_mappings,
1064 },
1065 "required": ["username", "password"],
1066 "additionalProperties": False,
1067 }
1068 user_edit_schema = {
1069 "$schema": "http://json-schema.org/draft-04/schema#",
1070 "title": "User edit schema for administrators",
1071 "type": "object",
1072 "properties": {
1073 "password": passwd_schema,
1074 "old_password": passwd_schema,
1075 "username": string_schema, # To allow User Name modification
1076 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
1077 "project_role_mappings": project_role_mappings,
1078 "add_project_role_mappings": project_role_mappings,
1079 "remove_project_role_mappings": project_role_mappings_optional,
1080 },
1081 "minProperties": 1,
1082 "additionalProperties": False,
1083 }
1084
1085 # PROJECTS
1086 topics_with_quota = [
1087 "vnfds",
1088 "nsds",
1089 "slice_templates",
1090 "pduds",
1091 "ns_instances",
1092 "slice_instances",
1093 "vim_accounts",
1094 "wim_accounts",
1095 "sdn_controllers",
1096 "k8sclusters",
1097 "vca",
1098 "k8srepos",
1099 "osmrepos",
1100 "ns_subscriptions",
1101 ]
1102 project_new_schema = {
1103 "$schema": "http://json-schema.org/draft-04/schema#",
1104 "title": "New project schema for administrators",
1105 "type": "object",
1106 "properties": {
1107 "name": shortname_schema,
1108 "admin": bool_schema,
1109 "domain_name": shortname_schema,
1110 "quotas": {
1111 "type": "object",
1112 "properties": {topic: integer0_schema for topic in topics_with_quota},
1113 "additionalProperties": False,
1114 },
1115 },
1116 "required": ["name"],
1117 "additionalProperties": False,
1118 }
1119 project_edit_schema = {
1120 "$schema": "http://json-schema.org/draft-04/schema#",
1121 "title": "Project edit schema for administrators",
1122 "type": "object",
1123 "properties": {
1124 "admin": bool_schema,
1125 "name": shortname_schema, # To allow Project Name modification
1126 "quotas": {
1127 "type": "object",
1128 "properties": {
1129 topic: {"oneOf": [integer0_schema, null_schema]}
1130 for topic in topics_with_quota
1131 },
1132 "additionalProperties": False,
1133 },
1134 },
1135 "additionalProperties": False,
1136 "minProperties": 1,
1137 }
1138
1139 # ROLES
1140 roles_new_schema = {
1141 "$schema": "http://json-schema.org/draft-04/schema#",
1142 "title": "New role schema for administrators",
1143 "type": "object",
1144 "properties": {
1145 "name": shortname_schema,
1146 "permissions": {
1147 "type": "object",
1148 "patternProperties": {
1149 ".": bool_schema,
1150 },
1151 # "minProperties": 1,
1152 },
1153 },
1154 "required": ["name"],
1155 "additionalProperties": False,
1156 }
1157 roles_edit_schema = {
1158 "$schema": "http://json-schema.org/draft-04/schema#",
1159 "title": "Roles edit schema for administrators",
1160 "type": "object",
1161 "properties": {
1162 "name": shortname_schema,
1163 "permissions": {
1164 "type": "object",
1165 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
1166 # "minProperties": 1,
1167 },
1168 },
1169 "additionalProperties": False,
1170 "minProperties": 1,
1171 }
1172
1173 # GLOBAL SCHEMAS
1174
1175 nbi_new_input_schemas = {
1176 "users": user_new_schema,
1177 "projects": project_new_schema,
1178 "vim_accounts": vim_account_new_schema,
1179 "sdns": sdn_new_schema,
1180 "ns_instantiate": ns_instantiate,
1181 "ns_action": ns_action,
1182 "ns_scale": ns_scale,
1183 "ns_update": ns_update,
1184 "ns_heal": ns_heal,
1185 "pdus": pdu_new_schema,
1186 }
1187
1188 nbi_edit_input_schemas = {
1189 "users": user_edit_schema,
1190 "projects": project_edit_schema,
1191 "vim_accounts": vim_account_edit_schema,
1192 "sdns": sdn_edit_schema,
1193 "pdus": pdu_edit_schema,
1194 }
1195
1196 # NETSLICE SCHEMAS
1197 nsi_subnet_instantiate = deepcopy(ns_instantiate)
1198 nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1199 nsi_subnet_instantiate["properties"]["id"] = name_schema
1200 del nsi_subnet_instantiate["required"]
1201
1202 nsi_vld_instantiate = {
1203 "title": "netslice vld instantiation params input schema",
1204 "$schema": "http://json-schema.org/draft-04/schema#",
1205 "type": "object",
1206 "properties": {
1207 "name": string_schema,
1208 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1209 "vim-network-id": {"oneOf": [string_schema, object_schema]},
1210 "ip-profile": object_schema,
1211 },
1212 "required": ["name"],
1213 "additionalProperties": False,
1214 }
1215
1216 nsi_instantiate = {
1217 "title": "netslice action instantiate input schema",
1218 "$schema": "http://json-schema.org/draft-04/schema#",
1219 "type": "object",
1220 "properties": {
1221 "lcmOperationType": string_schema,
1222 "netsliceInstanceId": id_schema,
1223 "nsiName": name_schema,
1224 "nsiDescription": {"oneOf": [description_schema, null_schema]},
1225 "nstId": string_schema,
1226 "vimAccountId": id_schema,
1227 "timeout_nsi_deploy": integer1_schema,
1228 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1229 "nsi_id": id_schema,
1230 "additionalParamsForNsi": object_schema,
1231 "netslice-subnet": {
1232 "type": "array",
1233 "minItems": 1,
1234 "items": nsi_subnet_instantiate,
1235 },
1236 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
1237 },
1238 "required": ["nsiName", "nstId", "vimAccountId"],
1239 "additionalProperties": False,
1240 }
1241
1242 nsi_action = {}
1243
1244 nsi_terminate = {}
1245
1246 nsinstancesubscriptionfilter_schema = {
1247 "title": "instance identifier schema",
1248 "$schema": "http://json-schema.org/draft-07/schema#",
1249 "type": "object",
1250 "properties": {
1251 "nsdIds": {"type": "array"},
1252 "vnfdIds": {"type": "array"},
1253 "pnfdIds": {"type": "array"},
1254 "nsInstanceIds": {"type": "array"},
1255 "nsInstanceNames": {"type": "array"},
1256 },
1257 }
1258
1259 nslcmsub_schema = {
1260 "title": "nslcmsubscription input schema",
1261 "$schema": "http://json-schema.org/draft-07/schema#",
1262 "type": "object",
1263 "properties": {
1264 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1265 "notificationTypes": {
1266 "type": "array",
1267 "items": {
1268 "enum": [
1269 "NsLcmOperationOccurrenceNotification",
1270 "NsChangeNotification",
1271 "NsIdentifierCreationNotification",
1272 "NsIdentifierDeletionNotification",
1273 ]
1274 },
1275 },
1276 "operationTypes": {
1277 "type": "array",
1278 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1279 },
1280 "operationStates": {
1281 "type": "array",
1282 "items": {
1283 "enum": [
1284 "PROCESSING",
1285 "COMPLETED",
1286 "PARTIALLY_COMPLETED",
1287 "FAILED",
1288 "FAILED_TEMP",
1289 "ROLLING_BACK",
1290 "ROLLED_BACK",
1291 ]
1292 },
1293 },
1294 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1295 "lcmOpNameImpactingNsComponent": {
1296 "type": "array",
1297 "items": {
1298 "enum": [
1299 "VNF_INSTANTIATE",
1300 "VNF_SCALE",
1301 "VNF_SCALE_TO_LEVEL",
1302 "VNF_CHANGE_FLAVOUR",
1303 "VNF_TERMINATE",
1304 "VNF_HEAL",
1305 "VNF_OPERATE",
1306 "VNF_CHANGE_EXT_CONN",
1307 "VNF_MODIFY_INFO",
1308 "NS_INSTANTIATE",
1309 "NS_SCALE",
1310 "NS_UPDATE",
1311 "NS_TERMINATE",
1312 "NS_HEAL",
1313 ]
1314 },
1315 },
1316 "lcmOpOccStatusImpactingNsComponent": {
1317 "type": "array",
1318 "items": {
1319 "enum": [
1320 "START",
1321 "COMPLETED",
1322 "PARTIALLY_COMPLETED",
1323 "FAILED",
1324 "ROLLED_BACK",
1325 ]
1326 },
1327 },
1328 },
1329 "allOf": [
1330 {
1331 "if": {
1332 "properties": {
1333 "notificationTypes": {
1334 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1335 }
1336 },
1337 },
1338 "then": {
1339 "anyOf": [
1340 {"required": ["operationTypes"]},
1341 {"required": ["operationStates"]},
1342 ]
1343 },
1344 },
1345 {
1346 "if": {
1347 "properties": {
1348 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1349 },
1350 },
1351 "then": {
1352 "anyOf": [
1353 {"required": ["nsComponentTypes"]},
1354 {"required": ["lcmOpNameImpactingNsComponent"]},
1355 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1356 ]
1357 },
1358 },
1359 ],
1360 }
1361
1362 authentication_schema = {
1363 "title": "authentication schema for subscription",
1364 "$schema": "http://json-schema.org/draft-07/schema#",
1365 "type": "object",
1366 "properties": {
1367 "authType": {"enum": ["basic"]},
1368 "paramsBasic": {
1369 "type": "object",
1370 "properties": {
1371 "userName": string_schema,
1372 "password": passwd_schema,
1373 },
1374 },
1375 },
1376 }
1377
1378 subscription = {
1379 "title": "subscription input schema",
1380 "$schema": "http://json-schema.org/draft-07/schema#",
1381 "type": "object",
1382 "properties": {
1383 "filter": nslcmsub_schema,
1384 "CallbackUri": description_schema,
1385 "authentication": authentication_schema,
1386 },
1387 "required": ["CallbackUri"],
1388 }
1389
1390 vnflcmsub_schema = {
1391 "title": "vnflcmsubscription input schema",
1392 "$schema": "http://json-schema.org/draft-07/schema#",
1393 "type": "object",
1394 "properties": {
1395 "VnfInstanceSubscriptionFilter": {
1396 "type": "object",
1397 "properties": {
1398 "vnfdIds": {"type": "array"},
1399 "vnfInstanceIds": {"type": "array"},
1400 },
1401 },
1402 "notificationTypes": {
1403 "type": "array",
1404 "items": {
1405 "enum": [
1406 "VnfIdentifierCreationNotification",
1407 "VnfLcmOperationOccurrenceNotification",
1408 "VnfIdentifierDeletionNotification"
1409 ]
1410 }
1411 },
1412 "operationTypes": {
1413 "type": "array",
1414 "items": {
1415 "enum": [
1416 "INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE",
1417 "HEAL", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO", "CREATE_SNAPSHOT",
1418 "REVERT_TO_SNAPSHOT", "CHANGE_VNFPKG"
1419 ]
1420 }
1421 },
1422 "operationStates": {
1423 "type": "array",
1424 "items": {
1425 "enum": [
1426 "STARTING", "PROCESSING", "COMPLETED", "FAILED_TEMP", "FAILED",
1427 "ROLLING_BACK", "ROLLED_BACK"
1428 ]
1429 }
1430 }
1431 },
1432 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"]
1433 }
1434
1435 vnf_subscription = {
1436 "title": "vnf subscription input schema",
1437 "$schema": "http://json-schema.org/draft-07/schema#",
1438 "type": "object",
1439 "properties": {
1440 "filter": vnflcmsub_schema,
1441 "CallbackUri": description_schema,
1442 "authentication": authentication_schema
1443 },
1444 "required": ["filter", "CallbackUri"]
1445 }
1446
1447
1448 class ValidationError(Exception):
1449 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1450 self.http_code = http_code
1451 Exception.__init__(self, message)
1452
1453
1454 def validate_input(indata, schema_to_use):
1455 """
1456 Validates input data against json schema
1457 :param indata: user input data. Should be a dictionary
1458 :param schema_to_use: jsonschema to test
1459 :return: None if ok, raises ValidationError exception on error
1460 """
1461 try:
1462 if schema_to_use:
1463 js_v(indata, schema_to_use)
1464 return None
1465 except js_e.ValidationError as e:
1466 if e.path:
1467 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
1468 else:
1469 error_pos = ""
1470 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
1471 except js_e.SchemaError:
1472 raise ValidationError(
1473 "Bad json schema {}".format(schema_to_use),
1474 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1475 )
1476
1477
1478 def is_valid_uuid(x):
1479 """
1480 Test for a valid UUID
1481 :param x: string to test
1482 :return: True if x is a valid uuid, False otherwise
1483 """
1484 try:
1485 if UUID(x):
1486 return True
1487 except (TypeError, ValueError, AttributeError):
1488 return False