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 "vim-flavor-id": name_schema
,
148 "vim-volume-id": name_schema
,
150 "required": ["name", "vim-volume-id"],
151 "additionalProperties": False,
161 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
162 "mac-address": mac_schema
,
163 "floating-ip-required": bool_schema
,
165 "required": ["name"],
166 "additionalProperties": False,
171 "additionalProperties": False,
174 ip_profile_dns_schema
= {
180 "address": {"oneOf": [ip_schema
, ipv6_schema
]},
182 "required": ["address"],
183 "additionalProperties": False,
187 ip_profile_dhcp_schema
= {
190 "enabled": {"type": "boolean"},
191 "count": integer1_schema
,
192 "start-address": ip_schema
,
194 "additionalProperties": False,
197 ip_profile_schema
= {
198 "title": "ip profile validation schema",
199 "$schema": "http://json-schema.org/draft-04/schema#",
202 "ip-version": {"enum": ["ipv4", "ipv6"]},
203 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
204 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
205 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
206 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
208 "additionalProperties": False,
211 provider_network_schema
= {
212 "title": "provider network validation schema",
213 "$schema": "http://json-schema.org/draft-04/schema#",
216 "physical-network": name_schema
,
217 "segmentation-id": name_schema
,
218 "sdn-ports": { # external ports to append to the SDN-assist network
223 "switch_id": shortname_schema
,
224 "switch_port": shortname_schema
,
225 "mac_address": mac_schema
,
228 "additionalProperties": True,
231 "network-type": shortname_schema
,
233 "additionalProperties": True,
236 ns_instantiate_internal_vld
= {
237 "title": "ns action instantiate input schema for vld",
238 "$schema": "http://json-schema.org/draft-04/schema#",
242 "vim-network-name": name_schema
,
243 "vim-network-id": name_schema
,
244 "ip-profile": ip_profile_schema
,
245 "provider-network": provider_network_schema
,
246 "internal-connection-point": {
252 "id-ref": name_schema
,
253 "ip-address": ip_schema
,
254 # "mac-address": mac_schema,
256 "required": ["id-ref"],
258 "additionalProperties": False,
262 "required": ["name"],
264 "additionalProperties": False,
267 additional_params_for_vnf
= {
272 "member-vnf-index": name_schema
,
273 "additionalParams": object_schema
,
274 "k8s-namespace": name_schema
,
275 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
276 "additionalParamsForVdu": {
281 "vdu_id": name_schema
,
282 "additionalParams": object_schema
,
283 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
285 "required": ["vdu_id"],
287 "additionalProperties": False,
290 "additionalParamsForKdu": {
295 "kdu_name": name_schema
,
296 "additionalParams": object_schema
,
297 "kdu_model": name_schema
,
298 "k8s-namespace": name_schema
,
299 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
300 "kdu-deployment-name": name_schema
,
302 "required": ["kdu_name"],
304 "additionalProperties": False,
307 "affinity-or-anti-affinity-group": {
313 "vim-affinity-group-id": name_schema
,
317 "additionalProperties": False,
321 "required": ["member-vnf-index"],
323 "additionalProperties": False,
328 "title": "ns action instantiate input schema",
329 "$schema": "http://json-schema.org/draft-04/schema#",
332 "lcmOperationType": string_schema
,
333 "nsInstanceId": id_schema
,
334 "netsliceInstanceId": id_schema
,
335 "nsName": name_schema
,
336 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
338 "vimAccountId": id_schema
,
339 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
340 "placement-engine": string_schema
,
341 "placement-constraints": object_schema
,
342 "additionalParamsForNs": object_schema
,
343 "additionalParamsForVnf": additional_params_for_vnf
,
344 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
345 "k8s-namespace": name_schema
,
346 "ssh_keys": {"type": "array", "items": {"type": "string"}},
347 "timeout_ns_deploy": integer1_schema
,
349 "vduImage": name_schema
,
356 "member-vnf-index": name_schema
,
357 "vimAccountId": id_schema
,
361 "items": ns_instantiate_vdu
,
366 "items": ns_instantiate_internal_vld
,
369 "required": ["member-vnf-index"],
371 "additionalProperties": False,
380 "name": string_schema
,
381 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
382 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
383 "ns-net": object_schema
,
384 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
385 "ip-profile": ip_profile_schema
,
386 "provider-network": provider_network_schema
,
387 "vnfd-connection-point-ref": {
393 "member-vnf-index-ref": name_schema
,
394 "vnfd-connection-point-ref": name_schema
,
395 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
396 # "mac-address": mac_schema,
399 "member-vnf-index-ref",
400 "vnfd-connection-point-ref",
403 "additionalProperties": False,
407 "required": ["name"],
408 "additionalProperties": False,
412 "required": ["nsName", "nsdId", "vimAccountId"],
413 "additionalProperties": False,
417 "title": "ns terminate input schema",
418 "$schema": "http://json-schema.org/draft-04/schema#",
421 "lcmOperationType": string_schema
,
422 "nsInstanceId": id_schema
,
423 "autoremove": bool_schema
,
424 "timeout_ns_terminate": integer1_schema
,
425 "skip_terminate_primitives": bool_schema
,
426 "netsliceInstanceId": id_schema
,
428 "additionalProperties": False,
432 "title": "ns update input schema",
433 "$schema": "http://json-schema.org/draft-04/schema#",
436 "lcmOperationType": string_schema
,
437 "nsInstanceId": id_schema
,
438 "timeout_ns_update": integer1_schema
,
443 "MODIFY_VNF_INFORMATION",
447 "modifyVnfInfoData": {
450 "vnfInstanceId": id_schema
,
453 "required": ["vnfInstanceId", "vnfdId"],
455 "removeVnfInstanceId": id_schema
,
456 "changeVnfPackageData": {
459 "vnfInstanceId": id_schema
,
462 "required": ["vnfInstanceId", "vnfdId"],
467 "vnfInstanceId": id_schema
,
468 "changeStateTo": name_schema
,
472 "run-day1": bool_schema
,
473 "vdu_id": name_schema
,
474 "count-index": integer0_schema
,
476 "required": ["vdu_id", "count-index"],
477 "additionalProperties": False,
480 "required": ["vnfInstanceId", "changeStateTo"],
483 "required": ["updateType"],
484 "additionalProperties": False,
487 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
488 "title": "ns action input schema",
489 "$schema": "http://json-schema.org/draft-04/schema#",
492 "lcmOperationType": string_schema
,
493 "nsInstanceId": id_schema
,
494 "member_vnf_index": name_schema
,
495 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
496 "vdu_id": name_schema
,
497 "vdu_count_index": integer0_schema
,
498 "kdu_name": name_schema
,
499 "primitive": name_schema
,
500 "timeout_ns_action": integer1_schema
,
501 "primitive_params": {"type": "object"},
503 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
504 "additionalProperties": False,
507 ns_scale
= { # TODO for the moment it is only VDU-scaling
508 "title": "ns scale input schema",
509 "$schema": "http://json-schema.org/draft-04/schema#",
512 "lcmOperationType": string_schema
,
513 "nsInstanceId": id_schema
,
514 "scaleType": {"enum": ["SCALE_VNF"]},
515 "timeout_ns_scale": integer1_schema
,
519 "vnfInstanceId": name_schema
,
520 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
524 "scaling-group-descriptor": name_schema
,
525 "member-vnf-index": name_schema
,
526 "scaling-policy": name_schema
,
528 "required": ["scaling-group-descriptor", "member-vnf-index"],
529 "additionalProperties": False,
532 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
533 "additionalProperties": False,
535 "scaleTime": time_schema
,
537 "required": ["scaleType", "scaleVnfData"],
538 "additionalProperties": False,
542 "title": "ns migrate input schema",
543 "$schema": "http://json-schema.org/draft-04/schema#",
546 "lcmOperationType": string_schema
,
547 "nsInstanceId": id_schema
,
548 "vnfInstanceId": id_schema
,
549 "migrateToHost": string_schema
,
553 "vduId": name_schema
,
554 "vduCountIndex": integer0_schema
,
556 "required": ["vduId"],
557 "additionalProperties": False,
560 "required": ["vnfInstanceId"],
561 "additionalProperties": False,
565 "title": "ns heal input schema",
566 "$schema": "http://json-schema.org/draft-04/schema#",
569 "lcmOperationType": string_schema
,
570 "nsInstanceId": id_schema
,
571 "timeout_ns_heal": integer1_schema
,
577 "vnfInstanceId": id_schema
,
578 "cause": description_schema
,
579 "additionalParams": {
582 "run-day1": bool_schema
,
588 "run-day1": bool_schema
,
589 "vdu-id": name_schema
,
590 "count-index": integer0_schema
,
592 "required": ["vdu-id"],
593 "additionalProperties": False,
597 "additionalProperties": False,
600 "required": ["vnfInstanceId"],
601 "additionalProperties": False,
605 "required": ["healVnfData"],
606 "additionalProperties": False,
610 "title": "vertial scale input schema",
611 "$schema": "http://json-schema.org/draft-04/schema#",
614 "lcmOperationType": string_schema
,
615 "verticalScale": string_schema
,
616 "nsInstanceId": id_schema
,
617 "changeVnfFlavorData": {
620 "vnfInstanceId": id_schema
,
621 "additionalParams": {
624 "vduid": string_schema
,
625 "vduCountIndex": integer0_schema
,
626 "virtualMemory": integer1_schema
,
627 "sizeOfStorage": integer0_schema
,
628 "numVirtualCpu": integer1_schema
,
632 "required": ["vnfInstanceId", "additionalParams"],
633 "additionalProperties": False,
636 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
637 "additionalProperties": False,
640 schema_version
= {"type": "string", "enum": ["1.0"]}
641 schema_type
= {"type": "string"}
642 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
644 vim_account_edit_schema
= {
645 "title": "vim_account edit input schema",
646 "$schema": "http://json-schema.org/draft-04/schema#",
650 "description": description_schema
,
652 "datacenter": name_schema
,
653 "vim_type": vim_type
,
654 "vim_url": description_schema
,
655 # "vim_url_admin": description_schema,
656 # "vim_tenant": name_schema,
657 "vim_tenant_name": name_schema
,
658 "vim_user": string_schema
,
659 "vim_password": passwd_schema
,
661 "config": {"type": "object"},
662 "prometheus-config": {"type": "object"},
664 "additionalProperties": False,
667 vim_account_new_schema
= {
668 "title": "vim_account creation input schema",
669 "$schema": "http://json-schema.org/draft-04/schema#",
672 "schema_version": schema_version
,
673 "schema_type": schema_type
,
675 "description": description_schema
,
677 "datacenter": name_schema
,
678 "vim_type": vim_type
,
679 "vim_url": description_schema
,
680 # "vim_url_admin": description_schema,
681 # "vim_tenant": name_schema,
682 "vim_tenant_name": name_schema
,
683 "vim_user": string_schema
,
684 "vim_password": passwd_schema
,
686 "config": {"type": "object"},
687 "prometheus-config": {"type": "object"},
697 "additionalProperties": False,
700 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
702 wim_account_edit_schema
= {
703 "title": "wim_account edit input schema",
704 "$schema": "http://json-schema.org/draft-04/schema#",
708 "description": description_schema
,
710 "wim_type": wim_type
,
711 "wim_url": description_schema
,
712 "user": string_schema
,
713 "password": passwd_schema
,
714 "config": {"type": "object"},
716 "additionalProperties": False,
719 wim_account_new_schema
= {
720 "title": "wim_account creation input schema",
721 "$schema": "http://json-schema.org/draft-04/schema#",
724 "schema_version": schema_version
,
725 "schema_type": schema_type
,
727 "description": description_schema
,
729 "wim_type": wim_type
,
730 "wim_url": description_schema
,
731 "user": string_schema
,
732 "password": passwd_schema
,
735 "patternProperties": {".": {"not": {"type": "null"}}},
738 "required": ["name", "wim_url", "wim_type"],
739 "additionalProperties": False,
744 "type": {"type": "string"},
745 "url": {"type": "string"},
746 "user": string_schema
,
747 "password": passwd_schema
,
748 "config": {"type": "object"},
749 "description": description_schema
,
750 # The folowing are deprecated. Maintanied for backward compatibility
754 "version": {"type": "string", "minLength": 1, "maxLength": 12},
757 "title": "sdn controller information schema",
758 "$schema": "http://json-schema.org/draft-04/schema#",
760 "properties": sdn_properties
,
761 "required": ["name", "type"],
762 "additionalProperties": False,
765 "title": "sdn controller update information schema",
766 "$schema": "http://json-schema.org/draft-04/schema#",
768 "properties": sdn_properties
,
769 # "required": ["name", "port", 'ip', 'dpid', 'type'],
770 "additionalProperties": False,
772 sdn_port_mapping_schema
= {
773 "$schema": "http://json-schema.org/draft-04/schema#",
774 "title": "sdn port mapping information schema",
779 "compute_node": shortname_schema
,
785 "pci": pci_extended_schema
,
786 "switch_port": shortname_schema
,
787 "switch_mac": mac_schema
,
793 "required": ["compute_node", "ports"],
796 sdn_external_port_schema
= {
797 "$schema": "http://json-schema.org/draft-04/schema#",
798 "title": "External port information",
801 "port": {"type": "string", "minLength": 1, "maxLength": 60},
805 "required": ["port"],
809 k8scluster_deploy_method_schema
= {
810 "$schema": "http://json-schema.org/draft-04/schema#",
811 "title": "Deployment methods for K8s cluster",
814 "helm-chart": {"type": "boolean"},
815 "juju-bundle": {"type": "boolean"},
816 "helm-chart-v3": {"type": "boolean"},
818 "additionalProperties": False,
821 k8scluster_nets_schema
= {
822 "title": "k8scluster nets input schema",
823 "$schema": "http://json-schema.org/draft-04/schema#",
825 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
827 "additionalProperties": False,
829 k8scluster_new_schema
= {
830 "title": "k8scluster creation input schema",
831 "$schema": "http://json-schema.org/draft-04/schema#",
834 "schema_version": schema_version
,
835 "schema_type": schema_type
,
837 "description": description_schema
,
838 "credentials": object_schema
,
839 "vim_account": id_schema
,
841 "k8s_version": string_schema
,
842 "nets": k8scluster_nets_schema
,
843 "deployment_methods": k8scluster_deploy_method_schema
,
844 "namespace": name_schema
,
845 "cni": nameshort_list_schema
,
847 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
848 "additionalProperties": False,
850 k8scluster_edit_schema
= {
851 "title": "vim_account edit input schema",
852 "$schema": "http://json-schema.org/draft-04/schema#",
856 "description": description_schema
,
857 "credentials": object_schema
,
858 "vim_account": id_schema
,
860 "k8s_version": string_schema
,
861 "nets": k8scluster_nets_schema
,
862 "namespace": name_schema
,
863 "cni": nameshort_list_schema
,
865 "additionalProperties": False,
870 "title": "vca creation input schema",
871 "$schema": "http://json-schema.org/draft-04/schema#",
874 "schema_version": schema_version
,
875 "schema_type": schema_type
,
877 "description": description_schema
,
878 "endpoints": description_list_schema
,
879 "user": string_schema
,
880 "secret": passwd_schema
,
881 "cacert": long_description_schema
,
882 "lxd-cloud": shortname_schema
,
883 "lxd-credentials": shortname_schema
,
884 "k8s-cloud": shortname_schema
,
885 "k8s-credentials": shortname_schema
,
886 "model-config": object_schema
,
899 "additionalProperties": False,
902 "title": "vca creation input schema",
903 "$schema": "http://json-schema.org/draft-04/schema#",
907 "description": description_schema
,
908 "endpoints": description_list_schema
,
909 "port": integer1_schema
,
910 "user": string_schema
,
911 "secret": passwd_schema
,
912 "cacert": long_description_schema
,
913 "lxd-cloud": shortname_schema
,
914 "lxd-credentials": shortname_schema
,
915 "k8s-cloud": shortname_schema
,
916 "k8s-credentials": shortname_schema
,
917 "model-config": object_schema
,
919 "additionalProperties": False,
923 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
924 k8srepo_properties
= {
926 "description": description_schema
,
927 "type": k8srepo_types
,
928 "url": description_schema
,
930 k8srepo_new_schema
= {
931 "title": "k8scluster creation input schema",
932 "$schema": "http://json-schema.org/draft-04/schema#",
934 "properties": k8srepo_properties
,
935 "required": ["name", "type", "url"],
936 "additionalProperties": False,
938 k8srepo_edit_schema
= {
939 "title": "vim_account edit input schema",
940 "$schema": "http://json-schema.org/draft-04/schema#",
942 "properties": k8srepo_properties
,
943 "additionalProperties": False,
947 osmrepo_types
= {"enum": ["osm"]}
948 osmrepo_properties
= {
950 "description": description_schema
,
951 "type": osmrepo_types
,
952 "url": description_schema
953 # "user": string_schema,
954 # "password": passwd_schema
956 osmrepo_new_schema
= {
957 "title": "osm repo creation input schema",
958 "$schema": "http://json-schema.org/draft-04/schema#",
960 "properties": osmrepo_properties
,
961 "required": ["name", "type", "url"],
962 "additionalProperties": False,
964 osmrepo_edit_schema
= {
965 "title": "osm repo edit input schema",
966 "$schema": "http://json-schema.org/draft-04/schema#",
968 "properties": osmrepo_properties
,
969 "additionalProperties": False,
976 "name": shortname_schema
,
978 "type": {"enum": ["overlay", "underlay"]},
979 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
980 # TODO, add user, password, ssh-key
981 "mac-address": mac_schema
,
982 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
983 "vim-network-id": shortname_schema
,
984 # # provide this in case SDN assist must deal with this interface
985 # "switch-dpid": dpid_Schema,
986 # "switch-port": shortname_schema,
987 # "switch-mac": shortname_schema,
988 # "switch-vlan": vlan_schema,
990 "required": ["name", "mgmt", "ip-address"],
991 "additionalProperties": False,
994 "title": "pdu creation input schema",
995 "$schema": "http://json-schema.org/draft-04/schema#",
998 "name": shortname_schema
,
999 "type": shortname_schema
,
1000 "description": description_schema
,
1001 "shared": bool_schema
,
1002 "vims": nameshort_list_schema
,
1003 "vim_accounts": nameshort_list_schema
,
1004 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
1006 "required": ["name", "type", "interfaces"],
1007 "additionalProperties": False,
1010 "title": "pdu edit input schema",
1011 "$schema": "http://json-schema.org/draft-04/schema#",
1014 "name": shortname_schema
,
1015 "type": shortname_schema
,
1016 "description": description_schema
,
1017 "shared": bool_schema
,
1018 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1019 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1022 array_edition_schema
,
1023 {"type": "array", "items": pdu_interface
, "minItems": 1},
1027 "additionalProperties": False,
1031 # VNF PKG OPERATIONS
1032 vnfpkgop_new_schema
= {
1033 "title": "VNF PKG operation creation input schema",
1034 "$schema": "http://json-schema.org/draft-04/schema#",
1037 "lcmOperationType": string_schema
,
1038 "vnfPkgId": id_schema
,
1039 "kdu_name": name_schema
,
1040 "primitive": name_schema
,
1041 "primitive_params": {"type": "object"},
1050 "additionalProperties": False,
1054 project_role_mappings
= {
1055 "title": "list pf projects/roles",
1056 "$schema": "http://json-schema.org/draft-04/schema#",
1060 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1061 "required": ["project", "role"],
1062 "additionalProperties": False,
1066 project_role_mappings_optional
= {
1067 "title": "list of projects/roles or projects only",
1068 "$schema": "http://json-schema.org/draft-04/schema#",
1072 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1073 "required": ["project"],
1074 "additionalProperties": False,
1079 "$schema": "http://json-schema.org/draft-04/schema#",
1080 "title": "New user schema",
1083 "username": string_schema
,
1084 "domain_name": shortname_schema
,
1085 "password": passwd_schema
,
1086 "projects": nameshort_list_schema
,
1087 "project_role_mappings": project_role_mappings
,
1089 "required": ["username", "password"],
1090 "additionalProperties": False,
1092 user_edit_schema
= {
1093 "$schema": "http://json-schema.org/draft-04/schema#",
1094 "title": "User edit schema for administrators",
1097 "password": passwd_schema
,
1098 "old_password": passwd_schema
,
1099 "username": string_schema
, # To allow User Name modification
1100 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
1101 "project_role_mappings": project_role_mappings
,
1102 "add_project_role_mappings": project_role_mappings
,
1103 "remove_project_role_mappings": project_role_mappings_optional
,
1106 "additionalProperties": False,
1110 topics_with_quota
= [
1126 project_new_schema
= {
1127 "$schema": "http://json-schema.org/draft-04/schema#",
1128 "title": "New project schema for administrators",
1131 "name": shortname_schema
,
1132 "admin": bool_schema
,
1133 "domain_name": shortname_schema
,
1136 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
1137 "additionalProperties": False,
1140 "required": ["name"],
1141 "additionalProperties": False,
1143 project_edit_schema
= {
1144 "$schema": "http://json-schema.org/draft-04/schema#",
1145 "title": "Project edit schema for administrators",
1148 "admin": bool_schema
,
1149 "name": shortname_schema
, # To allow Project Name modification
1153 topic
: {"oneOf": [integer0_schema
, null_schema
]}
1154 for topic
in topics_with_quota
1156 "additionalProperties": False,
1159 "additionalProperties": False,
1164 roles_new_schema
= {
1165 "$schema": "http://json-schema.org/draft-04/schema#",
1166 "title": "New role schema for administrators",
1169 "name": shortname_schema
,
1172 "patternProperties": {
1175 # "minProperties": 1,
1178 "required": ["name"],
1179 "additionalProperties": False,
1181 roles_edit_schema
= {
1182 "$schema": "http://json-schema.org/draft-04/schema#",
1183 "title": "Roles edit schema for administrators",
1186 "name": shortname_schema
,
1189 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1190 # "minProperties": 1,
1193 "additionalProperties": False,
1199 nbi_new_input_schemas
= {
1200 "users": user_new_schema
,
1201 "projects": project_new_schema
,
1202 "vim_accounts": vim_account_new_schema
,
1203 "sdns": sdn_new_schema
,
1204 "ns_instantiate": ns_instantiate
,
1205 "ns_action": ns_action
,
1206 "ns_scale": ns_scale
,
1207 "ns_update": ns_update
,
1209 "pdus": pdu_new_schema
,
1212 nbi_edit_input_schemas
= {
1213 "users": user_edit_schema
,
1214 "projects": project_edit_schema
,
1215 "vim_accounts": vim_account_edit_schema
,
1216 "sdns": sdn_edit_schema
,
1217 "pdus": pdu_edit_schema
,
1221 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1222 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1223 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1224 del nsi_subnet_instantiate
["required"]
1226 nsi_vld_instantiate
= {
1227 "title": "netslice vld instantiation params input schema",
1228 "$schema": "http://json-schema.org/draft-04/schema#",
1231 "name": string_schema
,
1232 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1233 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1234 "ip-profile": object_schema
,
1236 "required": ["name"],
1237 "additionalProperties": False,
1241 "title": "netslice action instantiate input schema",
1242 "$schema": "http://json-schema.org/draft-04/schema#",
1245 "lcmOperationType": string_schema
,
1246 "netsliceInstanceId": id_schema
,
1247 "nsiName": name_schema
,
1248 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1249 "nstId": string_schema
,
1250 "vimAccountId": id_schema
,
1251 "timeout_nsi_deploy": integer1_schema
,
1252 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1253 "nsi_id": id_schema
,
1254 "additionalParamsForNsi": object_schema
,
1255 "netslice-subnet": {
1258 "items": nsi_subnet_instantiate
,
1260 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1262 "required": ["nsiName", "nstId", "vimAccountId"],
1263 "additionalProperties": False,
1270 nsinstancesubscriptionfilter_schema
= {
1271 "title": "instance identifier schema",
1272 "$schema": "http://json-schema.org/draft-07/schema#",
1275 "nsdIds": {"type": "array"},
1276 "vnfdIds": {"type": "array"},
1277 "pnfdIds": {"type": "array"},
1278 "nsInstanceIds": {"type": "array"},
1279 "nsInstanceNames": {"type": "array"},
1284 "title": "nslcmsubscription input schema",
1285 "$schema": "http://json-schema.org/draft-07/schema#",
1288 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1289 "notificationTypes": {
1293 "NsLcmOperationOccurrenceNotification",
1294 "NsChangeNotification",
1295 "NsIdentifierCreationNotification",
1296 "NsIdentifierDeletionNotification",
1302 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1304 "operationStates": {
1310 "PARTIALLY_COMPLETED",
1318 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1319 "lcmOpNameImpactingNsComponent": {
1325 "VNF_SCALE_TO_LEVEL",
1326 "VNF_CHANGE_FLAVOUR",
1330 "VNF_CHANGE_EXT_CONN",
1340 "lcmOpOccStatusImpactingNsComponent": {
1346 "PARTIALLY_COMPLETED",
1357 "notificationTypes": {
1358 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1364 {"required": ["operationTypes"]},
1365 {"required": ["operationStates"]},
1372 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1377 {"required": ["nsComponentTypes"]},
1378 {"required": ["lcmOpNameImpactingNsComponent"]},
1379 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1386 authentication_schema
= {
1387 "title": "authentication schema for subscription",
1388 "$schema": "http://json-schema.org/draft-07/schema#",
1391 "authType": {"enum": ["basic"]},
1395 "userName": string_schema
,
1396 "password": passwd_schema
,
1403 "title": "subscription input schema",
1404 "$schema": "http://json-schema.org/draft-07/schema#",
1407 "filter": nslcmsub_schema
,
1408 "CallbackUri": description_schema
,
1409 "authentication": authentication_schema
,
1411 "required": ["CallbackUri"],
1414 vnflcmsub_schema
= {
1415 "title": "vnflcmsubscription input schema",
1416 "$schema": "http://json-schema.org/draft-07/schema#",
1419 "VnfInstanceSubscriptionFilter": {
1422 "vnfdIds": {"type": "array"},
1423 "vnfInstanceIds": {"type": "array"},
1426 "notificationTypes": {
1430 "VnfIdentifierCreationNotification",
1431 "VnfLcmOperationOccurrenceNotification",
1432 "VnfIdentifierDeletionNotification",
1450 "REVERT_TO_SNAPSHOT",
1455 "operationStates": {
1470 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1473 vnf_subscription
= {
1474 "title": "vnf subscription input schema",
1475 "$schema": "http://json-schema.org/draft-07/schema#",
1478 "filter": vnflcmsub_schema
,
1479 "CallbackUri": description_schema
,
1480 "authentication": authentication_schema
,
1482 "required": ["filter", "CallbackUri"],
1486 class ValidationError(Exception):
1487 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1488 self
.http_code
= http_code
1489 Exception.__init
__(self
, message
)
1492 def validate_input(indata
, schema_to_use
):
1494 Validates input data against json schema
1495 :param indata: user input data. Should be a dictionary
1496 :param schema_to_use: jsonschema to test
1497 :return: None if ok, raises ValidationError exception on error
1501 js_v(indata
, schema_to_use
)
1503 except js_e
.ValidationError
as e
:
1505 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1508 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1509 except js_e
.SchemaError
:
1510 raise ValidationError(
1511 "Bad json schema {}".format(schema_to_use
),
1512 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1516 def is_valid_uuid(x
):
1518 Test for a valid UUID
1519 :param x: string to test
1520 :return: True if x is a valid uuid, False otherwise
1525 except (TypeError, ValueError, AttributeError):