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,
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"]}
648 vim_account_edit_schema
= {
649 "title": "vim_account edit input schema",
650 "$schema": "http://json-schema.org/draft-04/schema#",
654 "description": description_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
,
665 "config": {"type": "object"},
666 "prometheus-config": {"type": "object"},
668 "additionalProperties": False,
671 vim_account_new_schema
= {
672 "title": "vim_account creation input schema",
673 "$schema": "http://json-schema.org/draft-04/schema#",
676 "schema_version": schema_version
,
677 "schema_type": schema_type
,
679 "description": description_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
,
690 "config": {"type": "object"},
691 "prometheus-config": {"type": "object"},
701 "additionalProperties": False,
704 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
706 wim_account_edit_schema
= {
707 "title": "wim_account edit input schema",
708 "$schema": "http://json-schema.org/draft-04/schema#",
712 "description": description_schema
,
714 "wim_type": wim_type
,
715 "wim_url": description_schema
,
716 "user": string_schema
,
717 "password": passwd_schema
,
718 "config": {"type": "object"},
720 "additionalProperties": False,
723 wim_account_new_schema
= {
724 "title": "wim_account creation input schema",
725 "$schema": "http://json-schema.org/draft-04/schema#",
728 "schema_version": schema_version
,
729 "schema_type": schema_type
,
731 "description": description_schema
,
733 "wim_type": wim_type
,
734 "wim_url": description_schema
,
735 "user": string_schema
,
736 "password": passwd_schema
,
739 "patternProperties": {".": {"not": {"type": "null"}}},
742 "required": ["name", "wim_url", "wim_type"],
743 "additionalProperties": False,
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
758 "version": {"type": "string", "minLength": 1, "maxLength": 12},
761 "title": "sdn controller information schema",
762 "$schema": "http://json-schema.org/draft-04/schema#",
764 "properties": sdn_properties
,
765 "required": ["name", "type"],
766 "additionalProperties": False,
769 "title": "sdn controller update information schema",
770 "$schema": "http://json-schema.org/draft-04/schema#",
772 "properties": sdn_properties
,
773 # "required": ["name", "port", 'ip', 'dpid', 'type'],
774 "additionalProperties": False,
776 sdn_port_mapping_schema
= {
777 "$schema": "http://json-schema.org/draft-04/schema#",
778 "title": "sdn port mapping information schema",
783 "compute_node": shortname_schema
,
789 "pci": pci_extended_schema
,
790 "switch_port": shortname_schema
,
791 "switch_mac": mac_schema
,
797 "required": ["compute_node", "ports"],
800 sdn_external_port_schema
= {
801 "$schema": "http://json-schema.org/draft-04/schema#",
802 "title": "External port information",
805 "port": {"type": "string", "minLength": 1, "maxLength": 60},
809 "required": ["port"],
813 k8scluster_deploy_method_schema
= {
814 "$schema": "http://json-schema.org/draft-04/schema#",
815 "title": "Deployment methods for K8s cluster",
818 "helm-chart": {"type": "boolean"},
819 "juju-bundle": {"type": "boolean"},
820 "helm-chart-v3": {"type": "boolean"},
822 "additionalProperties": False,
825 k8scluster_nets_schema
= {
826 "title": "k8scluster nets input schema",
827 "$schema": "http://json-schema.org/draft-04/schema#",
829 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
831 "additionalProperties": False,
833 k8scluster_new_schema
= {
834 "title": "k8scluster creation input schema",
835 "$schema": "http://json-schema.org/draft-04/schema#",
838 "schema_version": schema_version
,
839 "schema_type": schema_type
,
841 "description": description_schema
,
842 "credentials": object_schema
,
843 "vim_account": id_schema
,
845 "k8s_version": string_schema
,
846 "nets": k8scluster_nets_schema
,
847 "deployment_methods": k8scluster_deploy_method_schema
,
848 "namespace": name_schema
,
849 "cni": nameshort_list_schema
,
851 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
852 "additionalProperties": False,
854 k8scluster_edit_schema
= {
855 "title": "vim_account edit input schema",
856 "$schema": "http://json-schema.org/draft-04/schema#",
860 "description": description_schema
,
861 "credentials": object_schema
,
862 "vim_account": id_schema
,
864 "k8s_version": string_schema
,
865 "nets": k8scluster_nets_schema
,
866 "namespace": name_schema
,
867 "cni": nameshort_list_schema
,
869 "additionalProperties": False,
874 "title": "vca creation input schema",
875 "$schema": "http://json-schema.org/draft-04/schema#",
878 "schema_version": schema_version
,
879 "schema_type": schema_type
,
881 "description": description_schema
,
882 "endpoints": description_list_schema
,
883 "user": string_schema
,
884 "secret": passwd_schema
,
885 "cacert": long_description_schema
,
886 "lxd-cloud": shortname_schema
,
887 "lxd-credentials": shortname_schema
,
888 "k8s-cloud": shortname_schema
,
889 "k8s-credentials": shortname_schema
,
890 "model-config": object_schema
,
903 "additionalProperties": False,
906 "title": "vca creation input schema",
907 "$schema": "http://json-schema.org/draft-04/schema#",
911 "description": description_schema
,
912 "endpoints": description_list_schema
,
913 "port": integer1_schema
,
914 "user": string_schema
,
915 "secret": passwd_schema
,
916 "cacert": long_description_schema
,
917 "lxd-cloud": shortname_schema
,
918 "lxd-credentials": shortname_schema
,
919 "k8s-cloud": shortname_schema
,
920 "k8s-credentials": shortname_schema
,
921 "model-config": object_schema
,
923 "additionalProperties": False,
927 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
928 k8srepo_properties
= {
930 "description": description_schema
,
931 "type": k8srepo_types
,
932 "url": description_schema
,
933 "cacert": long_description_schema
,
934 "user": string_schema
,
935 "password": passwd_schema
,
937 k8srepo_new_schema
= {
938 "title": "k8scluster creation input schema",
939 "$schema": "http://json-schema.org/draft-04/schema#",
941 "properties": k8srepo_properties
,
942 "required": ["name", "type", "url"],
943 "additionalProperties": False,
945 k8srepo_edit_schema
= {
946 "title": "vim_account edit input schema",
947 "$schema": "http://json-schema.org/draft-04/schema#",
949 "properties": k8srepo_properties
,
950 "additionalProperties": False,
954 osmrepo_types
= {"enum": ["osm"]}
955 osmrepo_properties
= {
957 "description": description_schema
,
958 "type": osmrepo_types
,
959 "url": description_schema
960 # "user": string_schema,
961 # "password": passwd_schema
963 osmrepo_new_schema
= {
964 "title": "osm repo creation input schema",
965 "$schema": "http://json-schema.org/draft-04/schema#",
967 "properties": osmrepo_properties
,
968 "required": ["name", "type", "url"],
969 "additionalProperties": False,
971 osmrepo_edit_schema
= {
972 "title": "osm repo edit input schema",
973 "$schema": "http://json-schema.org/draft-04/schema#",
975 "properties": osmrepo_properties
,
976 "additionalProperties": False,
983 "name": shortname_schema
,
985 "type": {"enum": ["overlay", "underlay"]},
986 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
987 # TODO, add user, password, ssh-key
988 "mac-address": mac_schema
,
989 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
990 "vim-network-id": shortname_schema
,
991 # # provide this in case SDN assist must deal with this interface
992 # "switch-dpid": dpid_Schema,
993 # "switch-port": shortname_schema,
994 # "switch-mac": shortname_schema,
995 # "switch-vlan": vlan_schema,
997 "required": ["name", "mgmt", "ip-address"],
998 "additionalProperties": False,
1001 "title": "pdu creation input schema",
1002 "$schema": "http://json-schema.org/draft-04/schema#",
1005 "name": shortname_schema
,
1006 "type": shortname_schema
,
1007 "description": description_schema
,
1008 "shared": bool_schema
,
1009 "vims": nameshort_list_schema
,
1010 "vim_accounts": nameshort_list_schema
,
1011 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
1013 "required": ["name", "type", "interfaces"],
1014 "additionalProperties": False,
1017 "title": "pdu edit input schema",
1018 "$schema": "http://json-schema.org/draft-04/schema#",
1021 "name": shortname_schema
,
1022 "type": shortname_schema
,
1023 "description": description_schema
,
1024 "shared": bool_schema
,
1025 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1026 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1029 array_edition_schema
,
1030 {"type": "array", "items": pdu_interface
, "minItems": 1},
1034 "additionalProperties": False,
1038 # VNF PKG OPERATIONS
1039 vnfpkgop_new_schema
= {
1040 "title": "VNF PKG operation creation input schema",
1041 "$schema": "http://json-schema.org/draft-04/schema#",
1044 "lcmOperationType": string_schema
,
1045 "vnfPkgId": id_schema
,
1046 "kdu_name": name_schema
,
1047 "primitive": name_schema
,
1048 "primitive_params": {"type": "object"},
1057 "additionalProperties": False,
1061 project_role_mappings
= {
1062 "title": "list pf projects/roles",
1063 "$schema": "http://json-schema.org/draft-04/schema#",
1067 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1068 "required": ["project", "role"],
1069 "additionalProperties": False,
1073 project_role_mappings_optional
= {
1074 "title": "list of projects/roles or projects only",
1075 "$schema": "http://json-schema.org/draft-04/schema#",
1079 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1080 "required": ["project"],
1081 "additionalProperties": False,
1086 "$schema": "http://json-schema.org/draft-04/schema#",
1087 "title": "New user schema",
1090 "username": string_schema
,
1091 "domain_name": shortname_schema
,
1092 "password": user_passwd_schema
,
1093 "projects": nameshort_list_schema
,
1094 "project_role_mappings": project_role_mappings
,
1096 "required": ["username", "password"],
1097 "additionalProperties": False,
1099 user_edit_schema
= {
1100 "$schema": "http://json-schema.org/draft-04/schema#",
1101 "title": "User edit schema for administrators",
1104 "password": user_passwd_schema
,
1105 "old_password": passwd_schema
,
1106 "username": string_schema
, # To allow User Name modification
1107 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
1108 "project_role_mappings": project_role_mappings
,
1109 "add_project_role_mappings": project_role_mappings
,
1110 "remove_project_role_mappings": project_role_mappings_optional
,
1111 "system_admin_id": id_schema
,
1112 "unlock": bool_schema
,
1113 "renew": bool_schema
,
1116 "additionalProperties": False,
1120 topics_with_quota
= [
1136 project_new_schema
= {
1137 "$schema": "http://json-schema.org/draft-04/schema#",
1138 "title": "New project schema for administrators",
1141 "name": shortname_schema
,
1142 "admin": bool_schema
,
1143 "domain_name": shortname_schema
,
1146 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
1147 "additionalProperties": False,
1150 "required": ["name"],
1151 "additionalProperties": False,
1153 project_edit_schema
= {
1154 "$schema": "http://json-schema.org/draft-04/schema#",
1155 "title": "Project edit schema for administrators",
1158 "admin": bool_schema
,
1159 "name": shortname_schema
, # To allow Project Name modification
1163 topic
: {"oneOf": [integer0_schema
, null_schema
]}
1164 for topic
in topics_with_quota
1166 "additionalProperties": False,
1169 "additionalProperties": False,
1174 roles_new_schema
= {
1175 "$schema": "http://json-schema.org/draft-04/schema#",
1176 "title": "New role schema for administrators",
1179 "name": shortname_schema
,
1182 "patternProperties": {
1185 # "minProperties": 1,
1188 "required": ["name"],
1189 "additionalProperties": False,
1191 roles_edit_schema
= {
1192 "$schema": "http://json-schema.org/draft-04/schema#",
1193 "title": "Roles edit schema for administrators",
1196 "name": shortname_schema
,
1199 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1200 # "minProperties": 1,
1203 "additionalProperties": False,
1209 nbi_new_input_schemas
= {
1210 "users": user_new_schema
,
1211 "projects": project_new_schema
,
1212 "vim_accounts": vim_account_new_schema
,
1213 "sdns": sdn_new_schema
,
1214 "ns_instantiate": ns_instantiate
,
1215 "ns_action": ns_action
,
1216 "ns_scale": ns_scale
,
1217 "ns_update": ns_update
,
1219 "pdus": pdu_new_schema
,
1222 nbi_edit_input_schemas
= {
1223 "users": user_edit_schema
,
1224 "projects": project_edit_schema
,
1225 "vim_accounts": vim_account_edit_schema
,
1226 "sdns": sdn_edit_schema
,
1227 "pdus": pdu_edit_schema
,
1231 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1232 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1233 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1234 del nsi_subnet_instantiate
["required"]
1236 nsi_vld_instantiate
= {
1237 "title": "netslice vld instantiation params input schema",
1238 "$schema": "http://json-schema.org/draft-04/schema#",
1241 "name": string_schema
,
1242 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1243 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1244 "ip-profile": object_schema
,
1246 "required": ["name"],
1247 "additionalProperties": False,
1251 "title": "netslice action instantiate input schema",
1252 "$schema": "http://json-schema.org/draft-04/schema#",
1255 "lcmOperationType": string_schema
,
1256 "netsliceInstanceId": id_schema
,
1257 "nsiName": name_schema
,
1258 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1259 "nstId": string_schema
,
1260 "vimAccountId": id_schema
,
1261 "timeout_nsi_deploy": integer1_schema
,
1262 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1263 "nsi_id": id_schema
,
1264 "additionalParamsForNsi": object_schema
,
1265 "netslice-subnet": {
1268 "items": nsi_subnet_instantiate
,
1270 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1272 "required": ["nsiName", "nstId", "vimAccountId"],
1273 "additionalProperties": False,
1280 nsinstancesubscriptionfilter_schema
= {
1281 "title": "instance identifier schema",
1282 "$schema": "http://json-schema.org/draft-07/schema#",
1285 "nsdIds": {"type": "array"},
1286 "vnfdIds": {"type": "array"},
1287 "pnfdIds": {"type": "array"},
1288 "nsInstanceIds": {"type": "array"},
1289 "nsInstanceNames": {"type": "array"},
1294 "title": "nslcmsubscription input schema",
1295 "$schema": "http://json-schema.org/draft-07/schema#",
1298 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1299 "notificationTypes": {
1303 "NsLcmOperationOccurrenceNotification",
1304 "NsChangeNotification",
1305 "NsIdentifierCreationNotification",
1306 "NsIdentifierDeletionNotification",
1312 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1314 "operationStates": {
1320 "PARTIALLY_COMPLETED",
1328 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1329 "lcmOpNameImpactingNsComponent": {
1335 "VNF_SCALE_TO_LEVEL",
1336 "VNF_CHANGE_FLAVOUR",
1340 "VNF_CHANGE_EXT_CONN",
1350 "lcmOpOccStatusImpactingNsComponent": {
1356 "PARTIALLY_COMPLETED",
1367 "notificationTypes": {
1368 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1374 {"required": ["operationTypes"]},
1375 {"required": ["operationStates"]},
1382 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1387 {"required": ["nsComponentTypes"]},
1388 {"required": ["lcmOpNameImpactingNsComponent"]},
1389 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1396 authentication_schema
= {
1397 "title": "authentication schema for subscription",
1398 "$schema": "http://json-schema.org/draft-07/schema#",
1401 "authType": {"enum": ["basic"]},
1405 "userName": string_schema
,
1406 "password": passwd_schema
,
1413 "title": "subscription input schema",
1414 "$schema": "http://json-schema.org/draft-07/schema#",
1417 "filter": nslcmsub_schema
,
1418 "CallbackUri": description_schema
,
1419 "authentication": authentication_schema
,
1421 "required": ["CallbackUri"],
1424 vnflcmsub_schema
= {
1425 "title": "vnflcmsubscription input schema",
1426 "$schema": "http://json-schema.org/draft-07/schema#",
1429 "VnfInstanceSubscriptionFilter": {
1432 "vnfdIds": {"type": "array"},
1433 "vnfInstanceIds": {"type": "array"},
1436 "notificationTypes": {
1440 "VnfIdentifierCreationNotification",
1441 "VnfLcmOperationOccurrenceNotification",
1442 "VnfIdentifierDeletionNotification",
1460 "REVERT_TO_SNAPSHOT",
1465 "operationStates": {
1480 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1483 vnf_subscription
= {
1484 "title": "vnf subscription input schema",
1485 "$schema": "http://json-schema.org/draft-07/schema#",
1488 "filter": vnflcmsub_schema
,
1489 "CallbackUri": description_schema
,
1490 "authentication": authentication_schema
,
1492 "required": ["filter", "CallbackUri"],
1496 class ValidationError(Exception):
1497 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1498 self
.http_code
= http_code
1499 Exception.__init
__(self
, message
)
1502 def validate_input(indata
, schema_to_use
):
1504 Validates input data against json schema
1505 :param indata: user input data. Should be a dictionary
1506 :param schema_to_use: jsonschema to test
1507 :return: None if ok, raises ValidationError exception on error
1511 js_v(indata
, schema_to_use
)
1513 except js_e
.ValidationError
as e
:
1515 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1518 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1519 except js_e
.SchemaError
:
1520 raise ValidationError(
1521 "Bad json schema {}".format(schema_to_use
),
1522 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1526 def is_valid_uuid(x
):
1528 Test for a valid UUID
1529 :param x: string to test
1530 :return: True if x is a valid uuid, False otherwise
1535 except (TypeError, ValueError, AttributeError):