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": {
143 "vim-flavor-id": name_schema
,
151 "vim-volume-id": name_schema
,
153 "required": ["name", "vim-volume-id"],
154 "additionalProperties": False,
164 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
165 "mac-address": mac_schema
,
166 "floating-ip-required": bool_schema
,
168 "required": ["name"],
169 "additionalProperties": False,
174 "additionalProperties": False,
177 ip_profile_dns_schema
= {
183 "address": {"oneOf": [ip_schema
, ipv6_schema
]},
185 "required": ["address"],
186 "additionalProperties": False,
190 ip_profile_dhcp_schema
= {
193 "enabled": {"type": "boolean"},
194 "count": integer1_schema
,
195 "start-address": ip_schema
,
197 "additionalProperties": False,
200 ip_profile_schema
= {
201 "title": "ip profile validation schema",
202 "$schema": "http://json-schema.org/draft-04/schema#",
205 "ip-version": {"enum": ["ipv4", "ipv6"]},
206 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
207 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
208 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
209 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
211 "additionalProperties": False,
214 provider_network_schema
= {
215 "title": "provider network validation schema",
216 "$schema": "http://json-schema.org/draft-04/schema#",
219 "physical-network": name_schema
,
220 "segmentation-id": name_schema
,
221 "sdn-ports": { # external ports to append to the SDN-assist network
226 "switch_id": shortname_schema
,
227 "switch_port": shortname_schema
,
228 "mac_address": mac_schema
,
231 "additionalProperties": True,
234 "network-type": shortname_schema
,
236 "additionalProperties": True,
239 ns_instantiate_internal_vld
= {
240 "title": "ns action instantiate input schema for vld",
241 "$schema": "http://json-schema.org/draft-04/schema#",
245 "vim-network-name": name_schema
,
246 "vim-network-id": name_schema
,
247 "ip-profile": ip_profile_schema
,
248 "provider-network": provider_network_schema
,
249 "internal-connection-point": {
255 "id-ref": name_schema
,
256 "ip-address": ip_schema
,
257 # "mac-address": mac_schema,
259 "required": ["id-ref"],
261 "additionalProperties": False,
265 "required": ["name"],
267 "additionalProperties": False,
270 additional_params_for_vnf
= {
275 "member-vnf-index": name_schema
,
276 "additionalParams": object_schema
,
277 "k8s-namespace": name_schema
,
278 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
279 "additionalParamsForVdu": {
284 "vdu_id": name_schema
,
285 "additionalParams": object_schema
,
286 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
288 "required": ["vdu_id"],
290 "additionalProperties": False,
293 "additionalParamsForKdu": {
298 "kdu_name": name_schema
,
299 "additionalParams": object_schema
,
300 "kdu_model": name_schema
,
301 "k8s-namespace": name_schema
,
302 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
303 "kdu-deployment-name": name_schema
,
305 "required": ["kdu_name"],
307 "additionalProperties": False,
310 "affinity-or-anti-affinity-group": {
316 "vim-affinity-group-id": name_schema
,
320 "additionalProperties": False,
324 "required": ["member-vnf-index"],
326 "additionalProperties": False,
331 "title": "ns action instantiate input schema",
332 "$schema": "http://json-schema.org/draft-04/schema#",
335 "lcmOperationType": string_schema
,
336 "nsInstanceId": id_schema
,
337 "netsliceInstanceId": id_schema
,
338 "nsName": name_schema
,
339 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
341 "vimAccountId": id_schema
,
342 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
343 "placement-engine": string_schema
,
344 "placement-constraints": object_schema
,
345 "additionalParamsForNs": object_schema
,
346 "additionalParamsForVnf": additional_params_for_vnf
,
347 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
348 "k8s-namespace": name_schema
,
349 "ssh_keys": {"type": "array", "items": {"type": "string"}},
350 "timeout_ns_deploy": integer1_schema
,
352 "vduImage": name_schema
,
359 "member-vnf-index": name_schema
,
360 "vimAccountId": id_schema
,
364 "items": ns_instantiate_vdu
,
369 "items": ns_instantiate_internal_vld
,
372 "required": ["member-vnf-index"],
374 "additionalProperties": False,
383 "name": string_schema
,
384 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
385 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
386 "ns-net": object_schema
,
387 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
388 "ip-profile": ip_profile_schema
,
389 "provider-network": provider_network_schema
,
390 "vnfd-connection-point-ref": {
396 "member-vnf-index-ref": name_schema
,
397 "vnfd-connection-point-ref": name_schema
,
398 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
399 # "mac-address": mac_schema,
402 "member-vnf-index-ref",
403 "vnfd-connection-point-ref",
406 "additionalProperties": False,
410 "required": ["name"],
411 "additionalProperties": False,
415 "required": ["nsName", "nsdId", "vimAccountId"],
416 "additionalProperties": False,
420 "title": "ns terminate input schema",
421 "$schema": "http://json-schema.org/draft-04/schema#",
424 "lcmOperationType": string_schema
,
425 "nsInstanceId": id_schema
,
426 "autoremove": bool_schema
,
427 "timeout_ns_terminate": integer1_schema
,
428 "skip_terminate_primitives": bool_schema
,
429 "netsliceInstanceId": id_schema
,
431 "additionalProperties": False,
435 "title": "ns update input schema",
436 "$schema": "http://json-schema.org/draft-04/schema#",
439 "lcmOperationType": string_schema
,
440 "nsInstanceId": id_schema
,
441 "timeout_ns_update": integer1_schema
,
446 "MODIFY_VNF_INFORMATION",
450 "modifyVnfInfoData": {
453 "vnfInstanceId": id_schema
,
456 "required": ["vnfInstanceId", "vnfdId"],
458 "removeVnfInstanceId": id_schema
,
459 "changeVnfPackageData": {
462 "vnfInstanceId": id_schema
,
465 "required": ["vnfInstanceId", "vnfdId"],
470 "vnfInstanceId": id_schema
,
471 "changeStateTo": name_schema
,
475 "run-day1": bool_schema
,
476 "vdu_id": name_schema
,
477 "count-index": integer0_schema
,
479 "required": ["vdu_id", "count-index"],
480 "additionalProperties": False,
483 "required": ["vnfInstanceId", "changeStateTo"],
486 "required": ["updateType"],
487 "additionalProperties": False,
490 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
491 "title": "ns action input schema",
492 "$schema": "http://json-schema.org/draft-04/schema#",
495 "lcmOperationType": string_schema
,
496 "nsInstanceId": id_schema
,
497 "member_vnf_index": name_schema
,
498 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
499 "vdu_id": name_schema
,
500 "vdu_count_index": integer0_schema
,
501 "kdu_name": name_schema
,
502 "primitive": name_schema
,
503 "timeout_ns_action": integer1_schema
,
504 "primitive_params": {"type": "object"},
506 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
507 "additionalProperties": False,
510 ns_scale
= { # TODO for the moment it is only VDU-scaling
511 "title": "ns scale input schema",
512 "$schema": "http://json-schema.org/draft-04/schema#",
515 "lcmOperationType": string_schema
,
516 "nsInstanceId": id_schema
,
517 "scaleType": {"enum": ["SCALE_VNF"]},
518 "timeout_ns_scale": integer1_schema
,
522 "vnfInstanceId": name_schema
,
523 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
527 "scaling-group-descriptor": name_schema
,
528 "member-vnf-index": name_schema
,
529 "scaling-policy": name_schema
,
531 "required": ["scaling-group-descriptor", "member-vnf-index"],
532 "additionalProperties": False,
535 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
536 "additionalProperties": False,
538 "scaleTime": time_schema
,
540 "required": ["scaleType", "scaleVnfData"],
541 "additionalProperties": False,
545 "title": "ns migrate input schema",
546 "$schema": "http://json-schema.org/draft-04/schema#",
549 "lcmOperationType": string_schema
,
550 "nsInstanceId": id_schema
,
551 "vnfInstanceId": id_schema
,
552 "migrateToHost": string_schema
,
556 "vduId": name_schema
,
557 "vduCountIndex": integer0_schema
,
559 "required": ["vduId"],
560 "additionalProperties": False,
563 "required": ["vnfInstanceId"],
564 "additionalProperties": False,
568 "title": "ns heal input schema",
569 "$schema": "http://json-schema.org/draft-04/schema#",
572 "lcmOperationType": string_schema
,
573 "nsInstanceId": id_schema
,
574 "timeout_ns_heal": integer1_schema
,
580 "vnfInstanceId": id_schema
,
581 "cause": description_schema
,
582 "additionalParams": {
585 "run-day1": bool_schema
,
591 "run-day1": bool_schema
,
592 "vdu-id": name_schema
,
593 "count-index": integer0_schema
,
595 "required": ["vdu-id"],
596 "additionalProperties": False,
600 "additionalProperties": False,
603 "required": ["vnfInstanceId"],
604 "additionalProperties": False,
608 "required": ["healVnfData"],
609 "additionalProperties": False,
613 "title": "vertial scale input schema",
614 "$schema": "http://json-schema.org/draft-04/schema#",
617 "lcmOperationType": string_schema
,
618 "verticalScale": string_schema
,
619 "nsInstanceId": id_schema
,
620 "changeVnfFlavorData": {
623 "vnfInstanceId": id_schema
,
624 "additionalParams": {
627 "vduid": string_schema
,
628 "vduCountIndex": integer0_schema
,
629 "virtualMemory": integer1_schema
,
630 "sizeOfStorage": integer0_schema
,
631 "numVirtualCpu": integer1_schema
,
635 "required": ["vnfInstanceId", "additionalParams"],
636 "additionalProperties": False,
639 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
640 "additionalProperties": False,
643 schema_version
= {"type": "string", "enum": ["1.0"]}
644 schema_type
= {"type": "string"}
645 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
647 vim_account_edit_schema
= {
648 "title": "vim_account edit input schema",
649 "$schema": "http://json-schema.org/draft-04/schema#",
653 "description": description_schema
,
655 "datacenter": name_schema
,
656 "vim_type": vim_type
,
657 "vim_url": description_schema
,
658 # "vim_url_admin": description_schema,
659 # "vim_tenant": name_schema,
660 "vim_tenant_name": name_schema
,
661 "vim_user": string_schema
,
662 "vim_password": passwd_schema
,
664 "config": {"type": "object"},
665 "prometheus-config": {"type": "object"},
667 "additionalProperties": False,
670 vim_account_new_schema
= {
671 "title": "vim_account creation input schema",
672 "$schema": "http://json-schema.org/draft-04/schema#",
675 "schema_version": schema_version
,
676 "schema_type": schema_type
,
678 "description": description_schema
,
680 "datacenter": name_schema
,
681 "vim_type": vim_type
,
682 "vim_url": description_schema
,
683 # "vim_url_admin": description_schema,
684 # "vim_tenant": name_schema,
685 "vim_tenant_name": name_schema
,
686 "vim_user": string_schema
,
687 "vim_password": passwd_schema
,
689 "config": {"type": "object"},
690 "prometheus-config": {"type": "object"},
700 "additionalProperties": False,
703 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
705 wim_account_edit_schema
= {
706 "title": "wim_account edit input schema",
707 "$schema": "http://json-schema.org/draft-04/schema#",
711 "description": description_schema
,
713 "wim_type": wim_type
,
714 "wim_url": description_schema
,
715 "user": string_schema
,
716 "password": passwd_schema
,
717 "config": {"type": "object"},
719 "additionalProperties": False,
722 wim_account_new_schema
= {
723 "title": "wim_account creation input schema",
724 "$schema": "http://json-schema.org/draft-04/schema#",
727 "schema_version": schema_version
,
728 "schema_type": schema_type
,
730 "description": description_schema
,
732 "wim_type": wim_type
,
733 "wim_url": description_schema
,
734 "user": string_schema
,
735 "password": passwd_schema
,
738 "patternProperties": {".": {"not": {"type": "null"}}},
741 "required": ["name", "wim_url", "wim_type"],
742 "additionalProperties": False,
747 "type": {"type": "string"},
748 "url": {"type": "string"},
749 "user": string_schema
,
750 "password": passwd_schema
,
751 "config": {"type": "object"},
752 "description": description_schema
,
753 # The folowing are deprecated. Maintanied for backward compatibility
757 "version": {"type": "string", "minLength": 1, "maxLength": 12},
760 "title": "sdn controller information schema",
761 "$schema": "http://json-schema.org/draft-04/schema#",
763 "properties": sdn_properties
,
764 "required": ["name", "type"],
765 "additionalProperties": False,
768 "title": "sdn controller update information schema",
769 "$schema": "http://json-schema.org/draft-04/schema#",
771 "properties": sdn_properties
,
772 # "required": ["name", "port", 'ip', 'dpid', 'type'],
773 "additionalProperties": False,
775 sdn_port_mapping_schema
= {
776 "$schema": "http://json-schema.org/draft-04/schema#",
777 "title": "sdn port mapping information schema",
782 "compute_node": shortname_schema
,
788 "pci": pci_extended_schema
,
789 "switch_port": shortname_schema
,
790 "switch_mac": mac_schema
,
796 "required": ["compute_node", "ports"],
799 sdn_external_port_schema
= {
800 "$schema": "http://json-schema.org/draft-04/schema#",
801 "title": "External port information",
804 "port": {"type": "string", "minLength": 1, "maxLength": 60},
808 "required": ["port"],
812 k8scluster_deploy_method_schema
= {
813 "$schema": "http://json-schema.org/draft-04/schema#",
814 "title": "Deployment methods for K8s cluster",
817 "helm-chart": {"type": "boolean"},
818 "juju-bundle": {"type": "boolean"},
819 "helm-chart-v3": {"type": "boolean"},
821 "additionalProperties": False,
824 k8scluster_nets_schema
= {
825 "title": "k8scluster nets input schema",
826 "$schema": "http://json-schema.org/draft-04/schema#",
828 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
830 "additionalProperties": False,
832 k8scluster_new_schema
= {
833 "title": "k8scluster creation input schema",
834 "$schema": "http://json-schema.org/draft-04/schema#",
837 "schema_version": schema_version
,
838 "schema_type": schema_type
,
840 "description": description_schema
,
841 "credentials": object_schema
,
842 "vim_account": id_schema
,
844 "k8s_version": string_schema
,
845 "nets": k8scluster_nets_schema
,
846 "deployment_methods": k8scluster_deploy_method_schema
,
847 "namespace": name_schema
,
848 "cni": nameshort_list_schema
,
850 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
851 "additionalProperties": False,
853 k8scluster_edit_schema
= {
854 "title": "vim_account edit input schema",
855 "$schema": "http://json-schema.org/draft-04/schema#",
859 "description": description_schema
,
860 "credentials": object_schema
,
861 "vim_account": id_schema
,
863 "k8s_version": string_schema
,
864 "nets": k8scluster_nets_schema
,
865 "namespace": name_schema
,
866 "cni": nameshort_list_schema
,
868 "additionalProperties": False,
873 "title": "vca creation input schema",
874 "$schema": "http://json-schema.org/draft-04/schema#",
877 "schema_version": schema_version
,
878 "schema_type": schema_type
,
880 "description": description_schema
,
881 "endpoints": description_list_schema
,
882 "user": string_schema
,
883 "secret": passwd_schema
,
884 "cacert": long_description_schema
,
885 "lxd-cloud": shortname_schema
,
886 "lxd-credentials": shortname_schema
,
887 "k8s-cloud": shortname_schema
,
888 "k8s-credentials": shortname_schema
,
889 "model-config": object_schema
,
902 "additionalProperties": False,
905 "title": "vca creation input schema",
906 "$schema": "http://json-schema.org/draft-04/schema#",
910 "description": description_schema
,
911 "endpoints": description_list_schema
,
912 "port": integer1_schema
,
913 "user": string_schema
,
914 "secret": passwd_schema
,
915 "cacert": long_description_schema
,
916 "lxd-cloud": shortname_schema
,
917 "lxd-credentials": shortname_schema
,
918 "k8s-cloud": shortname_schema
,
919 "k8s-credentials": shortname_schema
,
920 "model-config": object_schema
,
922 "additionalProperties": False,
926 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
927 k8srepo_properties
= {
929 "description": description_schema
,
930 "type": k8srepo_types
,
931 "url": description_schema
,
933 k8srepo_new_schema
= {
934 "title": "k8scluster creation input schema",
935 "$schema": "http://json-schema.org/draft-04/schema#",
937 "properties": k8srepo_properties
,
938 "required": ["name", "type", "url"],
939 "additionalProperties": False,
941 k8srepo_edit_schema
= {
942 "title": "vim_account edit input schema",
943 "$schema": "http://json-schema.org/draft-04/schema#",
945 "properties": k8srepo_properties
,
946 "additionalProperties": False,
950 osmrepo_types
= {"enum": ["osm"]}
951 osmrepo_properties
= {
953 "description": description_schema
,
954 "type": osmrepo_types
,
955 "url": description_schema
956 # "user": string_schema,
957 # "password": passwd_schema
959 osmrepo_new_schema
= {
960 "title": "osm repo creation input schema",
961 "$schema": "http://json-schema.org/draft-04/schema#",
963 "properties": osmrepo_properties
,
964 "required": ["name", "type", "url"],
965 "additionalProperties": False,
967 osmrepo_edit_schema
= {
968 "title": "osm repo edit input schema",
969 "$schema": "http://json-schema.org/draft-04/schema#",
971 "properties": osmrepo_properties
,
972 "additionalProperties": False,
979 "name": shortname_schema
,
981 "type": {"enum": ["overlay", "underlay"]},
982 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
983 # TODO, add user, password, ssh-key
984 "mac-address": mac_schema
,
985 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
986 "vim-network-id": shortname_schema
,
987 # # provide this in case SDN assist must deal with this interface
988 # "switch-dpid": dpid_Schema,
989 # "switch-port": shortname_schema,
990 # "switch-mac": shortname_schema,
991 # "switch-vlan": vlan_schema,
993 "required": ["name", "mgmt", "ip-address"],
994 "additionalProperties": False,
997 "title": "pdu creation input schema",
998 "$schema": "http://json-schema.org/draft-04/schema#",
1001 "name": shortname_schema
,
1002 "type": shortname_schema
,
1003 "description": description_schema
,
1004 "shared": bool_schema
,
1005 "vims": nameshort_list_schema
,
1006 "vim_accounts": nameshort_list_schema
,
1007 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
1009 "required": ["name", "type", "interfaces"],
1010 "additionalProperties": False,
1013 "title": "pdu edit input schema",
1014 "$schema": "http://json-schema.org/draft-04/schema#",
1017 "name": shortname_schema
,
1018 "type": shortname_schema
,
1019 "description": description_schema
,
1020 "shared": bool_schema
,
1021 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1022 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
1025 array_edition_schema
,
1026 {"type": "array", "items": pdu_interface
, "minItems": 1},
1030 "additionalProperties": False,
1034 # VNF PKG OPERATIONS
1035 vnfpkgop_new_schema
= {
1036 "title": "VNF PKG operation creation input schema",
1037 "$schema": "http://json-schema.org/draft-04/schema#",
1040 "lcmOperationType": string_schema
,
1041 "vnfPkgId": id_schema
,
1042 "kdu_name": name_schema
,
1043 "primitive": name_schema
,
1044 "primitive_params": {"type": "object"},
1053 "additionalProperties": False,
1057 project_role_mappings
= {
1058 "title": "list pf projects/roles",
1059 "$schema": "http://json-schema.org/draft-04/schema#",
1063 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1064 "required": ["project", "role"],
1065 "additionalProperties": False,
1069 project_role_mappings_optional
= {
1070 "title": "list of projects/roles or projects only",
1071 "$schema": "http://json-schema.org/draft-04/schema#",
1075 "properties": {"project": shortname_schema
, "role": shortname_schema
},
1076 "required": ["project"],
1077 "additionalProperties": False,
1082 "$schema": "http://json-schema.org/draft-04/schema#",
1083 "title": "New user schema",
1086 "username": string_schema
,
1087 "domain_name": shortname_schema
,
1088 "password": passwd_schema
,
1089 "projects": nameshort_list_schema
,
1090 "project_role_mappings": project_role_mappings
,
1092 "required": ["username", "password"],
1093 "additionalProperties": False,
1095 user_edit_schema
= {
1096 "$schema": "http://json-schema.org/draft-04/schema#",
1097 "title": "User edit schema for administrators",
1100 "password": passwd_schema
,
1101 "old_password": passwd_schema
,
1102 "username": string_schema
, # To allow User Name modification
1103 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
1104 "project_role_mappings": project_role_mappings
,
1105 "add_project_role_mappings": project_role_mappings
,
1106 "remove_project_role_mappings": project_role_mappings_optional
,
1109 "additionalProperties": False,
1113 topics_with_quota
= [
1129 project_new_schema
= {
1130 "$schema": "http://json-schema.org/draft-04/schema#",
1131 "title": "New project schema for administrators",
1134 "name": shortname_schema
,
1135 "admin": bool_schema
,
1136 "domain_name": shortname_schema
,
1139 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
1140 "additionalProperties": False,
1143 "required": ["name"],
1144 "additionalProperties": False,
1146 project_edit_schema
= {
1147 "$schema": "http://json-schema.org/draft-04/schema#",
1148 "title": "Project edit schema for administrators",
1151 "admin": bool_schema
,
1152 "name": shortname_schema
, # To allow Project Name modification
1156 topic
: {"oneOf": [integer0_schema
, null_schema
]}
1157 for topic
in topics_with_quota
1159 "additionalProperties": False,
1162 "additionalProperties": False,
1167 roles_new_schema
= {
1168 "$schema": "http://json-schema.org/draft-04/schema#",
1169 "title": "New role schema for administrators",
1172 "name": shortname_schema
,
1175 "patternProperties": {
1178 # "minProperties": 1,
1181 "required": ["name"],
1182 "additionalProperties": False,
1184 roles_edit_schema
= {
1185 "$schema": "http://json-schema.org/draft-04/schema#",
1186 "title": "Roles edit schema for administrators",
1189 "name": shortname_schema
,
1192 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1193 # "minProperties": 1,
1196 "additionalProperties": False,
1202 nbi_new_input_schemas
= {
1203 "users": user_new_schema
,
1204 "projects": project_new_schema
,
1205 "vim_accounts": vim_account_new_schema
,
1206 "sdns": sdn_new_schema
,
1207 "ns_instantiate": ns_instantiate
,
1208 "ns_action": ns_action
,
1209 "ns_scale": ns_scale
,
1210 "ns_update": ns_update
,
1212 "pdus": pdu_new_schema
,
1215 nbi_edit_input_schemas
= {
1216 "users": user_edit_schema
,
1217 "projects": project_edit_schema
,
1218 "vim_accounts": vim_account_edit_schema
,
1219 "sdns": sdn_edit_schema
,
1220 "pdus": pdu_edit_schema
,
1224 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1225 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1226 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1227 del nsi_subnet_instantiate
["required"]
1229 nsi_vld_instantiate
= {
1230 "title": "netslice vld instantiation params input schema",
1231 "$schema": "http://json-schema.org/draft-04/schema#",
1234 "name": string_schema
,
1235 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1236 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1237 "ip-profile": object_schema
,
1239 "required": ["name"],
1240 "additionalProperties": False,
1244 "title": "netslice action instantiate input schema",
1245 "$schema": "http://json-schema.org/draft-04/schema#",
1248 "lcmOperationType": string_schema
,
1249 "netsliceInstanceId": id_schema
,
1250 "nsiName": name_schema
,
1251 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1252 "nstId": string_schema
,
1253 "vimAccountId": id_schema
,
1254 "timeout_nsi_deploy": integer1_schema
,
1255 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1256 "nsi_id": id_schema
,
1257 "additionalParamsForNsi": object_schema
,
1258 "netslice-subnet": {
1261 "items": nsi_subnet_instantiate
,
1263 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1265 "required": ["nsiName", "nstId", "vimAccountId"],
1266 "additionalProperties": False,
1273 nsinstancesubscriptionfilter_schema
= {
1274 "title": "instance identifier schema",
1275 "$schema": "http://json-schema.org/draft-07/schema#",
1278 "nsdIds": {"type": "array"},
1279 "vnfdIds": {"type": "array"},
1280 "pnfdIds": {"type": "array"},
1281 "nsInstanceIds": {"type": "array"},
1282 "nsInstanceNames": {"type": "array"},
1287 "title": "nslcmsubscription input schema",
1288 "$schema": "http://json-schema.org/draft-07/schema#",
1291 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1292 "notificationTypes": {
1296 "NsLcmOperationOccurrenceNotification",
1297 "NsChangeNotification",
1298 "NsIdentifierCreationNotification",
1299 "NsIdentifierDeletionNotification",
1305 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1307 "operationStates": {
1313 "PARTIALLY_COMPLETED",
1321 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1322 "lcmOpNameImpactingNsComponent": {
1328 "VNF_SCALE_TO_LEVEL",
1329 "VNF_CHANGE_FLAVOUR",
1333 "VNF_CHANGE_EXT_CONN",
1343 "lcmOpOccStatusImpactingNsComponent": {
1349 "PARTIALLY_COMPLETED",
1360 "notificationTypes": {
1361 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1367 {"required": ["operationTypes"]},
1368 {"required": ["operationStates"]},
1375 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1380 {"required": ["nsComponentTypes"]},
1381 {"required": ["lcmOpNameImpactingNsComponent"]},
1382 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1389 authentication_schema
= {
1390 "title": "authentication schema for subscription",
1391 "$schema": "http://json-schema.org/draft-07/schema#",
1394 "authType": {"enum": ["basic"]},
1398 "userName": string_schema
,
1399 "password": passwd_schema
,
1406 "title": "subscription input schema",
1407 "$schema": "http://json-schema.org/draft-07/schema#",
1410 "filter": nslcmsub_schema
,
1411 "CallbackUri": description_schema
,
1412 "authentication": authentication_schema
,
1414 "required": ["CallbackUri"],
1417 vnflcmsub_schema
= {
1418 "title": "vnflcmsubscription input schema",
1419 "$schema": "http://json-schema.org/draft-07/schema#",
1422 "VnfInstanceSubscriptionFilter": {
1425 "vnfdIds": {"type": "array"},
1426 "vnfInstanceIds": {"type": "array"},
1429 "notificationTypes": {
1433 "VnfIdentifierCreationNotification",
1434 "VnfLcmOperationOccurrenceNotification",
1435 "VnfIdentifierDeletionNotification",
1453 "REVERT_TO_SNAPSHOT",
1458 "operationStates": {
1473 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1476 vnf_subscription
= {
1477 "title": "vnf subscription input schema",
1478 "$schema": "http://json-schema.org/draft-07/schema#",
1481 "filter": vnflcmsub_schema
,
1482 "CallbackUri": description_schema
,
1483 "authentication": authentication_schema
,
1485 "required": ["filter", "CallbackUri"],
1489 class ValidationError(Exception):
1490 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1491 self
.http_code
= http_code
1492 Exception.__init
__(self
, message
)
1495 def validate_input(indata
, schema_to_use
):
1497 Validates input data against json schema
1498 :param indata: user input data. Should be a dictionary
1499 :param schema_to_use: jsonschema to test
1500 :return: None if ok, raises ValidationError exception on error
1504 js_v(indata
, schema_to_use
)
1506 except js_e
.ValidationError
as e
:
1508 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1511 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1512 except js_e
.SchemaError
:
1513 raise ValidationError(
1514 "Bad json schema {}".format(schema_to_use
),
1515 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1519 def is_valid_uuid(x
):
1521 Test for a valid UUID
1522 :param x: string to test
1523 :return: True if x is a valid uuid, False otherwise
1528 except (TypeError, ValueError, AttributeError):