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]))", # noqa: W605
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#",
140 "configurable-properties": {
150 "vim-volume-id": name_schema
,
152 "required": ["name", "vim-volume-id"],
153 "additionalProperties": False,
163 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
164 "mac-address": mac_schema
,
165 "floating-ip-required": bool_schema
,
167 "required": ["name"],
168 "additionalProperties": False,
173 "additionalProperties": False,
176 ip_profile_dns_schema
= {
182 "address": {"oneOf": [ip_schema
, ipv6_schema
]},
184 "required": ["address"],
185 "additionalProperties": False,
189 ip_profile_dhcp_schema
= {
192 "enabled": {"type": "boolean"},
193 "count": integer1_schema
,
194 "start-address": ip_schema
,
196 "additionalProperties": False,
199 ip_profile_schema
= {
200 "title": "ip profile validation schema",
201 "$schema": "http://json-schema.org/draft-04/schema#",
204 "ip-version": {"enum": ["ipv4", "ipv6"]},
205 "subnet-address": ip_prefix_schema
,
206 "gateway-address": ip_schema
,
207 "dns-server": ip_profile_dns_schema
,
208 "dhcp-params": ip_profile_dhcp_schema
,
212 ip_profile_update_schema
= {
213 "title": "ip profile validation schema",
214 "$schema": "http://json-schema.org/draft-04/schema#",
217 "ip-version": {"enum": ["ipv4", "ipv6"]},
218 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
219 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
220 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
221 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
223 "additionalProperties": False,
226 provider_network_schema
= {
227 "title": "provider network validation schema",
228 "$schema": "http://json-schema.org/draft-04/schema#",
231 "physical-network": name_schema
,
232 "segmentation-id": name_schema
,
233 "sdn-ports": { # external ports to append to the SDN-assist network
238 "switch_id": shortname_schema
,
239 "switch_port": shortname_schema
,
240 "mac_address": mac_schema
,
243 "additionalProperties": True,
246 "network-type": shortname_schema
,
248 "additionalProperties": True,
251 ns_instantiate_internal_vld
= {
252 "title": "ns action instantiate input schema for vld",
253 "$schema": "http://json-schema.org/draft-04/schema#",
257 "vim-network-name": name_schema
,
258 "vim-network-id": name_schema
,
259 "ip-profile": ip_profile_update_schema
,
260 "provider-network": provider_network_schema
,
261 "internal-connection-point": {
267 "id-ref": name_schema
,
268 "ip-address": ip_schema
,
269 # "mac-address": mac_schema,
271 "required": ["id-ref"],
273 "additionalProperties": False,
277 "required": ["name"],
279 "additionalProperties": False,
282 additional_params_for_vnf
= {
287 "member-vnf-index": name_schema
,
288 "additionalParams": object_schema
,
289 "k8s-namespace": name_schema
,
290 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
291 "additionalParamsForVdu": {
296 "vdu_id": name_schema
,
297 "additionalParams": object_schema
,
298 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
300 "required": ["vdu_id"],
302 "additionalProperties": False,
305 "additionalParamsForKdu": {
310 "kdu_name": name_schema
,
311 "additionalParams": object_schema
,
312 "kdu_model": name_schema
,
313 "k8s-namespace": name_schema
,
314 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
315 "kdu-deployment-name": name_schema
,
317 "required": ["kdu_name"],
319 "additionalProperties": False,
322 "affinity-or-anti-affinity-group": {
328 "vim-affinity-group-id": name_schema
,
332 "additionalProperties": False,
336 "required": ["member-vnf-index"],
338 "additionalProperties": False,
343 "title": "ns action instantiate input schema",
344 "$schema": "http://json-schema.org/draft-04/schema#",
347 "lcmOperationType": string_schema
,
348 "nsInstanceId": id_schema
,
349 "netsliceInstanceId": id_schema
,
350 "nsName": name_schema
,
351 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
353 "vimAccountId": id_schema
,
354 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
355 "placement-engine": string_schema
,
356 "placement-constraints": object_schema
,
357 "additionalParamsForNs": object_schema
,
358 "additionalParamsForVnf": additional_params_for_vnf
,
359 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
360 "k8s-namespace": name_schema
,
361 "ssh_keys": {"type": "array", "items": {"type": "string"}},
362 "timeout_ns_deploy": integer1_schema
,
364 "vduImage": name_schema
,
371 "member-vnf-index": name_schema
,
372 "vimAccountId": id_schema
,
376 "items": ns_instantiate_vdu
,
381 "items": ns_instantiate_internal_vld
,
384 "required": ["member-vnf-index"],
386 "additionalProperties": False,
395 "name": string_schema
,
396 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
397 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
398 "ns-net": object_schema
,
399 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
400 "ip-profile": object_schema
,
401 "provider-network": provider_network_schema
,
402 "vnfd-connection-point-ref": {
408 "member-vnf-index-ref": name_schema
,
409 "vnfd-connection-point-ref": name_schema
,
410 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
411 # "mac-address": mac_schema,
414 "member-vnf-index-ref",
415 "vnfd-connection-point-ref",
418 "additionalProperties": False,
422 "required": ["name"],
423 "additionalProperties": False,
427 "required": ["nsName", "nsdId", "vimAccountId"],
428 "additionalProperties": False,
432 "title": "ns terminate input schema",
433 "$schema": "http://json-schema.org/draft-04/schema#",
436 "lcmOperationType": string_schema
,
437 "nsInstanceId": id_schema
,
438 "autoremove": bool_schema
,
439 "timeout_ns_terminate": integer1_schema
,
440 "skip_terminate_primitives": bool_schema
,
441 "netsliceInstanceId": id_schema
,
443 "additionalProperties": False,
447 "title": "ns update input schema",
448 "$schema": "http://json-schema.org/draft-04/schema#",
451 "lcmOperationType": string_schema
,
452 "nsInstanceId": id_schema
,
453 "timeout_ns_update": integer1_schema
,
458 "MODIFY_VNF_INFORMATION",
462 "modifyVnfInfoData": {
465 "vnfInstanceId": id_schema
,
468 "required": ["vnfInstanceId", "vnfdId"],
470 "removeVnfInstanceId": id_schema
,
471 "changeVnfPackageData": {
474 "vnfInstanceId": id_schema
,
477 "required": ["vnfInstanceId", "vnfdId"],
482 "vnfInstanceId": id_schema
,
483 "changeStateTo": name_schema
,
487 "run-day1": bool_schema
,
488 "vdu_id": name_schema
,
489 "count-index": integer0_schema
,
491 "required": ["vdu_id", "count-index"],
492 "additionalProperties": False,
495 "required": ["vnfInstanceId", "changeStateTo"],
498 "required": ["updateType"],
499 "additionalProperties": False,
502 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
503 "title": "ns action input schema",
504 "$schema": "http://json-schema.org/draft-04/schema#",
507 "lcmOperationType": string_schema
,
508 "nsInstanceId": id_schema
,
509 "member_vnf_index": name_schema
,
510 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
511 "vdu_id": name_schema
,
512 "vdu_count_index": integer0_schema
,
513 "kdu_name": name_schema
,
514 "primitive": name_schema
,
515 "timeout_ns_action": integer1_schema
,
516 "primitive_params": {"type": "object"},
518 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
519 "additionalProperties": False,
522 ns_scale
= { # TODO for the moment it is only VDU-scaling
523 "title": "ns scale input schema",
524 "$schema": "http://json-schema.org/draft-04/schema#",
527 "lcmOperationType": string_schema
,
528 "nsInstanceId": id_schema
,
529 "scaleType": {"enum": ["SCALE_VNF"]},
530 "timeout_ns_scale": integer1_schema
,
534 "vnfInstanceId": name_schema
,
535 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
539 "scaling-group-descriptor": name_schema
,
540 "member-vnf-index": name_schema
,
541 "scaling-policy": name_schema
,
543 "required": ["scaling-group-descriptor", "member-vnf-index"],
544 "additionalProperties": False,
547 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
548 "additionalProperties": False,
550 "scaleTime": time_schema
,
552 "required": ["scaleType", "scaleVnfData"],
553 "additionalProperties": False,
557 "title": "ns migrate input schema",
558 "$schema": "http://json-schema.org/draft-04/schema#",
561 "lcmOperationType": string_schema
,
562 "nsInstanceId": id_schema
,
563 "vnfInstanceId": id_schema
,
564 "migrateToHost": string_schema
,
568 "vduId": name_schema
,
569 "vduCountIndex": integer0_schema
,
571 "required": ["vduId"],
572 "additionalProperties": False,
575 "required": ["vnfInstanceId"],
576 "additionalProperties": False,
580 "title": "ns heal input schema",
581 "$schema": "http://json-schema.org/draft-04/schema#",
584 "lcmOperationType": string_schema
,
585 "nsInstanceId": id_schema
,
586 "timeout_ns_heal": integer1_schema
,
592 "vnfInstanceId": id_schema
,
593 "cause": description_schema
,
594 "additionalParams": {
597 "run-day1": bool_schema
,
603 "run-day1": bool_schema
,
604 "vdu-id": name_schema
,
605 "count-index": integer0_schema
,
607 "required": ["vdu-id"],
608 "additionalProperties": False,
612 "additionalProperties": False,
615 "required": ["vnfInstanceId"],
616 "additionalProperties": False,
620 "required": ["healVnfData"],
621 "additionalProperties": False,
625 "title": "vertial scale input schema",
626 "$schema": "http://json-schema.org/draft-04/schema#",
629 "lcmOperationType": string_schema
,
630 "verticalScale": string_schema
,
631 "nsInstanceId": id_schema
,
632 "changeVnfFlavorData": {
635 "vnfInstanceId": id_schema
,
636 "additionalParams": {
639 "vduid": string_schema
,
640 "vduCountIndex": integer0_schema
,
641 "virtualMemory": integer1_schema
,
642 "sizeOfStorage": integer0_schema
,
643 "numVirtualCpu": integer1_schema
,
647 "required": ["vnfInstanceId", "additionalParams"],
648 "additionalProperties": False,
651 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
652 "additionalProperties": False,
655 schema_version
= {"type": "string", "enum": ["1.0"]}
656 schema_type
= {"type": "string"}
657 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
659 vim_account_edit_schema
= {
660 "title": "vim_account edit input schema",
661 "$schema": "http://json-schema.org/draft-04/schema#",
665 "description": description_schema
,
667 "datacenter": name_schema
,
668 "vim_type": vim_type
,
669 "vim_url": description_schema
,
670 # "vim_url_admin": description_schema,
671 # "vim_tenant": name_schema,
672 "vim_tenant_name": name_schema
,
673 "vim_user": string_schema
,
674 "vim_password": passwd_schema
,
676 "config": {"type": "object"},
677 "prometheus-config": {"type": "object"},
679 "additionalProperties": False,
682 vim_account_new_schema
= {
683 "title": "vim_account creation input schema",
684 "$schema": "http://json-schema.org/draft-04/schema#",
687 "schema_version": schema_version
,
688 "schema_type": schema_type
,
690 "description": description_schema
,
692 "datacenter": name_schema
,
693 "vim_type": vim_type
,
694 "vim_url": description_schema
,
695 # "vim_url_admin": description_schema,
696 # "vim_tenant": name_schema,
697 "vim_tenant_name": name_schema
,
698 "vim_user": string_schema
,
699 "vim_password": passwd_schema
,
701 "config": {"type": "object"},
702 "prometheus-config": {"type": "object"},
712 "additionalProperties": False,
715 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
717 wim_account_edit_schema
= {
718 "title": "wim_account edit input schema",
719 "$schema": "http://json-schema.org/draft-04/schema#",
723 "description": description_schema
,
725 "wim_type": wim_type
,
726 "wim_url": description_schema
,
727 "user": string_schema
,
728 "password": passwd_schema
,
729 "config": {"type": "object"},
731 "additionalProperties": False,
734 wim_account_new_schema
= {
735 "title": "wim_account creation input schema",
736 "$schema": "http://json-schema.org/draft-04/schema#",
739 "schema_version": schema_version
,
740 "schema_type": schema_type
,
742 "description": description_schema
,
744 "wim_type": wim_type
,
745 "wim_url": description_schema
,
746 "user": string_schema
,
747 "password": passwd_schema
,
750 "patternProperties": {".": {"not": {"type": "null"}}},
753 "required": ["name", "wim_url", "wim_type"],
754 "additionalProperties": False,
759 "type": {"type": "string"},
760 "url": {"type": "string"},
761 "user": string_schema
,
762 "password": passwd_schema
,
763 "config": {"type": "object"},
764 "description": description_schema
,
765 # The folowing are deprecated. Maintanied for backward compatibility
769 "version": {"type": "string", "minLength": 1, "maxLength": 12},
772 "title": "sdn controller information schema",
773 "$schema": "http://json-schema.org/draft-04/schema#",
775 "properties": sdn_properties
,
776 "required": ["name", "type"],
777 "additionalProperties": False,
780 "title": "sdn controller update information schema",
781 "$schema": "http://json-schema.org/draft-04/schema#",
783 "properties": sdn_properties
,
784 # "required": ["name", "port", 'ip', 'dpid', 'type'],
785 "additionalProperties": False,
787 sdn_port_mapping_schema
= {
788 "$schema": "http://json-schema.org/draft-04/schema#",
789 "title": "sdn port mapping information schema",
794 "compute_node": shortname_schema
,
800 "pci": pci_extended_schema
,
801 "switch_port": shortname_schema
,
802 "switch_mac": mac_schema
,
808 "required": ["compute_node", "ports"],
811 sdn_external_port_schema
= {
812 "$schema": "http://json-schema.org/draft-04/schema#",
813 "title": "External port information",
816 "port": {"type": "string", "minLength": 1, "maxLength": 60},
820 "required": ["port"],
824 k8scluster_deploy_method_schema
= {
825 "$schema": "http://json-schema.org/draft-04/schema#",
826 "title": "Deployment methods for K8s cluster",
829 "helm-chart": {"type": "boolean"},
830 "juju-bundle": {"type": "boolean"},
831 "helm-chart-v3": {"type": "boolean"},
833 "additionalProperties": False,
836 k8scluster_nets_schema
= {
837 "title": "k8scluster nets input schema",
838 "$schema": "http://json-schema.org/draft-04/schema#",
840 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
842 "additionalProperties": False,
844 k8scluster_new_schema
= {
845 "title": "k8scluster creation input schema",
846 "$schema": "http://json-schema.org/draft-04/schema#",
849 "schema_version": schema_version
,
850 "schema_type": schema_type
,
852 "description": description_schema
,
853 "credentials": object_schema
,
854 "vim_account": id_schema
,
856 "k8s_version": string_schema
,
857 "nets": k8scluster_nets_schema
,
858 "deployment_methods": k8scluster_deploy_method_schema
,
859 "namespace": name_schema
,
860 "cni": nameshort_list_schema
,
862 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
863 "additionalProperties": False,
865 k8scluster_edit_schema
= {
866 "title": "vim_account edit input schema",
867 "$schema": "http://json-schema.org/draft-04/schema#",
871 "description": description_schema
,
872 "credentials": object_schema
,
873 "vim_account": id_schema
,
875 "k8s_version": string_schema
,
876 "nets": k8scluster_nets_schema
,
877 "namespace": name_schema
,
878 "cni": nameshort_list_schema
,
880 "additionalProperties": False,
885 "title": "vca creation input schema",
886 "$schema": "http://json-schema.org/draft-04/schema#",
889 "schema_version": schema_version
,
890 "schema_type": schema_type
,
892 "description": description_schema
,
893 "endpoints": description_list_schema
,
894 "user": string_schema
,
895 "secret": passwd_schema
,
896 "cacert": long_description_schema
,
897 "lxd-cloud": shortname_schema
,
898 "lxd-credentials": shortname_schema
,
899 "k8s-cloud": shortname_schema
,
900 "k8s-credentials": shortname_schema
,
901 "model-config": object_schema
,
914 "additionalProperties": False,
917 "title": "vca creation input schema",
918 "$schema": "http://json-schema.org/draft-04/schema#",
922 "description": description_schema
,
923 "endpoints": description_list_schema
,
924 "port": integer1_schema
,
925 "user": string_schema
,
926 "secret": passwd_schema
,
927 "cacert": long_description_schema
,
928 "lxd-cloud": shortname_schema
,
929 "lxd-credentials": shortname_schema
,
930 "k8s-cloud": shortname_schema
,
931 "k8s-credentials": shortname_schema
,
932 "model-config": object_schema
,
934 "additionalProperties": False,
938 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
939 k8srepo_properties
= {
941 "description": description_schema
,
942 "type": k8srepo_types
,
943 "url": description_schema
,
945 k8srepo_new_schema
= {
946 "title": "k8scluster creation input schema",
947 "$schema": "http://json-schema.org/draft-04/schema#",
949 "properties": k8srepo_properties
,
950 "required": ["name", "type", "url"],
951 "additionalProperties": False,
953 k8srepo_edit_schema
= {
954 "title": "vim_account edit input schema",
955 "$schema": "http://json-schema.org/draft-04/schema#",
957 "properties": k8srepo_properties
,
958 "additionalProperties": False,
962 osmrepo_types
= {"enum": ["osm"]}
963 osmrepo_properties
= {
965 "description": description_schema
,
966 "type": osmrepo_types
,
967 "url": description_schema
968 # "user": string_schema,
969 # "password": passwd_schema
971 osmrepo_new_schema
= {
972 "title": "osm repo creation input schema",
973 "$schema": "http://json-schema.org/draft-04/schema#",
975 "properties": osmrepo_properties
,
976 "required": ["name", "type", "url"],
977 "additionalProperties": False,
979 osmrepo_edit_schema
= {
980 "title": "osm repo edit input schema",
981 "$schema": "http://json-schema.org/draft-04/schema#",
983 "properties": osmrepo_properties
,
984 "additionalProperties": False,
991 "name": shortname_schema
,
993 "type": {"enum": ["overlay", "underlay"]},
994 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
995 # TODO, add user, password, ssh-key
996 "mac-address": mac_schema
,
997 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
998 "vim-network-id": shortname_schema
,
999 # # provide this in case SDN assist must deal with this interface
1000 # "switch-dpid": dpid_Schema,
1001 # "switch-port": shortname_schema,
1002 # "switch-mac": shortname_schema,
1003 # "switch-vlan": vlan_schema,
1005 "required": ["name", "mgmt", "ip-address"],
1006 "additionalProperties": False,
1009 "title": "pdu creation input schema",
1010 "$schema": "http://json-schema.org/draft-04/schema#",
1013 "name": shortname_schema
,
1014 "type": shortname_schema
,
1015 "description": description_schema
,
1016 "shared": bool_schema
,
1017 "vims": nameshort_list_schema
,
1018 "vim_accounts": nameshort_list_schema
,
1019 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
1021 "required": ["name", "type", "interfaces"],
1022 "additionalProperties": False,
1025 "title": "pdu edit input schema",
1026 "$schema": "http://json-schema.org/draft-04/schema#",
1029 "name": shortname_schema
,
1030 "type": shortname_schema
,
1031 "description": description_schema
,
1032 "shared": bool_schema
,
1033 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1034 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1037 array_edition_schema
,
1038 {"type": "array", "items": pdu_interface
, "minItems": 1},
1042 "additionalProperties": False,
1046 # VNF PKG OPERATIONS
1047 vnfpkgop_new_schema
= {
1048 "title": "VNF PKG operation creation input schema",
1049 "$schema": "http://json-schema.org/draft-04/schema#",
1052 "lcmOperationType": string_schema
,
1053 "vnfPkgId": id_schema
,
1054 "kdu_name": name_schema
,
1055 "primitive": name_schema
,
1056 "primitive_params": {"type": "object"},
1065 "additionalProperties": False,
1069 project_role_mappings
= {
1070 "title": "list pf projects/roles",
1071 "$schema": "http://json-schema.org/draft-04/schema#",
1075 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1076 "required": ["project", "role"],
1077 "additionalProperties": False,
1081 project_role_mappings_optional
= {
1082 "title": "list of projects/roles or projects only",
1083 "$schema": "http://json-schema.org/draft-04/schema#",
1087 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1088 "required": ["project"],
1089 "additionalProperties": False,
1094 "$schema": "http://json-schema.org/draft-04/schema#",
1095 "title": "New user schema",
1098 "username": string_schema
,
1099 "domain_name": shortname_schema
,
1100 "password": passwd_schema
,
1101 "projects": nameshort_list_schema
,
1102 "project_role_mappings": project_role_mappings
,
1104 "required": ["username", "password"],
1105 "additionalProperties": False,
1107 user_edit_schema
= {
1108 "$schema": "http://json-schema.org/draft-04/schema#",
1109 "title": "User edit schema for administrators",
1112 "password": passwd_schema
,
1113 "old_password": passwd_schema
,
1114 "username": string_schema
, # To allow User Name modification
1115 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
1116 "project_role_mappings": project_role_mappings
,
1117 "add_project_role_mappings": project_role_mappings
,
1118 "remove_project_role_mappings": project_role_mappings_optional
,
1121 "additionalProperties": False,
1125 topics_with_quota
= [
1141 project_new_schema
= {
1142 "$schema": "http://json-schema.org/draft-04/schema#",
1143 "title": "New project schema for administrators",
1146 "name": shortname_schema
,
1147 "admin": bool_schema
,
1148 "domain_name": shortname_schema
,
1151 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
1152 "additionalProperties": False,
1155 "required": ["name"],
1156 "additionalProperties": False,
1158 project_edit_schema
= {
1159 "$schema": "http://json-schema.org/draft-04/schema#",
1160 "title": "Project edit schema for administrators",
1163 "admin": bool_schema
,
1164 "name": shortname_schema
, # To allow Project Name modification
1168 topic
: {"oneOf": [integer0_schema
, null_schema
]}
1169 for topic
in topics_with_quota
1171 "additionalProperties": False,
1174 "additionalProperties": False,
1179 roles_new_schema
= {
1180 "$schema": "http://json-schema.org/draft-04/schema#",
1181 "title": "New role schema for administrators",
1184 "name": shortname_schema
,
1187 "patternProperties": {
1190 # "minProperties": 1,
1193 "required": ["name"],
1194 "additionalProperties": False,
1196 roles_edit_schema
= {
1197 "$schema": "http://json-schema.org/draft-04/schema#",
1198 "title": "Roles edit schema for administrators",
1201 "name": shortname_schema
,
1204 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1205 # "minProperties": 1,
1208 "additionalProperties": False,
1214 nbi_new_input_schemas
= {
1215 "users": user_new_schema
,
1216 "projects": project_new_schema
,
1217 "vim_accounts": vim_account_new_schema
,
1218 "sdns": sdn_new_schema
,
1219 "ns_instantiate": ns_instantiate
,
1220 "ns_action": ns_action
,
1221 "ns_scale": ns_scale
,
1222 "ns_update": ns_update
,
1224 "pdus": pdu_new_schema
,
1227 nbi_edit_input_schemas
= {
1228 "users": user_edit_schema
,
1229 "projects": project_edit_schema
,
1230 "vim_accounts": vim_account_edit_schema
,
1231 "sdns": sdn_edit_schema
,
1232 "pdus": pdu_edit_schema
,
1236 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1237 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1238 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1239 del nsi_subnet_instantiate
["required"]
1241 nsi_vld_instantiate
= {
1242 "title": "netslice vld instantiation params input schema",
1243 "$schema": "http://json-schema.org/draft-04/schema#",
1246 "name": string_schema
,
1247 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1248 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1249 "ip-profile": object_schema
,
1251 "required": ["name"],
1252 "additionalProperties": False,
1256 "title": "netslice action instantiate input schema",
1257 "$schema": "http://json-schema.org/draft-04/schema#",
1260 "lcmOperationType": string_schema
,
1261 "netsliceInstanceId": id_schema
,
1262 "nsiName": name_schema
,
1263 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1264 "nstId": string_schema
,
1265 "vimAccountId": id_schema
,
1266 "timeout_nsi_deploy": integer1_schema
,
1267 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1268 "nsi_id": id_schema
,
1269 "additionalParamsForNsi": object_schema
,
1270 "netslice-subnet": {
1273 "items": nsi_subnet_instantiate
,
1275 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1277 "required": ["nsiName", "nstId", "vimAccountId"],
1278 "additionalProperties": False,
1285 nsinstancesubscriptionfilter_schema
= {
1286 "title": "instance identifier schema",
1287 "$schema": "http://json-schema.org/draft-07/schema#",
1290 "nsdIds": {"type": "array"},
1291 "vnfdIds": {"type": "array"},
1292 "pnfdIds": {"type": "array"},
1293 "nsInstanceIds": {"type": "array"},
1294 "nsInstanceNames": {"type": "array"},
1299 "title": "nslcmsubscription input schema",
1300 "$schema": "http://json-schema.org/draft-07/schema#",
1303 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1304 "notificationTypes": {
1308 "NsLcmOperationOccurrenceNotification",
1309 "NsChangeNotification",
1310 "NsIdentifierCreationNotification",
1311 "NsIdentifierDeletionNotification",
1317 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1319 "operationStates": {
1325 "PARTIALLY_COMPLETED",
1333 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1334 "lcmOpNameImpactingNsComponent": {
1340 "VNF_SCALE_TO_LEVEL",
1341 "VNF_CHANGE_FLAVOUR",
1345 "VNF_CHANGE_EXT_CONN",
1355 "lcmOpOccStatusImpactingNsComponent": {
1361 "PARTIALLY_COMPLETED",
1372 "notificationTypes": {
1373 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1379 {"required": ["operationTypes"]},
1380 {"required": ["operationStates"]},
1387 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1392 {"required": ["nsComponentTypes"]},
1393 {"required": ["lcmOpNameImpactingNsComponent"]},
1394 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1401 authentication_schema
= {
1402 "title": "authentication schema for subscription",
1403 "$schema": "http://json-schema.org/draft-07/schema#",
1406 "authType": {"enum": ["basic"]},
1410 "userName": string_schema
,
1411 "password": passwd_schema
,
1418 "title": "subscription input schema",
1419 "$schema": "http://json-schema.org/draft-07/schema#",
1422 "filter": nslcmsub_schema
,
1423 "CallbackUri": description_schema
,
1424 "authentication": authentication_schema
,
1426 "required": ["CallbackUri"],
1429 vnflcmsub_schema
= {
1430 "title": "vnflcmsubscription input schema",
1431 "$schema": "http://json-schema.org/draft-07/schema#",
1434 "VnfInstanceSubscriptionFilter": {
1437 "vnfdIds": {"type": "array"},
1438 "vnfInstanceIds": {"type": "array"},
1441 "notificationTypes": {
1445 "VnfIdentifierCreationNotification",
1446 "VnfLcmOperationOccurrenceNotification",
1447 "VnfIdentifierDeletionNotification",
1465 "REVERT_TO_SNAPSHOT",
1470 "operationStates": {
1485 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1488 vnf_subscription
= {
1489 "title": "vnf subscription input schema",
1490 "$schema": "http://json-schema.org/draft-07/schema#",
1493 "filter": vnflcmsub_schema
,
1494 "CallbackUri": description_schema
,
1495 "authentication": authentication_schema
,
1497 "required": ["filter", "CallbackUri"],
1501 class ValidationError(Exception):
1502 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1503 self
.http_code
= http_code
1504 Exception.__init
__(self
, message
)
1507 def validate_input(indata
, schema_to_use
):
1509 Validates input data against json schema
1510 :param indata: user input data. Should be a dictionary
1511 :param schema_to_use: jsonschema to test
1512 :return: None if ok, raises ValidationError exception on error
1516 js_v(indata
, schema_to_use
)
1518 except js_e
.ValidationError
as e
:
1520 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1523 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1524 except js_e
.SchemaError
:
1525 raise ValidationError(
1526 "Bad json schema {}".format(schema_to_use
),
1527 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1531 def is_valid_uuid(x
):
1533 Test for a valid UUID
1534 :param x: string to test
1535 :return: True if x is a valid uuid, False otherwise
1540 except (TypeError, ValueError, AttributeError):