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}
42 "pattern": "^[^,;()'\"]+$",
44 string_schema
= {"type": "string", "minLength": 1, "maxLength": 255}
51 description_schema
= {
52 "type": ["string", "null"],
54 "pattern": "^[^'\"]+$",
56 long_description_schema
= {
57 "type": ["string", "null"],
59 "pattern": "^[^'\"]+$",
61 id_schema_fake
= {"type": "string", "minLength": 2, "maxLength": 36}
62 bool_schema
= {"type": "boolean"}
63 null_schema
= {"type": "null"}
64 # "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
67 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
71 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}",
75 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$",
77 # allows [] for wildcards. For that reason huge length limit is set
78 pci_extended_schema
= {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
79 http_schema
= {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
80 bandwidth_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
81 memory_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
82 integer0_schema
= {"type": "integer", "minimum": 0}
83 integer1_schema
= {"type": "integer", "minimum": 1}
84 path_schema
= {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
85 vlan_schema
= {"type": "integer", "minimum": 1, "maximum": 4095}
86 vlan1000_schema
= {"type": "integer", "minimum": 1000, "maximum": 4095}
89 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$",
90 } # must be unicast: LSB bit of MSB byte ==0
91 dpid_Schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
92 # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
95 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$",
99 "pattern": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))",
103 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
104 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
106 port_schema
= {"type": "integer", "minimum": 1, "maximum": 65534}
107 object_schema
= {"type": "object"}
108 schema_version_2
= {"type": "integer", "minimum": 2, "maximum": 2}
109 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
112 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
114 checksum_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
115 size_schema
= {"type": "integer", "minimum": 1, "maximum": 100}
116 array_edition_schema
= {
118 "patternProperties": {"^\\$": {}},
119 "additionalProperties": False,
122 nameshort_list_schema
= {
125 "items": shortname_schema
,
128 description_list_schema
= {
131 "items": description_schema
,
134 ns_instantiate_vdu
= {
135 "title": "ns action instantiate input schema for vdu",
136 "$schema": "http://json-schema.org/draft-04/schema#",
147 "vim-volume-id": name_schema
,
149 "required": ["name", "vim-volume-id"],
150 "additionalProperties": False,
160 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
161 "mac-address": mac_schema
,
162 "floating-ip-required": bool_schema
,
164 "required": ["name"],
165 "additionalProperties": False,
170 "additionalProperties": False,
173 ip_profile_dns_schema
= {
179 "address": {"oneOf": [ip_schema
, ipv6_schema
]},
181 "required": ["address"],
182 "additionalProperties": False,
186 ip_profile_dhcp_schema
= {
189 "enabled": {"type": "boolean"},
190 "count": integer1_schema
,
191 "start-address": ip_schema
,
193 "additionalProperties": False,
196 ip_profile_schema
= {
197 "title": "ip profile validation schema",
198 "$schema": "http://json-schema.org/draft-04/schema#",
201 "ip-version": {"enum": ["ipv4", "ipv6"]},
202 "subnet-address": ip_prefix_schema
,
203 "gateway-address": ip_schema
,
204 "dns-server": ip_profile_dns_schema
,
205 "dhcp-params": ip_profile_dhcp_schema
,
209 ip_profile_update_schema
= {
210 "title": "ip profile validation schema",
211 "$schema": "http://json-schema.org/draft-04/schema#",
214 "ip-version": {"enum": ["ipv4", "ipv6"]},
215 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
216 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
217 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
218 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
220 "additionalProperties": False,
223 provider_network_schema
= {
224 "title": "provider network validation schema",
225 "$schema": "http://json-schema.org/draft-04/schema#",
228 "physical-network": name_schema
,
229 "segmentation-id": name_schema
,
230 "sdn-ports": { # external ports to append to the SDN-assist network
235 "switch_id": shortname_schema
,
236 "switch_port": shortname_schema
,
237 "mac_address": mac_schema
,
240 "additionalProperties": True,
243 "network-type": shortname_schema
,
245 "additionalProperties": True,
248 ns_instantiate_internal_vld
= {
249 "title": "ns action instantiate input schema for vld",
250 "$schema": "http://json-schema.org/draft-04/schema#",
254 "vim-network-name": name_schema
,
255 "vim-network-id": name_schema
,
256 "ip-profile": ip_profile_update_schema
,
257 "provider-network": provider_network_schema
,
258 "internal-connection-point": {
264 "id-ref": name_schema
,
265 "ip-address": ip_schema
,
266 # "mac-address": mac_schema,
268 "required": ["id-ref"],
270 "additionalProperties": False,
274 "required": ["name"],
276 "additionalProperties": False,
279 additional_params_for_vnf
= {
284 "member-vnf-index": name_schema
,
285 "additionalParams": object_schema
,
286 "k8s-namespace": name_schema
,
287 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
288 "additionalParamsForVdu": {
293 "vdu_id": name_schema
,
294 "additionalParams": object_schema
,
295 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
297 "required": ["vdu_id"],
299 "additionalProperties": False,
302 "additionalParamsForKdu": {
307 "kdu_name": name_schema
,
308 "additionalParams": object_schema
,
309 "kdu_model": name_schema
,
310 "k8s-namespace": name_schema
,
311 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
312 "kdu-deployment-name": name_schema
,
314 "required": ["kdu_name"],
316 "additionalProperties": False,
319 "affinity-or-anti-affinity-group": {
325 "vim-affinity-group-id": name_schema
,
329 "additionalProperties": False,
333 "required": ["member-vnf-index"],
335 "additionalProperties": False,
340 "title": "ns action instantiate input schema",
341 "$schema": "http://json-schema.org/draft-04/schema#",
344 "lcmOperationType": string_schema
,
345 "nsInstanceId": id_schema
,
346 "netsliceInstanceId": id_schema
,
347 "nsName": name_schema
,
348 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
350 "vimAccountId": {"oneOf": [id_schema
, null_schema
]},
351 "paasAccountId": {"oneOf": [id_schema
, null_schema
]},
352 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
353 "placement-engine": string_schema
,
354 "placement-constraints": object_schema
,
355 "additionalParamsForNs": object_schema
,
356 "additionalParamsForVnf": additional_params_for_vnf
,
357 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
358 "k8s-namespace": name_schema
,
359 "ssh_keys": {"type": "array", "items": {"type": "string"}},
360 "timeout_ns_deploy": integer1_schema
,
362 "vduImage": name_schema
,
369 "member-vnf-index": name_schema
,
370 "vimAccountId": {"oneOf": [id_schema
, null_schema
]},
371 "paasAccountId": {"oneOf": [id_schema
, null_schema
]},
375 "items": ns_instantiate_vdu
,
380 "items": ns_instantiate_internal_vld
,
383 "required": ["member-vnf-index"],
385 "additionalProperties": False,
394 "name": string_schema
,
395 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
396 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
397 "ns-net": object_schema
,
398 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
399 "ip-profile": object_schema
,
400 "provider-network": provider_network_schema
,
401 "vnfd-connection-point-ref": {
407 "member-vnf-index-ref": name_schema
,
408 "vnfd-connection-point-ref": name_schema
,
409 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
410 # "mac-address": mac_schema,
413 "member-vnf-index-ref",
414 "vnfd-connection-point-ref",
417 "additionalProperties": False,
421 "required": ["name"],
422 "additionalProperties": False,
426 "required": ["nsName", "nsdId"],
427 "additionalProperties": False,
431 "title": "ns terminate input schema",
432 "$schema": "http://json-schema.org/draft-04/schema#",
435 "lcmOperationType": string_schema
,
436 "nsInstanceId": id_schema
,
437 "autoremove": bool_schema
,
438 "timeout_ns_terminate": integer1_schema
,
439 "skip_terminate_primitives": bool_schema
,
440 "netsliceInstanceId": id_schema
,
442 "additionalProperties": False,
446 "title": "ns update input schema",
447 "$schema": "http://json-schema.org/draft-04/schema#",
450 "lcmOperationType": string_schema
,
451 "nsInstanceId": id_schema
,
452 "timeout_ns_update": integer1_schema
,
457 "MODIFY_VNF_INFORMATION",
461 "modifyVnfInfoData": {
464 "vnfInstanceId": id_schema
,
467 "required": ["vnfInstanceId", "vnfdId"],
469 "removeVnfInstanceId": id_schema
,
470 "changeVnfPackageData": {
473 "vnfInstanceId": id_schema
,
476 "required": ["vnfInstanceId", "vnfdId"],
481 "vnfInstanceId": id_schema
,
482 "changeStateTo": name_schema
,
486 "run-day1": bool_schema
,
487 "vdu_id": name_schema
,
488 "count-index": integer0_schema
,
490 "required": ["vdu_id", "count-index"],
491 "additionalProperties": False,
494 "required": ["vnfInstanceId", "changeStateTo"],
497 "required": ["updateType"],
498 "additionalProperties": False,
501 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
502 "title": "ns action input schema",
503 "$schema": "http://json-schema.org/draft-04/schema#",
506 "lcmOperationType": string_schema
,
507 "nsInstanceId": id_schema
,
508 "member_vnf_index": name_schema
,
509 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
510 "vdu_id": name_schema
,
511 "vdu_count_index": integer0_schema
,
512 "kdu_name": name_schema
,
513 "primitive": name_schema
,
514 "timeout_ns_action": integer1_schema
,
515 "primitive_params": {"type": "object"},
517 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
518 "additionalProperties": False,
521 ns_scale
= { # TODO for the moment it is only VDU-scaling
522 "title": "ns scale input schema",
523 "$schema": "http://json-schema.org/draft-04/schema#",
526 "lcmOperationType": string_schema
,
527 "nsInstanceId": id_schema
,
528 "scaleType": {"enum": ["SCALE_VNF"]},
529 "timeout_ns_scale": integer1_schema
,
533 "vnfInstanceId": name_schema
,
534 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
538 "scaling-group-descriptor": name_schema
,
539 "member-vnf-index": name_schema
,
540 "scaling-policy": name_schema
,
542 "required": ["scaling-group-descriptor", "member-vnf-index"],
543 "additionalProperties": False,
546 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
547 "additionalProperties": False,
549 "scaleTime": time_schema
,
551 "required": ["scaleType", "scaleVnfData"],
552 "additionalProperties": False,
556 "title": "ns migrate input schema",
557 "$schema": "http://json-schema.org/draft-04/schema#",
560 "lcmOperationType": string_schema
,
561 "nsInstanceId": id_schema
,
562 "vnfInstanceId": id_schema
,
563 "migrateToHost": string_schema
,
567 "vduId": name_schema
,
568 "vduCountIndex": integer0_schema
,
570 "required": ["vduId"],
571 "additionalProperties": False,
574 "required": ["vnfInstanceId"],
575 "additionalProperties": False,
579 "title": "ns heal input schema",
580 "$schema": "http://json-schema.org/draft-04/schema#",
583 "lcmOperationType": string_schema
,
584 "nsInstanceId": id_schema
,
585 "timeout_ns_heal": integer1_schema
,
591 "vnfInstanceId": id_schema
,
592 "cause": description_schema
,
593 "additionalParams": {
596 "run-day1": bool_schema
,
602 "run-day1": bool_schema
,
603 "vdu-id": name_schema
,
604 "count-index": integer0_schema
,
606 "required": ["vdu-id"],
607 "additionalProperties": False,
611 "additionalProperties": False,
614 "required": ["vnfInstanceId"],
615 "additionalProperties": False,
619 "required": ["healVnfData"],
620 "additionalProperties": False,
624 "title": "vertial scale input schema",
625 "$schema": "http://json-schema.org/draft-04/schema#",
628 "lcmOperationType": string_schema
,
629 "verticalScale": string_schema
,
630 "nsInstanceId": id_schema
,
631 "changeVnfFlavorData": {
634 "vnfInstanceId": id_schema
,
635 "additionalParams": {
638 "vduid": string_schema
,
639 "vduCountIndex": integer0_schema
,
640 "virtualMemory": integer1_schema
,
641 "sizeOfStorage": integer0_schema
,
642 "numVirtualCpu": integer1_schema
,
646 "required": ["vnfInstanceId", "additionalParams"],
647 "additionalProperties": False,
650 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
651 "additionalProperties": False,
654 schema_version
= {"type": "string", "enum": ["1.0"]}
655 schema_type
= {"type": "string"}
656 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
658 vim_account_edit_schema
= {
659 "title": "vim_account edit input schema",
660 "$schema": "http://json-schema.org/draft-04/schema#",
664 "description": description_schema
,
666 "datacenter": name_schema
,
667 "vim_type": vim_type
,
668 "vim_url": description_schema
,
669 # "vim_url_admin": description_schema,
670 # "vim_tenant": name_schema,
671 "vim_tenant_name": name_schema
,
672 "vim_user": string_schema
,
673 "vim_password": passwd_schema
,
675 "config": {"type": "object"},
676 "prometheus-config": {"type": "object"},
678 "additionalProperties": False,
681 vim_account_new_schema
= {
682 "title": "vim_account creation input schema",
683 "$schema": "http://json-schema.org/draft-04/schema#",
686 "schema_version": schema_version
,
687 "schema_type": schema_type
,
689 "description": description_schema
,
691 "datacenter": name_schema
,
692 "vim_type": vim_type
,
693 "vim_url": description_schema
,
694 # "vim_url_admin": description_schema,
695 # "vim_tenant": name_schema,
696 "vim_tenant_name": name_schema
,
697 "vim_user": string_schema
,
698 "vim_password": passwd_schema
,
700 "config": {"type": "object"},
701 "prometheus-config": {"type": "object"},
711 "additionalProperties": False,
714 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
716 wim_account_edit_schema
= {
717 "title": "wim_account edit input schema",
718 "$schema": "http://json-schema.org/draft-04/schema#",
722 "description": description_schema
,
724 "wim_type": wim_type
,
725 "wim_url": description_schema
,
726 "user": string_schema
,
727 "password": passwd_schema
,
728 "config": {"type": "object"},
730 "additionalProperties": False,
733 wim_account_new_schema
= {
734 "title": "wim_account creation input schema",
735 "$schema": "http://json-schema.org/draft-04/schema#",
738 "schema_version": schema_version
,
739 "schema_type": schema_type
,
741 "description": description_schema
,
743 "wim_type": wim_type
,
744 "wim_url": description_schema
,
745 "user": string_schema
,
746 "password": passwd_schema
,
749 "patternProperties": {".": {"not": {"type": "null"}}},
752 "required": ["name", "wim_url", "wim_type"],
753 "additionalProperties": False,
758 "type": {"type": "string"},
759 "url": {"type": "string"},
760 "user": string_schema
,
761 "password": passwd_schema
,
762 "config": {"type": "object"},
763 "description": description_schema
,
764 # The folowing are deprecated. Maintanied for backward compatibility
768 "version": {"type": "string", "minLength": 1, "maxLength": 12},
771 "title": "sdn controller information schema",
772 "$schema": "http://json-schema.org/draft-04/schema#",
774 "properties": sdn_properties
,
775 "required": ["name", "type"],
776 "additionalProperties": False,
779 "title": "sdn controller update information schema",
780 "$schema": "http://json-schema.org/draft-04/schema#",
782 "properties": sdn_properties
,
783 # "required": ["name", "port", 'ip', 'dpid', 'type'],
784 "additionalProperties": False,
786 sdn_port_mapping_schema
= {
787 "$schema": "http://json-schema.org/draft-04/schema#",
788 "title": "sdn port mapping information schema",
793 "compute_node": shortname_schema
,
799 "pci": pci_extended_schema
,
800 "switch_port": shortname_schema
,
801 "switch_mac": mac_schema
,
807 "required": ["compute_node", "ports"],
810 sdn_external_port_schema
= {
811 "$schema": "http://json-schema.org/draft-04/schema#",
812 "title": "External port information",
815 "port": {"type": "string", "minLength": 1, "maxLength": 60},
819 "required": ["port"],
823 k8scluster_deploy_method_schema
= {
824 "$schema": "http://json-schema.org/draft-04/schema#",
825 "title": "Deployment methods for K8s cluster",
828 "helm-chart": {"type": "boolean"},
829 "juju-bundle": {"type": "boolean"},
830 "helm-chart-v3": {"type": "boolean"},
832 "additionalProperties": False,
835 k8scluster_nets_schema
= {
836 "title": "k8scluster nets input schema",
837 "$schema": "http://json-schema.org/draft-04/schema#",
839 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
841 "additionalProperties": False,
843 k8scluster_new_schema
= {
844 "title": "k8scluster creation input schema",
845 "$schema": "http://json-schema.org/draft-04/schema#",
848 "schema_version": schema_version
,
849 "schema_type": schema_type
,
851 "description": description_schema
,
852 "credentials": object_schema
,
853 "vim_account": id_schema
,
855 "k8s_version": string_schema
,
856 "nets": k8scluster_nets_schema
,
857 "deployment_methods": k8scluster_deploy_method_schema
,
858 "namespace": name_schema
,
859 "cni": nameshort_list_schema
,
861 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
862 "additionalProperties": False,
864 k8scluster_edit_schema
= {
865 "title": "vim_account edit input schema",
866 "$schema": "http://json-schema.org/draft-04/schema#",
870 "description": description_schema
,
871 "credentials": object_schema
,
872 "vim_account": id_schema
,
874 "k8s_version": string_schema
,
875 "nets": k8scluster_nets_schema
,
876 "namespace": name_schema
,
877 "cni": nameshort_list_schema
,
879 "additionalProperties": False,
884 "title": "vca creation input schema",
885 "$schema": "http://json-schema.org/draft-04/schema#",
888 "schema_version": schema_version
,
889 "schema_type": schema_type
,
891 "description": description_schema
,
892 "endpoints": description_list_schema
,
893 "user": string_schema
,
894 "secret": passwd_schema
,
895 "cacert": long_description_schema
,
896 "lxd-cloud": shortname_schema
,
897 "lxd-credentials": shortname_schema
,
898 "k8s-cloud": shortname_schema
,
899 "k8s-credentials": shortname_schema
,
900 "model-config": object_schema
,
913 "additionalProperties": False,
916 "title": "vca creation input schema",
917 "$schema": "http://json-schema.org/draft-04/schema#",
921 "description": description_schema
,
922 "endpoints": description_list_schema
,
923 "port": integer1_schema
,
924 "user": string_schema
,
925 "secret": passwd_schema
,
926 "cacert": long_description_schema
,
927 "lxd-cloud": shortname_schema
,
928 "lxd-credentials": shortname_schema
,
929 "k8s-cloud": shortname_schema
,
930 "k8s-credentials": shortname_schema
,
931 "model-config": object_schema
,
933 "additionalProperties": False,
937 paas_types
= {"enum": ["juju"]}
939 "title": "paas creation input schema",
940 "$schema": "http://json-schema.org/draft-04/schema#",
943 "schema_version": schema_version
,
944 "schema_type": schema_type
,
946 "paas_type": paas_types
,
947 "description": description_schema
,
948 "endpoints": description_list_schema
,
949 "user": string_schema
,
950 "secret": passwd_schema
,
951 "config": object_schema
,
960 "additionalProperties": False,
963 "title": "paas edition input schema",
964 "$schema": "http://json-schema.org/draft-04/schema#",
968 "paas_type": paas_types
,
969 "description": description_schema
,
970 "endpoints": description_list_schema
,
971 "user": string_schema
,
972 "secret": passwd_schema
,
973 "config": object_schema
,
975 "additionalProperties": False,
979 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
980 k8srepo_properties
= {
982 "description": description_schema
,
983 "type": k8srepo_types
,
984 "url": description_schema
,
986 k8srepo_new_schema
= {
987 "title": "k8scluster creation input schema",
988 "$schema": "http://json-schema.org/draft-04/schema#",
990 "properties": k8srepo_properties
,
991 "required": ["name", "type", "url"],
992 "additionalProperties": False,
994 k8srepo_edit_schema
= {
995 "title": "vim_account edit input schema",
996 "$schema": "http://json-schema.org/draft-04/schema#",
998 "properties": k8srepo_properties
,
999 "additionalProperties": False,
1003 osmrepo_types
= {"enum": ["osm"]}
1004 osmrepo_properties
= {
1005 "name": name_schema
,
1006 "description": description_schema
,
1007 "type": osmrepo_types
,
1008 "url": description_schema
1009 # "user": string_schema,
1010 # "password": passwd_schema
1012 osmrepo_new_schema
= {
1013 "title": "osm repo creation input schema",
1014 "$schema": "http://json-schema.org/draft-04/schema#",
1016 "properties": osmrepo_properties
,
1017 "required": ["name", "type", "url"],
1018 "additionalProperties": False,
1020 osmrepo_edit_schema
= {
1021 "title": "osm repo edit input schema",
1022 "$schema": "http://json-schema.org/draft-04/schema#",
1024 "properties": osmrepo_properties
,
1025 "additionalProperties": False,
1032 "name": shortname_schema
,
1033 "mgmt": bool_schema
,
1034 "type": {"enum": ["overlay", "underlay"]},
1035 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
1036 # TODO, add user, password, ssh-key
1037 "mac-address": mac_schema
,
1038 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
1039 "vim-network-id": shortname_schema
,
1040 # # provide this in case SDN assist must deal with this interface
1041 # "switch-dpid": dpid_Schema,
1042 # "switch-port": shortname_schema,
1043 # "switch-mac": shortname_schema,
1044 # "switch-vlan": vlan_schema,
1046 "required": ["name", "mgmt", "ip-address"],
1047 "additionalProperties": False,
1050 "title": "pdu creation input schema",
1051 "$schema": "http://json-schema.org/draft-04/schema#",
1054 "name": shortname_schema
,
1055 "type": shortname_schema
,
1056 "description": description_schema
,
1057 "shared": bool_schema
,
1058 "vims": nameshort_list_schema
,
1059 "vim_accounts": nameshort_list_schema
,
1060 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
1062 "required": ["name", "type", "interfaces"],
1063 "additionalProperties": False,
1066 "title": "pdu edit input schema",
1067 "$schema": "http://json-schema.org/draft-04/schema#",
1070 "name": shortname_schema
,
1071 "type": shortname_schema
,
1072 "description": description_schema
,
1073 "shared": bool_schema
,
1074 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1075 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1078 array_edition_schema
,
1079 {"type": "array", "items": pdu_interface
, "minItems": 1},
1083 "additionalProperties": False,
1087 # VNF PKG OPERATIONS
1088 vnfpkgop_new_schema
= {
1089 "title": "VNF PKG operation creation input schema",
1090 "$schema": "http://json-schema.org/draft-04/schema#",
1093 "lcmOperationType": string_schema
,
1094 "vnfPkgId": id_schema
,
1095 "kdu_name": name_schema
,
1096 "primitive": name_schema
,
1097 "primitive_params": {"type": "object"},
1106 "additionalProperties": False,
1110 project_role_mappings
= {
1111 "title": "list pf projects/roles",
1112 "$schema": "http://json-schema.org/draft-04/schema#",
1116 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1117 "required": ["project", "role"],
1118 "additionalProperties": False,
1122 project_role_mappings_optional
= {
1123 "title": "list of projects/roles or projects only",
1124 "$schema": "http://json-schema.org/draft-04/schema#",
1128 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1129 "required": ["project"],
1130 "additionalProperties": False,
1135 "$schema": "http://json-schema.org/draft-04/schema#",
1136 "title": "New user schema",
1139 "username": string_schema
,
1140 "domain_name": shortname_schema
,
1141 "password": passwd_schema
,
1142 "projects": nameshort_list_schema
,
1143 "project_role_mappings": project_role_mappings
,
1145 "required": ["username", "password"],
1146 "additionalProperties": False,
1148 user_edit_schema
= {
1149 "$schema": "http://json-schema.org/draft-04/schema#",
1150 "title": "User edit schema for administrators",
1153 "password": passwd_schema
,
1154 "old_password": passwd_schema
,
1155 "username": string_schema
, # To allow User Name modification
1156 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
1157 "project_role_mappings": project_role_mappings
,
1158 "add_project_role_mappings": project_role_mappings
,
1159 "remove_project_role_mappings": project_role_mappings_optional
,
1162 "additionalProperties": False,
1166 topics_with_quota
= [
1183 project_new_schema
= {
1184 "$schema": "http://json-schema.org/draft-04/schema#",
1185 "title": "New project schema for administrators",
1188 "name": shortname_schema
,
1189 "admin": bool_schema
,
1190 "domain_name": shortname_schema
,
1193 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
1194 "additionalProperties": False,
1197 "required": ["name"],
1198 "additionalProperties": False,
1200 project_edit_schema
= {
1201 "$schema": "http://json-schema.org/draft-04/schema#",
1202 "title": "Project edit schema for administrators",
1205 "admin": bool_schema
,
1206 "name": shortname_schema
, # To allow Project Name modification
1210 topic
: {"oneOf": [integer0_schema
, null_schema
]}
1211 for topic
in topics_with_quota
1213 "additionalProperties": False,
1216 "additionalProperties": False,
1221 roles_new_schema
= {
1222 "$schema": "http://json-schema.org/draft-04/schema#",
1223 "title": "New role schema for administrators",
1226 "name": shortname_schema
,
1229 "patternProperties": {
1232 # "minProperties": 1,
1235 "required": ["name"],
1236 "additionalProperties": False,
1238 roles_edit_schema
= {
1239 "$schema": "http://json-schema.org/draft-04/schema#",
1240 "title": "Roles edit schema for administrators",
1243 "name": shortname_schema
,
1246 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1247 # "minProperties": 1,
1250 "additionalProperties": False,
1256 nbi_new_input_schemas
= {
1257 "users": user_new_schema
,
1258 "projects": project_new_schema
,
1259 "vim_accounts": vim_account_new_schema
,
1260 "sdns": sdn_new_schema
,
1261 "ns_instantiate": ns_instantiate
,
1262 "ns_action": ns_action
,
1263 "ns_scale": ns_scale
,
1264 "ns_update": ns_update
,
1266 "pdus": pdu_new_schema
,
1269 nbi_edit_input_schemas
= {
1270 "users": user_edit_schema
,
1271 "projects": project_edit_schema
,
1272 "vim_accounts": vim_account_edit_schema
,
1273 "sdns": sdn_edit_schema
,
1274 "pdus": pdu_edit_schema
,
1278 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1279 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1280 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1281 del nsi_subnet_instantiate
["required"]
1283 nsi_vld_instantiate
= {
1284 "title": "netslice vld instantiation params input schema",
1285 "$schema": "http://json-schema.org/draft-04/schema#",
1288 "name": string_schema
,
1289 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1290 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1291 "ip-profile": object_schema
,
1293 "required": ["name"],
1294 "additionalProperties": False,
1298 "title": "netslice action instantiate input schema",
1299 "$schema": "http://json-schema.org/draft-04/schema#",
1302 "lcmOperationType": string_schema
,
1303 "netsliceInstanceId": id_schema
,
1304 "nsiName": name_schema
,
1305 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1306 "nstId": string_schema
,
1307 "vimAccountId": id_schema
,
1308 "timeout_nsi_deploy": integer1_schema
,
1309 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1310 "nsi_id": id_schema
,
1311 "additionalParamsForNsi": object_schema
,
1312 "netslice-subnet": {
1315 "items": nsi_subnet_instantiate
,
1317 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1319 "required": ["nsiName", "nstId", "vimAccountId"],
1320 "additionalProperties": False,
1327 nsinstancesubscriptionfilter_schema
= {
1328 "title": "instance identifier schema",
1329 "$schema": "http://json-schema.org/draft-07/schema#",
1332 "nsdIds": {"type": "array"},
1333 "vnfdIds": {"type": "array"},
1334 "pnfdIds": {"type": "array"},
1335 "nsInstanceIds": {"type": "array"},
1336 "nsInstanceNames": {"type": "array"},
1341 "title": "nslcmsubscription input schema",
1342 "$schema": "http://json-schema.org/draft-07/schema#",
1345 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1346 "notificationTypes": {
1350 "NsLcmOperationOccurrenceNotification",
1351 "NsChangeNotification",
1352 "NsIdentifierCreationNotification",
1353 "NsIdentifierDeletionNotification",
1359 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1361 "operationStates": {
1367 "PARTIALLY_COMPLETED",
1375 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1376 "lcmOpNameImpactingNsComponent": {
1382 "VNF_SCALE_TO_LEVEL",
1383 "VNF_CHANGE_FLAVOUR",
1387 "VNF_CHANGE_EXT_CONN",
1397 "lcmOpOccStatusImpactingNsComponent": {
1403 "PARTIALLY_COMPLETED",
1414 "notificationTypes": {
1415 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1421 {"required": ["operationTypes"]},
1422 {"required": ["operationStates"]},
1429 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1434 {"required": ["nsComponentTypes"]},
1435 {"required": ["lcmOpNameImpactingNsComponent"]},
1436 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1443 authentication_schema
= {
1444 "title": "authentication schema for subscription",
1445 "$schema": "http://json-schema.org/draft-07/schema#",
1448 "authType": {"enum": ["basic"]},
1452 "userName": string_schema
,
1453 "password": passwd_schema
,
1460 "title": "subscription input schema",
1461 "$schema": "http://json-schema.org/draft-07/schema#",
1464 "filter": nslcmsub_schema
,
1465 "CallbackUri": description_schema
,
1466 "authentication": authentication_schema
,
1468 "required": ["CallbackUri"],
1471 vnflcmsub_schema
= {
1472 "title": "vnflcmsubscription input schema",
1473 "$schema": "http://json-schema.org/draft-07/schema#",
1476 "VnfInstanceSubscriptionFilter": {
1479 "vnfdIds": {"type": "array"},
1480 "vnfInstanceIds": {"type": "array"},
1483 "notificationTypes": {
1487 "VnfIdentifierCreationNotification",
1488 "VnfLcmOperationOccurrenceNotification",
1489 "VnfIdentifierDeletionNotification",
1507 "REVERT_TO_SNAPSHOT",
1512 "operationStates": {
1527 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1530 vnf_subscription
= {
1531 "title": "vnf subscription input schema",
1532 "$schema": "http://json-schema.org/draft-07/schema#",
1535 "filter": vnflcmsub_schema
,
1536 "CallbackUri": description_schema
,
1537 "authentication": authentication_schema
,
1539 "required": ["filter", "CallbackUri"],
1543 class ValidationError(Exception):
1544 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1545 self
.http_code
= http_code
1546 Exception.__init
__(self
, message
)
1549 def validate_input(indata
, schema_to_use
):
1551 Validates input data against json schema
1552 :param indata: user input data. Should be a dictionary
1553 :param schema_to_use: jsonschema to test
1554 :return: None if ok, raises ValidationError exception on error
1558 js_v(indata
, schema_to_use
)
1560 except js_e
.ValidationError
as e
:
1562 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1565 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1566 except js_e
.SchemaError
:
1567 raise ValidationError(
1568 "Bad json schema {}".format(schema_to_use
),
1569 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1573 def is_valid_uuid(x
):
1575 Test for a valid UUID
1576 :param x: string to test
1577 :return: True if x is a valid uuid, False otherwise
1582 except (TypeError, ValueError, AttributeError):