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