1 # -*- coding: utf-8 -*-
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
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
21 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
23 version_date
= "Mar 2018"
26 Validator of input data using JSON schemas for those items that not contains an OSM yang information model
30 patern_name
= "^[ -~]+$"
35 "pattern": "^[^,;()\\.\\$'\"]+$",
37 passwd_schema
= {"type": "string", "minLength": 1, "maxLength": 60}
38 user_passwd_schema
= {
40 "pattern": "^.*(?=.{8,})((?=.*[!@#$%^&*()\\-_=+{};:,<.>]){1})(?=.*\\d)((?=.*[a-z]){1})((?=.*[A-Z]){1}).*$",
46 "pattern": "^[^,;()'\"]+$",
48 string_schema
= {"type": "string", "minLength": 1, "maxLength": 255}
55 description_schema
= {
56 "type": ["string", "null"],
58 "pattern": "^[^'\"]+$",
60 long_description_schema
= {
61 "type": ["string", "null"],
63 "pattern": "^[^'\"]+$",
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}$"
71 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
75 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}",
79 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$",
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}
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}$"}
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]?)$",
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
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])$",
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"]}
116 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
118 checksum_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
119 size_schema
= {"type": "integer", "minimum": 1, "maximum": 100}
120 array_edition_schema
= {
122 "patternProperties": {"^\\$": {}},
123 "additionalProperties": False,
126 nameshort_list_schema
= {
129 "items": shortname_schema
,
132 description_list_schema
= {
135 "items": description_schema
,
138 ns_instantiate_vdu
= {
139 "title": "ns action instantiate input schema for vdu",
140 "$schema": "http://json-schema.org/draft-04/schema#",
144 "vim-flavor-id": name_schema
,
152 "vim-volume-id": name_schema
,
154 "required": ["name", "vim-volume-id"],
155 "additionalProperties": False,
165 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
166 "mac-address": mac_schema
,
167 "floating-ip-required": bool_schema
,
169 "required": ["name"],
170 "additionalProperties": False,
175 "additionalProperties": False,
178 ip_profile_dns_schema
= {
184 "address": {"oneOf": [ip_schema
, ipv6_schema
]},
186 "required": ["address"],
187 "additionalProperties": False,
191 ip_profile_dhcp_schema
= {
194 "enabled": {"type": "boolean"},
195 "count": integer1_schema
,
196 "start-address": ip_schema
,
198 "additionalProperties": False,
201 ip_profile_schema
= {
202 "title": "ip profile validation schema",
203 "$schema": "http://json-schema.org/draft-04/schema#",
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
]},
212 "additionalProperties": False,
215 provider_network_schema
= {
216 "title": "provider network validation schema",
217 "$schema": "http://json-schema.org/draft-04/schema#",
220 "physical-network": name_schema
,
221 "segmentation-id": name_schema
,
222 "sdn-ports": { # external ports to append to the SDN-assist network
227 "switch_id": shortname_schema
,
228 "switch_port": shortname_schema
,
229 "mac_address": mac_schema
,
232 "additionalProperties": True,
235 "network-type": shortname_schema
,
237 "additionalProperties": True,
240 ns_instantiate_internal_vld
= {
241 "title": "ns action instantiate input schema for vld",
242 "$schema": "http://json-schema.org/draft-04/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": {
256 "id-ref": name_schema
,
257 "ip-address": ip_schema
,
258 # "mac-address": mac_schema,
260 "required": ["id-ref"],
262 "additionalProperties": False,
266 "required": ["name"],
268 "additionalProperties": False,
271 additional_params_for_vnf
= {
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": {
285 "vdu_id": name_schema
,
286 "additionalParams": object_schema
,
287 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
289 "required": ["vdu_id"],
291 "additionalProperties": False,
294 "additionalParamsForKdu": {
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
,
306 "required": ["kdu_name"],
308 "additionalProperties": False,
311 "affinity-or-anti-affinity-group": {
317 "vim-affinity-group-id": name_schema
,
321 "additionalProperties": False,
325 "required": ["member-vnf-index"],
327 "additionalProperties": False,
332 "title": "ns action instantiate input schema",
333 "$schema": "http://json-schema.org/draft-04/schema#",
336 "lcmOperationType": string_schema
,
337 "nsInstanceId": id_schema
,
338 "netsliceInstanceId": id_schema
,
339 "nsName": name_schema
,
340 "nsDescription": {"oneOf": [description_schema
, null_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
,
353 "vduImage": name_schema
,
360 "member-vnf-index": name_schema
,
361 "vimAccountId": id_schema
,
365 "items": ns_instantiate_vdu
,
370 "items": ns_instantiate_internal_vld
,
373 "required": ["member-vnf-index"],
375 "additionalProperties": False,
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": {
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,
403 "member-vnf-index-ref",
404 "vnfd-connection-point-ref",
407 "additionalProperties": False,
411 "required": ["name"],
412 "additionalProperties": False,
416 "required": ["nsName", "nsdId", "vimAccountId"],
417 "additionalProperties": False,
421 "title": "ns terminate input schema",
422 "$schema": "http://json-schema.org/draft-04/schema#",
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
,
432 "additionalProperties": False,
436 "title": "ns update input schema",
437 "$schema": "http://json-schema.org/draft-04/schema#",
440 "lcmOperationType": string_schema
,
441 "nsInstanceId": id_schema
,
442 "timeout_ns_update": integer1_schema
,
447 "MODIFY_VNF_INFORMATION",
451 "modifyVnfInfoData": {
454 "vnfInstanceId": id_schema
,
457 "required": ["vnfInstanceId", "vnfdId"],
459 "removeVnfInstanceId": id_schema
,
460 "changeVnfPackageData": {
463 "vnfInstanceId": id_schema
,
466 "required": ["vnfInstanceId", "vnfdId"],
471 "vnfInstanceId": id_schema
,
472 "changeStateTo": name_schema
,
476 "run-day1": bool_schema
,
477 "vdu_id": name_schema
,
478 "count-index": integer0_schema
,
480 "required": ["vdu_id", "count-index"],
481 "additionalProperties": False,
484 "required": ["vnfInstanceId", "changeStateTo"],
487 "required": ["updateType"],
488 "additionalProperties": False,
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#",
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"},
507 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
508 "additionalProperties": False,
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#",
516 "lcmOperationType": string_schema
,
517 "nsInstanceId": id_schema
,
518 "scaleType": {"enum": ["SCALE_VNF"]},
519 "timeout_ns_scale": integer1_schema
,
523 "vnfInstanceId": name_schema
,
524 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
528 "scaling-group-descriptor": name_schema
,
529 "member-vnf-index": name_schema
,
530 "scaling-policy": name_schema
,
532 "required": ["scaling-group-descriptor", "member-vnf-index"],
533 "additionalProperties": False,
536 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
537 "additionalProperties": False,
539 "scaleTime": time_schema
,
541 "required": ["scaleType", "scaleVnfData"],
542 "additionalProperties": False,
546 "title": "ns migrate input schema",
547 "$schema": "http://json-schema.org/draft-04/schema#",
550 "lcmOperationType": string_schema
,
551 "nsInstanceId": id_schema
,
552 "vnfInstanceId": id_schema
,
553 "migrateToHost": string_schema
,
557 "vduId": name_schema
,
558 "vduCountIndex": integer0_schema
,
560 "required": ["vduId"],
561 "additionalProperties": False,
564 "required": ["vnfInstanceId"],
565 "additionalProperties": False,
569 "title": "ns heal input schema",
570 "$schema": "http://json-schema.org/draft-04/schema#",
573 "lcmOperationType": string_schema
,
574 "nsInstanceId": id_schema
,
575 "timeout_ns_heal": integer1_schema
,
581 "vnfInstanceId": id_schema
,
582 "cause": description_schema
,
583 "additionalParams": {
586 "run-day1": bool_schema
,
592 "run-day1": bool_schema
,
593 "vdu-id": name_schema
,
594 "count-index": integer0_schema
,
596 "required": ["vdu-id"],
597 "additionalProperties": False,
601 "additionalProperties": False,
604 "required": ["vnfInstanceId"],
605 "additionalProperties": False,
609 "required": ["healVnfData"],
610 "additionalProperties": False,
614 "title": "vertial scale input schema",
615 "$schema": "http://json-schema.org/draft-04/schema#",
618 "lcmOperationType": string_schema
,
619 "verticalScale": string_schema
,
620 "nsInstanceId": id_schema
,
621 "changeVnfFlavorData": {
624 "vnfInstanceId": id_schema
,
625 "additionalParams": {
628 "vduid": string_schema
,
629 "vduCountIndex": integer0_schema
,
630 "virtualMemory": integer1_schema
,
631 "sizeOfStorage": integer0_schema
,
632 "numVirtualCpu": integer1_schema
,
636 "required": ["vnfInstanceId", "additionalParams"],
637 "additionalProperties": False,
640 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
641 "additionalProperties": False,
645 "title": "Cancel nslcmop input schema",
646 "$schema": "http://json-schema.org/draft-04/schema#",
649 "nsLcmOpOccId": id_schema
,
657 "required": ["cancelMode"],
658 "additionalProperties": False,
661 schema_version
= {"type": "string", "enum": ["1.0"]}
662 schema_type
= {"type": "string"}
663 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
665 vim_account_edit_schema
= {
666 "title": "vim_account edit input schema",
667 "$schema": "http://json-schema.org/draft-04/schema#",
671 "description": description_schema
,
673 "datacenter": name_schema
,
674 "vim_type": vim_type
,
675 "vim_url": description_schema
,
676 # "vim_url_admin": description_schema,
677 # "vim_tenant": name_schema,
678 "vim_tenant_name": name_schema
,
679 "vim_user": string_schema
,
680 "vim_password": passwd_schema
,
682 "config": {"type": "object"},
683 "prometheus-config": {"type": "object"},
685 "additionalProperties": False,
688 vim_account_new_schema
= {
689 "title": "vim_account creation input schema",
690 "$schema": "http://json-schema.org/draft-04/schema#",
693 "schema_version": schema_version
,
694 "schema_type": schema_type
,
696 "description": description_schema
,
698 "datacenter": name_schema
,
699 "vim_type": vim_type
,
700 "vim_url": description_schema
,
701 # "vim_url_admin": description_schema,
702 # "vim_tenant": name_schema,
703 "vim_tenant_name": name_schema
,
704 "vim_user": string_schema
,
705 "vim_password": passwd_schema
,
707 "config": {"type": "object"},
708 "prometheus-config": {"type": "object"},
718 "additionalProperties": False,
721 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
723 wim_account_edit_schema
= {
724 "title": "wim_account edit input schema",
725 "$schema": "http://json-schema.org/draft-04/schema#",
729 "description": description_schema
,
731 "wim_type": wim_type
,
732 "wim_url": description_schema
,
733 "user": string_schema
,
734 "password": passwd_schema
,
735 "config": {"type": "object"},
737 "additionalProperties": False,
740 wim_account_new_schema
= {
741 "title": "wim_account creation input schema",
742 "$schema": "http://json-schema.org/draft-04/schema#",
745 "schema_version": schema_version
,
746 "schema_type": schema_type
,
748 "description": description_schema
,
750 "wim_type": wim_type
,
751 "wim_url": description_schema
,
752 "user": string_schema
,
753 "password": passwd_schema
,
756 "patternProperties": {".": {"not": {"type": "null"}}},
759 "required": ["name", "wim_url", "wim_type"],
760 "additionalProperties": False,
765 "type": {"type": "string"},
766 "url": {"type": "string"},
767 "user": string_schema
,
768 "password": passwd_schema
,
769 "config": {"type": "object"},
770 "description": description_schema
,
771 # The folowing are deprecated. Maintanied for backward compatibility
775 "version": {"type": "string", "minLength": 1, "maxLength": 12},
778 "title": "sdn controller information schema",
779 "$schema": "http://json-schema.org/draft-04/schema#",
781 "properties": sdn_properties
,
782 "required": ["name", "type"],
783 "additionalProperties": False,
786 "title": "sdn controller update information schema",
787 "$schema": "http://json-schema.org/draft-04/schema#",
789 "properties": sdn_properties
,
790 # "required": ["name", "port", 'ip', 'dpid', 'type'],
791 "additionalProperties": False,
793 sdn_port_mapping_schema
= {
794 "$schema": "http://json-schema.org/draft-04/schema#",
795 "title": "sdn port mapping information schema",
800 "compute_node": shortname_schema
,
806 "pci": pci_extended_schema
,
807 "switch_port": shortname_schema
,
808 "switch_mac": mac_schema
,
814 "required": ["compute_node", "ports"],
817 sdn_external_port_schema
= {
818 "$schema": "http://json-schema.org/draft-04/schema#",
819 "title": "External port information",
822 "port": {"type": "string", "minLength": 1, "maxLength": 60},
826 "required": ["port"],
830 k8scluster_deploy_method_schema
= {
831 "$schema": "http://json-schema.org/draft-04/schema#",
832 "title": "Deployment methods for K8s cluster",
835 "juju-bundle": {"type": "boolean"},
836 "helm-chart-v3": {"type": "boolean"},
838 "additionalProperties": False,
841 k8scluster_nets_schema
= {
842 "title": "k8scluster nets input schema",
843 "$schema": "http://json-schema.org/draft-04/schema#",
845 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
847 "additionalProperties": False,
849 k8scluster_new_schema
= {
850 "title": "k8scluster creation input schema",
851 "$schema": "http://json-schema.org/draft-04/schema#",
854 "schema_version": schema_version
,
855 "schema_type": schema_type
,
857 "description": description_schema
,
858 "credentials": object_schema
,
859 "vim_account": id_schema
,
861 "k8s_version": string_schema
,
862 "nets": k8scluster_nets_schema
,
863 "deployment_methods": k8scluster_deploy_method_schema
,
864 "namespace": name_schema
,
865 "cni": nameshort_list_schema
,
867 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
868 "additionalProperties": False,
870 k8scluster_edit_schema
= {
871 "title": "vim_account edit input schema",
872 "$schema": "http://json-schema.org/draft-04/schema#",
876 "description": description_schema
,
877 "credentials": object_schema
,
878 "vim_account": id_schema
,
880 "k8s_version": string_schema
,
881 "nets": k8scluster_nets_schema
,
882 "namespace": name_schema
,
883 "cni": nameshort_list_schema
,
885 "additionalProperties": False,
890 "title": "vca creation input schema",
891 "$schema": "http://json-schema.org/draft-04/schema#",
894 "schema_version": schema_version
,
895 "schema_type": schema_type
,
897 "description": description_schema
,
898 "endpoints": description_list_schema
,
899 "user": string_schema
,
900 "secret": passwd_schema
,
901 "cacert": long_description_schema
,
902 "lxd-cloud": shortname_schema
,
903 "lxd-credentials": shortname_schema
,
904 "k8s-cloud": shortname_schema
,
905 "k8s-credentials": shortname_schema
,
906 "model-config": object_schema
,
919 "additionalProperties": False,
922 "title": "vca creation input schema",
923 "$schema": "http://json-schema.org/draft-04/schema#",
927 "description": description_schema
,
928 "endpoints": description_list_schema
,
929 "port": integer1_schema
,
930 "user": string_schema
,
931 "secret": passwd_schema
,
932 "cacert": long_description_schema
,
933 "lxd-cloud": shortname_schema
,
934 "lxd-credentials": shortname_schema
,
935 "k8s-cloud": shortname_schema
,
936 "k8s-credentials": shortname_schema
,
937 "model-config": object_schema
,
939 "additionalProperties": False,
943 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
944 k8srepo_properties
= {
946 "description": description_schema
,
947 "type": k8srepo_types
,
948 "url": description_schema
,
949 "cacert": long_description_schema
,
950 "user": string_schema
,
951 "password": passwd_schema
,
954 k8srepo_new_schema
= {
955 "title": "k8scluster creation input schema",
956 "$schema": "http://json-schema.org/draft-04/schema#",
958 "properties": k8srepo_properties
,
959 "required": ["name", "type", "url"],
960 "additionalProperties": False,
962 k8srepo_edit_schema
= {
963 "title": "vim_account edit input schema",
964 "$schema": "http://json-schema.org/draft-04/schema#",
966 "properties": k8srepo_properties
,
967 "additionalProperties": False,
971 osmrepo_types
= {"enum": ["osm"]}
972 osmrepo_properties
= {
974 "description": description_schema
,
975 "type": osmrepo_types
,
976 "url": description_schema
977 # "user": string_schema,
978 # "password": passwd_schema
980 osmrepo_new_schema
= {
981 "title": "osm repo creation input schema",
982 "$schema": "http://json-schema.org/draft-04/schema#",
984 "properties": osmrepo_properties
,
985 "required": ["name", "type", "url"],
986 "additionalProperties": False,
988 osmrepo_edit_schema
= {
989 "title": "osm repo edit input schema",
990 "$schema": "http://json-schema.org/draft-04/schema#",
992 "properties": osmrepo_properties
,
993 "additionalProperties": False,
1000 "name": shortname_schema
,
1001 "mgmt": bool_schema
,
1002 "type": {"enum": ["overlay", "underlay"]},
1003 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
1004 # TODO, add user, password, ssh-key
1005 "mac-address": mac_schema
,
1006 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
1007 "vim-network-id": shortname_schema
,
1008 # # provide this in case SDN assist must deal with this interface
1009 # "switch-dpid": dpid_Schema,
1010 # "switch-port": shortname_schema,
1011 # "switch-mac": shortname_schema,
1012 # "switch-vlan": vlan_schema,
1014 "required": ["name", "mgmt", "ip-address"],
1015 "additionalProperties": False,
1018 "title": "pdu creation input schema",
1019 "$schema": "http://json-schema.org/draft-04/schema#",
1022 "name": shortname_schema
,
1023 "type": shortname_schema
,
1024 "description": description_schema
,
1025 "shared": bool_schema
,
1026 "vims": nameshort_list_schema
,
1027 "vim_accounts": nameshort_list_schema
,
1028 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
1030 "required": ["name", "type", "interfaces"],
1031 "additionalProperties": False,
1034 "title": "pdu edit input schema",
1035 "$schema": "http://json-schema.org/draft-04/schema#",
1038 "name": shortname_schema
,
1039 "type": shortname_schema
,
1040 "description": description_schema
,
1041 "shared": bool_schema
,
1042 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1043 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1046 array_edition_schema
,
1047 {"type": "array", "items": pdu_interface
, "minItems": 1},
1051 "additionalProperties": False,
1055 # VNF PKG OPERATIONS
1056 vnfpkgop_new_schema
= {
1057 "title": "VNF PKG operation creation input schema",
1058 "$schema": "http://json-schema.org/draft-04/schema#",
1061 "lcmOperationType": string_schema
,
1062 "vnfPkgId": id_schema
,
1063 "kdu_name": name_schema
,
1064 "primitive": name_schema
,
1065 "primitive_params": {"type": "object"},
1074 "additionalProperties": False,
1078 project_role_mappings
= {
1079 "title": "list pf projects/roles",
1080 "$schema": "http://json-schema.org/draft-04/schema#",
1084 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1085 "required": ["project", "role"],
1086 "additionalProperties": False,
1090 project_role_mappings_optional
= {
1091 "title": "list of projects/roles or projects only",
1092 "$schema": "http://json-schema.org/draft-04/schema#",
1096 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1097 "required": ["project"],
1098 "additionalProperties": False,
1103 "$schema": "http://json-schema.org/draft-04/schema#",
1104 "title": "New user schema",
1107 "username": string_schema
,
1108 "domain_name": shortname_schema
,
1109 "password": user_passwd_schema
,
1110 "projects": nameshort_list_schema
,
1111 "project_role_mappings": project_role_mappings
,
1113 "required": ["username", "password"],
1114 "additionalProperties": False,
1116 user_edit_schema
= {
1117 "$schema": "http://json-schema.org/draft-04/schema#",
1118 "title": "User edit schema for administrators",
1121 "password": user_passwd_schema
,
1122 "old_password": passwd_schema
,
1123 "username": string_schema
, # To allow User Name modification
1124 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
1125 "project_role_mappings": project_role_mappings
,
1126 "add_project_role_mappings": project_role_mappings
,
1127 "remove_project_role_mappings": project_role_mappings_optional
,
1128 "system_admin_id": id_schema
,
1129 "unlock": bool_schema
,
1130 "renew": bool_schema
,
1133 "additionalProperties": False,
1137 topics_with_quota
= [
1153 project_new_schema
= {
1154 "$schema": "http://json-schema.org/draft-04/schema#",
1155 "title": "New project schema for administrators",
1158 "name": shortname_schema
,
1159 "admin": bool_schema
,
1160 "domain_name": shortname_schema
,
1163 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
1164 "additionalProperties": False,
1167 "required": ["name"],
1168 "additionalProperties": False,
1170 project_edit_schema
= {
1171 "$schema": "http://json-schema.org/draft-04/schema#",
1172 "title": "Project edit schema for administrators",
1175 "admin": bool_schema
,
1176 "name": shortname_schema
, # To allow Project Name modification
1180 topic
: {"oneOf": [integer0_schema
, null_schema
]}
1181 for topic
in topics_with_quota
1183 "additionalProperties": False,
1186 "additionalProperties": False,
1191 roles_new_schema
= {
1192 "$schema": "http://json-schema.org/draft-04/schema#",
1193 "title": "New role schema for administrators",
1196 "name": shortname_schema
,
1199 "patternProperties": {
1202 # "minProperties": 1,
1205 "required": ["name"],
1206 "additionalProperties": False,
1208 roles_edit_schema
= {
1209 "$schema": "http://json-schema.org/draft-04/schema#",
1210 "title": "Roles edit schema for administrators",
1213 "name": shortname_schema
,
1216 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1217 # "minProperties": 1,
1220 "additionalProperties": False,
1226 nbi_new_input_schemas
= {
1227 "users": user_new_schema
,
1228 "projects": project_new_schema
,
1229 "vim_accounts": vim_account_new_schema
,
1230 "sdns": sdn_new_schema
,
1231 "ns_instantiate": ns_instantiate
,
1232 "ns_action": ns_action
,
1233 "ns_scale": ns_scale
,
1234 "ns_update": ns_update
,
1236 "pdus": pdu_new_schema
,
1239 nbi_edit_input_schemas
= {
1240 "users": user_edit_schema
,
1241 "projects": project_edit_schema
,
1242 "vim_accounts": vim_account_edit_schema
,
1243 "sdns": sdn_edit_schema
,
1244 "pdus": pdu_edit_schema
,
1248 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1249 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1250 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1251 del nsi_subnet_instantiate
["required"]
1253 nsi_vld_instantiate
= {
1254 "title": "netslice vld instantiation params input schema",
1255 "$schema": "http://json-schema.org/draft-04/schema#",
1258 "name": string_schema
,
1259 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1260 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1261 "ip-profile": object_schema
,
1263 "required": ["name"],
1264 "additionalProperties": False,
1268 "title": "netslice action instantiate input schema",
1269 "$schema": "http://json-schema.org/draft-04/schema#",
1272 "lcmOperationType": string_schema
,
1273 "netsliceInstanceId": id_schema
,
1274 "nsiName": name_schema
,
1275 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1276 "nstId": string_schema
,
1277 "vimAccountId": id_schema
,
1278 "timeout_nsi_deploy": integer1_schema
,
1279 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1280 "nsi_id": id_schema
,
1281 "additionalParamsForNsi": object_schema
,
1282 "netslice-subnet": {
1285 "items": nsi_subnet_instantiate
,
1287 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1289 "required": ["nsiName", "nstId", "vimAccountId"],
1290 "additionalProperties": False,
1297 nsinstancesubscriptionfilter_schema
= {
1298 "title": "instance identifier schema",
1299 "$schema": "http://json-schema.org/draft-07/schema#",
1302 "nsdIds": {"type": "array"},
1303 "vnfdIds": {"type": "array"},
1304 "pnfdIds": {"type": "array"},
1305 "nsInstanceIds": {"type": "array"},
1306 "nsInstanceNames": {"type": "array"},
1311 "title": "nslcmsubscription input schema",
1312 "$schema": "http://json-schema.org/draft-07/schema#",
1315 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1316 "notificationTypes": {
1320 "NsLcmOperationOccurrenceNotification",
1321 "NsChangeNotification",
1322 "NsIdentifierCreationNotification",
1323 "NsIdentifierDeletionNotification",
1329 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1331 "operationStates": {
1337 "PARTIALLY_COMPLETED",
1345 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1346 "lcmOpNameImpactingNsComponent": {
1352 "VNF_SCALE_TO_LEVEL",
1353 "VNF_CHANGE_FLAVOUR",
1357 "VNF_CHANGE_EXT_CONN",
1367 "lcmOpOccStatusImpactingNsComponent": {
1373 "PARTIALLY_COMPLETED",
1384 "notificationTypes": {
1385 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1391 {"required": ["operationTypes"]},
1392 {"required": ["operationStates"]},
1399 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1404 {"required": ["nsComponentTypes"]},
1405 {"required": ["lcmOpNameImpactingNsComponent"]},
1406 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1413 authentication_schema
= {
1414 "title": "authentication schema for subscription",
1415 "$schema": "http://json-schema.org/draft-07/schema#",
1418 "authType": {"enum": ["basic"]},
1422 "userName": string_schema
,
1423 "password": passwd_schema
,
1430 "title": "subscription input schema",
1431 "$schema": "http://json-schema.org/draft-07/schema#",
1434 "filter": nslcmsub_schema
,
1435 "CallbackUri": description_schema
,
1436 "authentication": authentication_schema
,
1438 "required": ["CallbackUri"],
1441 vnflcmsub_schema
= {
1442 "title": "vnflcmsubscription input schema",
1443 "$schema": "http://json-schema.org/draft-07/schema#",
1446 "VnfInstanceSubscriptionFilter": {
1449 "vnfdIds": {"type": "array"},
1450 "vnfInstanceIds": {"type": "array"},
1453 "notificationTypes": {
1457 "VnfIdentifierCreationNotification",
1458 "VnfLcmOperationOccurrenceNotification",
1459 "VnfIdentifierDeletionNotification",
1477 "REVERT_TO_SNAPSHOT",
1482 "operationStates": {
1497 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1500 vnf_subscription
= {
1501 "title": "vnf subscription input schema",
1502 "$schema": "http://json-schema.org/draft-07/schema#",
1505 "filter": vnflcmsub_schema
,
1506 "CallbackUri": description_schema
,
1507 "authentication": authentication_schema
,
1509 "required": ["filter", "CallbackUri"],
1513 class ValidationError(Exception):
1514 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1515 self
.http_code
= http_code
1516 Exception.__init
__(self
, message
)
1519 def validate_input(indata
, schema_to_use
):
1521 Validates input data against json schema
1522 :param indata: user input data. Should be a dictionary
1523 :param schema_to_use: jsonschema to test
1524 :return: None if ok, raises ValidationError exception on error
1528 js_v(indata
, schema_to_use
)
1530 except js_e
.ValidationError
as e
:
1532 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1535 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1536 except js_e
.SchemaError
:
1537 raise ValidationError(
1538 "Bad json schema {}".format(schema_to_use
),
1539 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1543 def is_valid_uuid(x
):
1545 Test for a valid UUID
1546 :param x: string to test
1547 :return: True if x is a valid uuid, False otherwise
1552 except (TypeError, ValueError, AttributeError):