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": id_schema
,
351 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
352 "placement-engine": string_schema
,
353 "placement-constraints": object_schema
,
354 "additionalParamsForNs": object_schema
,
355 "additionalParamsForVnf": additional_params_for_vnf
,
356 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
357 "k8s-namespace": name_schema
,
358 "ssh_keys": {"type": "array", "items": {"type": "string"}},
359 "timeout_ns_deploy": integer1_schema
,
361 "vduImage": name_schema
,
368 "member-vnf-index": name_schema
,
369 "vimAccountId": id_schema
,
373 "items": ns_instantiate_vdu
,
378 "items": ns_instantiate_internal_vld
,
381 "required": ["member-vnf-index"],
383 "additionalProperties": False,
392 "name": string_schema
,
393 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
394 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
395 "ns-net": object_schema
,
396 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
397 "ip-profile": object_schema
,
398 "provider-network": provider_network_schema
,
399 "vnfd-connection-point-ref": {
405 "member-vnf-index-ref": name_schema
,
406 "vnfd-connection-point-ref": name_schema
,
407 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
408 # "mac-address": mac_schema,
411 "member-vnf-index-ref",
412 "vnfd-connection-point-ref",
415 "additionalProperties": False,
419 "required": ["name"],
420 "additionalProperties": False,
424 "required": ["nsName", "nsdId", "vimAccountId"],
425 "additionalProperties": False,
429 "title": "ns terminate input schema",
430 "$schema": "http://json-schema.org/draft-04/schema#",
433 "lcmOperationType": string_schema
,
434 "nsInstanceId": id_schema
,
435 "autoremove": bool_schema
,
436 "timeout_ns_terminate": integer1_schema
,
437 "skip_terminate_primitives": bool_schema
,
438 "netsliceInstanceId": id_schema
,
440 "additionalProperties": False,
444 "title": "ns update input schema",
445 "$schema": "http://json-schema.org/draft-04/schema#",
448 "lcmOperationType": string_schema
,
449 "nsInstanceId": id_schema
,
450 "timeout_ns_update": integer1_schema
,
452 "enum": ["CHANGE_VNFPKG", "REMOVE_VNF", "MODIFY_VNF_INFORMATION", "OPERATE_VNF"]
454 "modifyVnfInfoData": {
457 "vnfInstanceId": id_schema
,
460 "required": ["vnfInstanceId", "vnfdId"],
462 "removeVnfInstanceId": id_schema
,
463 "changeVnfPackageData": {
466 "vnfInstanceId": id_schema
,
469 "required": ["vnfInstanceId", "vnfdId"],
474 "vnfInstanceId": id_schema
,
475 "changeStateTo": name_schema
,
479 "run-day1": bool_schema
,
480 "vdu_id": name_schema
,
481 "count-index": integer0_schema
,
483 "required": ["vdu_id", "count-index"],
484 "additionalProperties": False,
487 "required": ["vnfInstanceId", "changeStateTo"],
490 "required": ["updateType"],
491 "additionalProperties": False,
494 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
495 "title": "ns action input schema",
496 "$schema": "http://json-schema.org/draft-04/schema#",
499 "lcmOperationType": string_schema
,
500 "nsInstanceId": id_schema
,
501 "member_vnf_index": name_schema
,
502 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
503 "vdu_id": name_schema
,
504 "vdu_count_index": integer0_schema
,
505 "kdu_name": name_schema
,
506 "primitive": name_schema
,
507 "timeout_ns_action": integer1_schema
,
508 "primitive_params": {"type": "object"},
510 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
511 "additionalProperties": False,
514 ns_scale
= { # TODO for the moment it is only VDU-scaling
515 "title": "ns scale input schema",
516 "$schema": "http://json-schema.org/draft-04/schema#",
519 "lcmOperationType": string_schema
,
520 "nsInstanceId": id_schema
,
521 "scaleType": {"enum": ["SCALE_VNF"]},
522 "timeout_ns_scale": integer1_schema
,
526 "vnfInstanceId": name_schema
,
527 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
531 "scaling-group-descriptor": name_schema
,
532 "member-vnf-index": name_schema
,
533 "scaling-policy": name_schema
,
535 "required": ["scaling-group-descriptor", "member-vnf-index"],
536 "additionalProperties": False,
539 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
540 "additionalProperties": False,
542 "scaleTime": time_schema
,
544 "required": ["scaleType", "scaleVnfData"],
545 "additionalProperties": False,
549 "title": "ns migrate input schema",
550 "$schema": "http://json-schema.org/draft-04/schema#",
553 "lcmOperationType": string_schema
,
554 "nsInstanceId": id_schema
,
555 "vnfInstanceId": id_schema
,
556 "migrateToHost": string_schema
,
560 "vduId": name_schema
,
561 "vduCountIndex": integer0_schema
,
563 "required": ["vduId"],
564 "additionalProperties": False,
567 "required": ["vnfInstanceId"],
568 "additionalProperties": False
572 "title": "ns heal input schema",
573 "$schema": "http://json-schema.org/draft-04/schema#",
576 "lcmOperationType": string_schema
,
577 "nsInstanceId": id_schema
,
578 "timeout_ns_heal": integer1_schema
,
584 "vnfInstanceId": id_schema
,
585 "cause": description_schema
,
586 "additionalParams": {
589 "run-day1": bool_schema
,
595 "run-day1": bool_schema
,
596 "vdu-id": name_schema
,
597 "count-index": integer0_schema
,
599 "required": ["vdu-id"],
600 "additionalProperties": False,
604 "additionalProperties": False,
607 "required": ["vnfInstanceId"],
608 "additionalProperties": False,
612 "required": ["healVnfData"],
613 "additionalProperties": False,
617 "title": "vertial scale input schema",
618 "$schema": "http://json-schema.org/draft-04/schema#",
621 "lcmOperationType": string_schema
,
622 "verticalScale": string_schema
,
623 "nsInstanceId": id_schema
,
624 "changeVnfFlavorData": {
627 "vnfInstanceId": id_schema
,
628 "additionalParams": {
631 "vduid": string_schema
,
632 "vduCountIndex": integer0_schema
,
633 "virtualMemory": integer1_schema
,
634 "sizeOfStorage": integer0_schema
,
635 "numVirtualCpu": integer1_schema
,
639 "required": ["vnfInstanceId", "additionalParams"],
640 "additionalProperties": False,
643 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
644 "additionalProperties": False,
647 schema_version
= {"type": "string", "enum": ["1.0"]}
648 schema_type
= {"type": "string"}
649 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
651 vim_account_edit_schema
= {
652 "title": "vim_account edit input schema",
653 "$schema": "http://json-schema.org/draft-04/schema#",
657 "description": description_schema
,
659 "datacenter": name_schema
,
660 "vim_type": vim_type
,
661 "vim_url": description_schema
,
662 # "vim_url_admin": description_schema,
663 # "vim_tenant": name_schema,
664 "vim_tenant_name": name_schema
,
665 "vim_user": string_schema
,
666 "vim_password": passwd_schema
,
668 "config": {"type": "object"},
669 "prometheus-config": {"type": "object"},
671 "additionalProperties": False,
674 vim_account_new_schema
= {
675 "title": "vim_account creation input schema",
676 "$schema": "http://json-schema.org/draft-04/schema#",
679 "schema_version": schema_version
,
680 "schema_type": schema_type
,
682 "description": description_schema
,
684 "datacenter": name_schema
,
685 "vim_type": vim_type
,
686 "vim_url": description_schema
,
687 # "vim_url_admin": description_schema,
688 # "vim_tenant": name_schema,
689 "vim_tenant_name": name_schema
,
690 "vim_user": string_schema
,
691 "vim_password": passwd_schema
,
693 "config": {"type": "object"},
694 "prometheus-config": {"type": "object"},
704 "additionalProperties": False,
707 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
709 wim_account_edit_schema
= {
710 "title": "wim_account edit input schema",
711 "$schema": "http://json-schema.org/draft-04/schema#",
715 "description": description_schema
,
717 "wim_type": wim_type
,
718 "wim_url": description_schema
,
719 "user": string_schema
,
720 "password": passwd_schema
,
721 "config": {"type": "object"},
723 "additionalProperties": False,
726 wim_account_new_schema
= {
727 "title": "wim_account creation input schema",
728 "$schema": "http://json-schema.org/draft-04/schema#",
731 "schema_version": schema_version
,
732 "schema_type": schema_type
,
734 "description": description_schema
,
736 "wim_type": wim_type
,
737 "wim_url": description_schema
,
738 "user": string_schema
,
739 "password": passwd_schema
,
742 "patternProperties": {".": {"not": {"type": "null"}}},
745 "required": ["name", "wim_url", "wim_type"],
746 "additionalProperties": False,
751 "type": {"type": "string"},
752 "url": {"type": "string"},
753 "user": string_schema
,
754 "password": passwd_schema
,
755 "config": {"type": "object"},
756 "description": description_schema
,
757 # The folowing are deprecated. Maintanied for backward compatibility
761 "version": {"type": "string", "minLength": 1, "maxLength": 12},
764 "title": "sdn controller information schema",
765 "$schema": "http://json-schema.org/draft-04/schema#",
767 "properties": sdn_properties
,
768 "required": ["name", "type"],
769 "additionalProperties": False,
772 "title": "sdn controller update information schema",
773 "$schema": "http://json-schema.org/draft-04/schema#",
775 "properties": sdn_properties
,
776 # "required": ["name", "port", 'ip', 'dpid', 'type'],
777 "additionalProperties": False,
779 sdn_port_mapping_schema
= {
780 "$schema": "http://json-schema.org/draft-04/schema#",
781 "title": "sdn port mapping information schema",
786 "compute_node": shortname_schema
,
792 "pci": pci_extended_schema
,
793 "switch_port": shortname_schema
,
794 "switch_mac": mac_schema
,
800 "required": ["compute_node", "ports"],
803 sdn_external_port_schema
= {
804 "$schema": "http://json-schema.org/draft-04/schema#",
805 "title": "External port information",
808 "port": {"type": "string", "minLength": 1, "maxLength": 60},
812 "required": ["port"],
816 k8scluster_deploy_method_schema
= {
817 "$schema": "http://json-schema.org/draft-04/schema#",
818 "title": "Deployment methods for K8s cluster",
821 "helm-chart": {"type": "boolean"},
822 "juju-bundle": {"type": "boolean"},
823 "helm-chart-v3": {"type": "boolean"},
825 "additionalProperties": False,
828 k8scluster_nets_schema
= {
829 "title": "k8scluster nets input schema",
830 "$schema": "http://json-schema.org/draft-04/schema#",
832 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
834 "additionalProperties": False,
836 k8scluster_new_schema
= {
837 "title": "k8scluster creation input schema",
838 "$schema": "http://json-schema.org/draft-04/schema#",
841 "schema_version": schema_version
,
842 "schema_type": schema_type
,
844 "description": description_schema
,
845 "credentials": object_schema
,
846 "vim_account": id_schema
,
848 "k8s_version": string_schema
,
849 "nets": k8scluster_nets_schema
,
850 "deployment_methods": k8scluster_deploy_method_schema
,
851 "namespace": name_schema
,
852 "cni": nameshort_list_schema
,
854 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
855 "additionalProperties": False,
857 k8scluster_edit_schema
= {
858 "title": "vim_account edit input schema",
859 "$schema": "http://json-schema.org/draft-04/schema#",
863 "description": description_schema
,
864 "credentials": object_schema
,
865 "vim_account": id_schema
,
867 "k8s_version": string_schema
,
868 "nets": k8scluster_nets_schema
,
869 "namespace": name_schema
,
870 "cni": nameshort_list_schema
,
872 "additionalProperties": False,
877 "title": "vca creation input schema",
878 "$schema": "http://json-schema.org/draft-04/schema#",
881 "schema_version": schema_version
,
882 "schema_type": schema_type
,
884 "description": description_schema
,
885 "endpoints": description_list_schema
,
886 "user": string_schema
,
887 "secret": passwd_schema
,
888 "cacert": long_description_schema
,
889 "lxd-cloud": shortname_schema
,
890 "lxd-credentials": shortname_schema
,
891 "k8s-cloud": shortname_schema
,
892 "k8s-credentials": shortname_schema
,
893 "model-config": object_schema
,
906 "additionalProperties": False,
909 "title": "vca creation input schema",
910 "$schema": "http://json-schema.org/draft-04/schema#",
914 "description": description_schema
,
915 "endpoints": description_list_schema
,
916 "port": integer1_schema
,
917 "user": string_schema
,
918 "secret": passwd_schema
,
919 "cacert": long_description_schema
,
920 "lxd-cloud": shortname_schema
,
921 "lxd-credentials": shortname_schema
,
922 "k8s-cloud": shortname_schema
,
923 "k8s-credentials": shortname_schema
,
924 "model-config": object_schema
,
926 "additionalProperties": False,
930 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
931 k8srepo_properties
= {
933 "description": description_schema
,
934 "type": k8srepo_types
,
935 "url": description_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": 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": 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
,
1113 "additionalProperties": False,
1117 topics_with_quota
= [
1133 project_new_schema
= {
1134 "$schema": "http://json-schema.org/draft-04/schema#",
1135 "title": "New project schema for administrators",
1138 "name": shortname_schema
,
1139 "admin": bool_schema
,
1140 "domain_name": shortname_schema
,
1143 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
1144 "additionalProperties": False,
1147 "required": ["name"],
1148 "additionalProperties": False,
1150 project_edit_schema
= {
1151 "$schema": "http://json-schema.org/draft-04/schema#",
1152 "title": "Project edit schema for administrators",
1155 "admin": bool_schema
,
1156 "name": shortname_schema
, # To allow Project Name modification
1160 topic
: {"oneOf": [integer0_schema
, null_schema
]}
1161 for topic
in topics_with_quota
1163 "additionalProperties": False,
1166 "additionalProperties": False,
1171 roles_new_schema
= {
1172 "$schema": "http://json-schema.org/draft-04/schema#",
1173 "title": "New role schema for administrators",
1176 "name": shortname_schema
,
1179 "patternProperties": {
1182 # "minProperties": 1,
1185 "required": ["name"],
1186 "additionalProperties": False,
1188 roles_edit_schema
= {
1189 "$schema": "http://json-schema.org/draft-04/schema#",
1190 "title": "Roles edit schema for administrators",
1193 "name": shortname_schema
,
1196 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1197 # "minProperties": 1,
1200 "additionalProperties": False,
1206 nbi_new_input_schemas
= {
1207 "users": user_new_schema
,
1208 "projects": project_new_schema
,
1209 "vim_accounts": vim_account_new_schema
,
1210 "sdns": sdn_new_schema
,
1211 "ns_instantiate": ns_instantiate
,
1212 "ns_action": ns_action
,
1213 "ns_scale": ns_scale
,
1214 "ns_update": ns_update
,
1216 "pdus": pdu_new_schema
,
1219 nbi_edit_input_schemas
= {
1220 "users": user_edit_schema
,
1221 "projects": project_edit_schema
,
1222 "vim_accounts": vim_account_edit_schema
,
1223 "sdns": sdn_edit_schema
,
1224 "pdus": pdu_edit_schema
,
1228 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1229 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1230 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1231 del nsi_subnet_instantiate
["required"]
1233 nsi_vld_instantiate
= {
1234 "title": "netslice vld instantiation params input schema",
1235 "$schema": "http://json-schema.org/draft-04/schema#",
1238 "name": string_schema
,
1239 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1240 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1241 "ip-profile": object_schema
,
1243 "required": ["name"],
1244 "additionalProperties": False,
1248 "title": "netslice action instantiate input schema",
1249 "$schema": "http://json-schema.org/draft-04/schema#",
1252 "lcmOperationType": string_schema
,
1253 "netsliceInstanceId": id_schema
,
1254 "nsiName": name_schema
,
1255 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1256 "nstId": string_schema
,
1257 "vimAccountId": id_schema
,
1258 "timeout_nsi_deploy": integer1_schema
,
1259 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1260 "nsi_id": id_schema
,
1261 "additionalParamsForNsi": object_schema
,
1262 "netslice-subnet": {
1265 "items": nsi_subnet_instantiate
,
1267 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1269 "required": ["nsiName", "nstId", "vimAccountId"],
1270 "additionalProperties": False,
1277 nsinstancesubscriptionfilter_schema
= {
1278 "title": "instance identifier schema",
1279 "$schema": "http://json-schema.org/draft-07/schema#",
1282 "nsdIds": {"type": "array"},
1283 "vnfdIds": {"type": "array"},
1284 "pnfdIds": {"type": "array"},
1285 "nsInstanceIds": {"type": "array"},
1286 "nsInstanceNames": {"type": "array"},
1291 "title": "nslcmsubscription input schema",
1292 "$schema": "http://json-schema.org/draft-07/schema#",
1295 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1296 "notificationTypes": {
1300 "NsLcmOperationOccurrenceNotification",
1301 "NsChangeNotification",
1302 "NsIdentifierCreationNotification",
1303 "NsIdentifierDeletionNotification",
1309 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1311 "operationStates": {
1317 "PARTIALLY_COMPLETED",
1325 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1326 "lcmOpNameImpactingNsComponent": {
1332 "VNF_SCALE_TO_LEVEL",
1333 "VNF_CHANGE_FLAVOUR",
1337 "VNF_CHANGE_EXT_CONN",
1347 "lcmOpOccStatusImpactingNsComponent": {
1353 "PARTIALLY_COMPLETED",
1364 "notificationTypes": {
1365 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1371 {"required": ["operationTypes"]},
1372 {"required": ["operationStates"]},
1379 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1384 {"required": ["nsComponentTypes"]},
1385 {"required": ["lcmOpNameImpactingNsComponent"]},
1386 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1393 authentication_schema
= {
1394 "title": "authentication schema for subscription",
1395 "$schema": "http://json-schema.org/draft-07/schema#",
1398 "authType": {"enum": ["basic"]},
1402 "userName": string_schema
,
1403 "password": passwd_schema
,
1410 "title": "subscription input schema",
1411 "$schema": "http://json-schema.org/draft-07/schema#",
1414 "filter": nslcmsub_schema
,
1415 "CallbackUri": description_schema
,
1416 "authentication": authentication_schema
,
1418 "required": ["CallbackUri"],
1421 vnflcmsub_schema
= {
1422 "title": "vnflcmsubscription input schema",
1423 "$schema": "http://json-schema.org/draft-07/schema#",
1426 "VnfInstanceSubscriptionFilter": {
1429 "vnfdIds": {"type": "array"},
1430 "vnfInstanceIds": {"type": "array"},
1433 "notificationTypes": {
1437 "VnfIdentifierCreationNotification",
1438 "VnfLcmOperationOccurrenceNotification",
1439 "VnfIdentifierDeletionNotification"
1447 "INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE",
1448 "HEAL", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO", "CREATE_SNAPSHOT",
1449 "REVERT_TO_SNAPSHOT", "CHANGE_VNFPKG"
1453 "operationStates": {
1457 "STARTING", "PROCESSING", "COMPLETED", "FAILED_TEMP", "FAILED",
1458 "ROLLING_BACK", "ROLLED_BACK"
1463 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"]
1466 vnf_subscription
= {
1467 "title": "vnf subscription input schema",
1468 "$schema": "http://json-schema.org/draft-07/schema#",
1471 "filter": vnflcmsub_schema
,
1472 "CallbackUri": description_schema
,
1473 "authentication": authentication_schema
1475 "required": ["filter", "CallbackUri"]
1479 class ValidationError(Exception):
1480 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1481 self
.http_code
= http_code
1482 Exception.__init
__(self
, message
)
1485 def validate_input(indata
, schema_to_use
):
1487 Validates input data against json schema
1488 :param indata: user input data. Should be a dictionary
1489 :param schema_to_use: jsonschema to test
1490 :return: None if ok, raises ValidationError exception on error
1494 js_v(indata
, schema_to_use
)
1496 except js_e
.ValidationError
as e
:
1498 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1501 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1502 except js_e
.SchemaError
:
1503 raise ValidationError(
1504 "Bad json schema {}".format(schema_to_use
),
1505 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1509 def is_valid_uuid(x
):
1511 Test for a valid UUID
1512 :param x: string to test
1513 :return: True if x is a valid uuid, False otherwise
1518 except (TypeError, ValueError, AttributeError):