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": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
100 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
102 port_schema
= {"type": "integer", "minimum": 1, "maximum": 65534}
103 object_schema
= {"type": "object"}
104 schema_version_2
= {"type": "integer", "minimum": 2, "maximum": 2}
105 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
108 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
110 checksum_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
111 size_schema
= {"type": "integer", "minimum": 1, "maximum": 100}
112 array_edition_schema
= {
114 "patternProperties": {"^\\$": {}},
115 "additionalProperties": False,
118 nameshort_list_schema
= {
121 "items": shortname_schema
,
124 description_list_schema
= {
127 "items": description_schema
,
130 ns_instantiate_vdu
= {
131 "title": "ns action instantiate input schema for vdu",
132 "$schema": "http://json-schema.org/draft-04/schema#",
143 "vim-volume-id": name_schema
,
145 "required": ["name", "vim-volume-id"],
146 "additionalProperties": False,
156 "ip-address": ip_schema
,
157 "mac-address": mac_schema
,
158 "floating-ip-required": bool_schema
,
160 "required": ["name"],
161 "additionalProperties": False,
166 "additionalProperties": False,
169 ip_profile_dns_schema
= {
175 "address": ip_schema
,
177 "required": ["address"],
178 "additionalProperties": False,
182 ip_profile_dhcp_schema
= {
185 "enabled": {"type": "boolean"},
186 "count": integer1_schema
,
187 "start-address": ip_schema
,
189 "additionalProperties": False,
192 ip_profile_schema
= {
193 "title": "ip profile validation schema",
194 "$schema": "http://json-schema.org/draft-04/schema#",
197 "ip-version": {"enum": ["ipv4", "ipv6"]},
198 "subnet-address": ip_prefix_schema
,
199 "gateway-address": ip_schema
,
200 "dns-server": ip_profile_dns_schema
,
201 "dhcp-params": ip_profile_dhcp_schema
,
205 ip_profile_update_schema
= {
206 "title": "ip profile validation schema",
207 "$schema": "http://json-schema.org/draft-04/schema#",
210 "ip-version": {"enum": ["ipv4", "ipv6"]},
211 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
212 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
213 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
214 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
216 "additionalProperties": False,
219 provider_network_schema
= {
220 "title": "provider network validation schema",
221 "$schema": "http://json-schema.org/draft-04/schema#",
224 "physical-network": name_schema
,
225 "segmentation-id": name_schema
,
226 "sdn-ports": { # external ports to append to the SDN-assist network
231 "switch_id": shortname_schema
,
232 "switch_port": shortname_schema
,
233 "mac_address": mac_schema
,
236 "additionalProperties": True,
239 "network-type": shortname_schema
,
241 "additionalProperties": True,
244 ns_instantiate_internal_vld
= {
245 "title": "ns action instantiate input schema for vdu",
246 "$schema": "http://json-schema.org/draft-04/schema#",
250 "vim-network-name": name_schema
,
251 "vim-network-id": name_schema
,
252 "ip-profile": ip_profile_update_schema
,
253 "provider-network": provider_network_schema
,
254 "internal-connection-point": {
260 "id-ref": name_schema
,
261 "ip-address": ip_schema
,
262 # "mac-address": mac_schema,
264 "required": ["id-ref"],
266 "additionalProperties": False,
270 "required": ["name"],
272 "additionalProperties": False,
275 additional_params_for_vnf
= {
280 "member-vnf-index": name_schema
,
281 "additionalParams": object_schema
,
282 "k8s-namespace": name_schema
,
283 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
284 "additionalParamsForVdu": {
289 "vdu_id": name_schema
,
290 "additionalParams": object_schema
,
291 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
293 "required": ["vdu_id"],
295 "additionalProperties": False,
298 "additionalParamsForKdu": {
303 "kdu_name": name_schema
,
304 "additionalParams": object_schema
,
305 "kdu_model": name_schema
,
306 "k8s-namespace": name_schema
,
307 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
308 "kdu-deployment-name": name_schema
,
310 "required": ["kdu_name"],
312 "additionalProperties": False,
316 "required": ["member-vnf-index"],
318 "additionalProperties": False,
323 "title": "ns action instantiate input schema",
324 "$schema": "http://json-schema.org/draft-04/schema#",
327 "lcmOperationType": string_schema
,
328 "nsInstanceId": id_schema
,
329 "netsliceInstanceId": id_schema
,
330 "nsName": name_schema
,
331 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
334 "vimAccountId": id_schema
,
335 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
336 "placement-engine": string_schema
,
337 "placement-constraints": object_schema
,
338 "additionalParamsForNs": object_schema
,
339 "additionalParamsForVnf": additional_params_for_vnf
,
340 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
341 "k8s-namespace": name_schema
,
342 "ssh_keys": {"type": "array", "items": {"type": "string"}},
343 "timeout_ns_deploy": integer1_schema
,
345 "vduImage": name_schema
,
352 "member-vnf-index": name_schema
,
353 "vimAccountId": id_schema
,
358 "items": ns_instantiate_vdu
,
363 "items": ns_instantiate_internal_vld
,
366 "required": ["member-vnf-index"],
368 "additionalProperties": False,
377 "name": string_schema
,
378 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
379 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
380 "ns-net": object_schema
,
381 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
382 "ip-profile": object_schema
,
383 "provider-network": provider_network_schema
,
384 "vnfd-connection-point-ref": {
390 "member-vnf-index-ref": name_schema
,
391 "vnfd-connection-point-ref": name_schema
,
392 "ip-address": ip_schema
,
393 # "mac-address": mac_schema,
396 "member-vnf-index-ref",
397 "vnfd-connection-point-ref",
400 "additionalProperties": False,
404 "required": ["name"],
405 "additionalProperties": False,
409 "required": ["nsName", "nsdId", "vimAccountId"],
410 "additionalProperties": False,
414 "title": "ns terminate input schema",
415 "$schema": "http://json-schema.org/draft-04/schema#",
418 "lcmOperationType": string_schema
,
419 "nsInstanceId": id_schema
,
420 "autoremove": bool_schema
,
421 "timeout_ns_terminate": integer1_schema
,
422 "skip_terminate_primitives": bool_schema
,
423 "netsliceInstanceId": id_schema
,
425 "additionalProperties": False,
428 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
429 "title": "ns action input schema",
430 "$schema": "http://json-schema.org/draft-04/schema#",
433 "lcmOperationType": string_schema
,
434 "nsInstanceId": id_schema
,
435 "member_vnf_index": name_schema
,
436 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
437 "vdu_id": name_schema
,
438 "vdu_count_index": integer0_schema
,
439 "kdu_name": name_schema
,
440 "primitive": name_schema
,
441 "timeout_ns_action": integer1_schema
,
442 "primitive_params": {"type": "object"},
444 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
445 "additionalProperties": False,
447 ns_scale
= { # TODO for the moment it is only VDU-scaling
448 "title": "ns scale input schema",
449 "$schema": "http://json-schema.org/draft-04/schema#",
452 "lcmOperationType": string_schema
,
453 "nsInstanceId": id_schema
,
454 "scaleType": {"enum": ["SCALE_VNF"]},
455 "timeout_ns_scale": integer1_schema
,
459 "vnfInstanceId": name_schema
,
460 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
464 "scaling-group-descriptor": name_schema
,
465 "member-vnf-index": name_schema
,
466 "scaling-policy": name_schema
,
468 "required": ["scaling-group-descriptor", "member-vnf-index"],
469 "additionalProperties": False,
472 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
473 "additionalProperties": False,
475 "scaleTime": time_schema
,
477 "required": ["scaleType", "scaleVnfData"],
478 "additionalProperties": False,
482 schema_version
= {"type": "string", "enum": ["1.0"]}
483 schema_type
= {"type": "string"}
484 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
486 vim_account_edit_schema
= {
487 "title": "vim_account edit input schema",
488 "$schema": "http://json-schema.org/draft-04/schema#",
492 "description": description_schema
,
494 "datacenter": name_schema
,
495 "vim_type": vim_type
,
496 "vim_url": description_schema
,
497 # "vim_url_admin": description_schema,
498 # "vim_tenant": name_schema,
499 "vim_tenant_name": name_schema
,
500 "vim_user": string_schema
,
501 "vim_password": passwd_schema
,
503 "config": {"type": "object"},
505 "additionalProperties": False,
508 vim_account_new_schema
= {
509 "title": "vim_account creation input schema",
510 "$schema": "http://json-schema.org/draft-04/schema#",
513 "schema_version": schema_version
,
514 "schema_type": schema_type
,
516 "description": description_schema
,
518 "datacenter": name_schema
,
519 "vim_type": vim_type
,
520 "vim_url": description_schema
,
521 # "vim_url_admin": description_schema,
522 # "vim_tenant": name_schema,
523 "vim_tenant_name": name_schema
,
524 "vim_user": string_schema
,
525 "vim_password": passwd_schema
,
527 "config": {"type": "object"},
537 "additionalProperties": False,
540 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
542 wim_account_edit_schema
= {
543 "title": "wim_account edit input schema",
544 "$schema": "http://json-schema.org/draft-04/schema#",
548 "description": description_schema
,
550 "wim_type": wim_type
,
551 "wim_url": description_schema
,
552 "user": shortname_schema
,
553 "password": passwd_schema
,
554 "config": {"type": "object"},
556 "additionalProperties": False,
559 wim_account_new_schema
= {
560 "title": "wim_account creation input schema",
561 "$schema": "http://json-schema.org/draft-04/schema#",
564 "schema_version": schema_version
,
565 "schema_type": schema_type
,
567 "description": description_schema
,
569 "wim_type": wim_type
,
570 "wim_url": description_schema
,
571 "user": shortname_schema
,
572 "password": passwd_schema
,
575 "patternProperties": {".": {"not": {"type": "null"}}},
578 "required": ["name", "wim_url", "wim_type"],
579 "additionalProperties": False,
584 "type": {"type": "string"},
585 "url": {"type": "string"},
586 "user": shortname_schema
,
587 "password": passwd_schema
,
588 "config": {"type": "object"},
589 "description": description_schema
,
590 # The folowing are deprecated. Maintanied for backward compatibility
594 "version": {"type": "string", "minLength": 1, "maxLength": 12},
597 "title": "sdn controller information schema",
598 "$schema": "http://json-schema.org/draft-04/schema#",
600 "properties": sdn_properties
,
601 "required": ["name", "type"],
602 "additionalProperties": False,
605 "title": "sdn controller update information schema",
606 "$schema": "http://json-schema.org/draft-04/schema#",
608 "properties": sdn_properties
,
609 # "required": ["name", "port", 'ip', 'dpid', 'type'],
610 "additionalProperties": False,
612 sdn_port_mapping_schema
= {
613 "$schema": "http://json-schema.org/draft-04/schema#",
614 "title": "sdn port mapping information schema",
619 "compute_node": shortname_schema
,
625 "pci": pci_extended_schema
,
626 "switch_port": shortname_schema
,
627 "switch_mac": mac_schema
,
633 "required": ["compute_node", "ports"],
636 sdn_external_port_schema
= {
637 "$schema": "http://json-schema.org/draft-04/schema#",
638 "title": "External port information",
641 "port": {"type": "string", "minLength": 1, "maxLength": 60},
645 "required": ["port"],
649 k8scluster_nets_schema
= {
650 "title": "k8scluster nets input schema",
651 "$schema": "http://json-schema.org/draft-04/schema#",
653 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
655 "additionalProperties": False,
657 k8scluster_new_schema
= {
658 "title": "k8scluster creation input schema",
659 "$schema": "http://json-schema.org/draft-04/schema#",
662 "schema_version": schema_version
,
663 "schema_type": schema_type
,
665 "description": description_schema
,
666 "credentials": object_schema
,
667 "vim_account": id_schema
,
669 "k8s_version": string_schema
,
670 "nets": k8scluster_nets_schema
,
671 "namespace": name_schema
,
672 "cni": nameshort_list_schema
,
674 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
675 "additionalProperties": False,
677 k8scluster_edit_schema
= {
678 "title": "vim_account edit input schema",
679 "$schema": "http://json-schema.org/draft-04/schema#",
683 "description": description_schema
,
684 "credentials": object_schema
,
685 "vim_account": id_schema
,
687 "k8s_version": string_schema
,
688 "nets": k8scluster_nets_schema
,
689 "namespace": name_schema
,
690 "cni": nameshort_list_schema
,
692 "additionalProperties": False,
697 "title": "vca creation input schema",
698 "$schema": "http://json-schema.org/draft-04/schema#",
701 "schema_version": schema_version
,
702 "schema_type": schema_type
,
704 "description": description_schema
,
705 "endpoints": description_list_schema
,
706 "user": shortname_schema
,
707 "secret": passwd_schema
,
708 "cacert": long_description_schema
,
709 "lxd-cloud": shortname_schema
,
710 "lxd-credentials": shortname_schema
,
711 "k8s-cloud": shortname_schema
,
712 "k8s-credentials": shortname_schema
,
713 "model-config": object_schema
,
726 "additionalProperties": False,
729 "title": "vca creation input schema",
730 "$schema": "http://json-schema.org/draft-04/schema#",
734 "description": description_schema
,
735 "endpoints": description_list_schema
,
736 "port": integer1_schema
,
737 "user": shortname_schema
,
738 "secret": passwd_schema
,
739 "cacert": long_description_schema
,
740 "lxd-cloud": shortname_schema
,
741 "lxd-credentials": shortname_schema
,
742 "k8s-cloud": shortname_schema
,
743 "k8s-credentials": shortname_schema
,
744 "model-config": object_schema
,
746 "additionalProperties": False,
750 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
751 k8srepo_properties
= {
753 "description": description_schema
,
754 "type": k8srepo_types
,
755 "url": description_schema
,
757 k8srepo_new_schema
= {
758 "title": "k8scluster creation input schema",
759 "$schema": "http://json-schema.org/draft-04/schema#",
761 "properties": k8srepo_properties
,
762 "required": ["name", "type", "url"],
763 "additionalProperties": False,
765 k8srepo_edit_schema
= {
766 "title": "vim_account edit input schema",
767 "$schema": "http://json-schema.org/draft-04/schema#",
769 "properties": k8srepo_properties
,
770 "additionalProperties": False,
774 osmrepo_types
= {"enum": ["osm"]}
775 osmrepo_properties
= {
777 "description": description_schema
,
778 "type": osmrepo_types
,
779 "url": description_schema
780 # "user": shortname_schema,
781 # "password": passwd_schema
783 osmrepo_new_schema
= {
784 "title": "osm repo creation input schema",
785 "$schema": "http://json-schema.org/draft-04/schema#",
787 "properties": osmrepo_properties
,
788 "required": ["name", "type", "url"],
789 "additionalProperties": False,
791 osmrepo_edit_schema
= {
792 "title": "osm repo edit input schema",
793 "$schema": "http://json-schema.org/draft-04/schema#",
795 "properties": osmrepo_properties
,
796 "additionalProperties": False,
803 "name": shortname_schema
,
805 "type": {"enum": ["overlay", "underlay"]},
806 "ip-address": ip_schema
,
807 # TODO, add user, password, ssh-key
808 "mac-address": mac_schema
,
809 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
810 "vim-network-id": shortname_schema
,
811 # # provide this in case SDN assist must deal with this interface
812 # "switch-dpid": dpid_Schema,
813 # "switch-port": shortname_schema,
814 # "switch-mac": shortname_schema,
815 # "switch-vlan": vlan_schema,
817 "required": ["name", "mgmt", "ip-address"],
818 "additionalProperties": False,
821 "title": "pdu creation input schema",
822 "$schema": "http://json-schema.org/draft-04/schema#",
825 "name": shortname_schema
,
826 "type": shortname_schema
,
827 "description": description_schema
,
828 "shared": bool_schema
,
829 "vims": nameshort_list_schema
,
830 "vim_accounts": nameshort_list_schema
,
831 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
833 "required": ["name", "type", "interfaces"],
834 "additionalProperties": False,
837 "title": "pdu edit input schema",
838 "$schema": "http://json-schema.org/draft-04/schema#",
841 "name": shortname_schema
,
842 "type": shortname_schema
,
843 "description": description_schema
,
844 "shared": bool_schema
,
845 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
846 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
849 array_edition_schema
,
850 {"type": "array", "items": pdu_interface
, "minItems": 1},
854 "additionalProperties": False,
859 vnfpkgop_new_schema
= {
860 "title": "VNF PKG operation creation input schema",
861 "$schema": "http://json-schema.org/draft-04/schema#",
864 "lcmOperationType": string_schema
,
865 "vnfPkgId": id_schema
,
866 "kdu_name": name_schema
,
867 "primitive": name_schema
,
868 "primitive_params": {"type": "object"},
877 "additionalProperties": False,
881 project_role_mappings
= {
882 "title": "list pf projects/roles",
883 "$schema": "http://json-schema.org/draft-04/schema#",
887 "properties": {"project": shortname_schema
, "role": shortname_schema
},
888 "required": ["project", "role"],
889 "additionalProperties": False,
893 project_role_mappings_optional
= {
894 "title": "list of projects/roles or projects only",
895 "$schema": "http://json-schema.org/draft-04/schema#",
899 "properties": {"project": shortname_schema
, "role": shortname_schema
},
900 "required": ["project"],
901 "additionalProperties": False,
906 "$schema": "http://json-schema.org/draft-04/schema#",
907 "title": "New user schema",
910 "username": shortname_schema
,
911 "domain_name": shortname_schema
,
912 "password": passwd_schema
,
913 "projects": nameshort_list_schema
,
914 "project_role_mappings": project_role_mappings
,
916 "required": ["username", "password"],
917 "additionalProperties": False,
920 "$schema": "http://json-schema.org/draft-04/schema#",
921 "title": "User edit schema for administrators",
924 "password": passwd_schema
,
925 "username": shortname_schema
, # To allow User Name modification
926 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
927 "project_role_mappings": project_role_mappings
,
928 "add_project_role_mappings": project_role_mappings
,
929 "remove_project_role_mappings": project_role_mappings_optional
,
932 "additionalProperties": False,
936 topics_with_quota
= [
952 project_new_schema
= {
953 "$schema": "http://json-schema.org/draft-04/schema#",
954 "title": "New project schema for administrators",
957 "name": shortname_schema
,
958 "admin": bool_schema
,
959 "domain_name": shortname_schema
,
962 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
963 "additionalProperties": False,
966 "required": ["name"],
967 "additionalProperties": False,
969 project_edit_schema
= {
970 "$schema": "http://json-schema.org/draft-04/schema#",
971 "title": "Project edit schema for administrators",
974 "admin": bool_schema
,
975 "name": shortname_schema
, # To allow Project Name modification
979 topic
: {"oneOf": [integer0_schema
, null_schema
]}
980 for topic
in topics_with_quota
982 "additionalProperties": False,
985 "additionalProperties": False,
991 "$schema": "http://json-schema.org/draft-04/schema#",
992 "title": "New role schema for administrators",
995 "name": shortname_schema
,
998 "patternProperties": {
1001 # "minProperties": 1,
1004 "required": ["name"],
1005 "additionalProperties": False,
1007 roles_edit_schema
= {
1008 "$schema": "http://json-schema.org/draft-04/schema#",
1009 "title": "Roles edit schema for administrators",
1012 "name": shortname_schema
,
1015 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1016 # "minProperties": 1,
1019 "additionalProperties": False,
1025 nbi_new_input_schemas
= {
1026 "users": user_new_schema
,
1027 "projects": project_new_schema
,
1028 "vim_accounts": vim_account_new_schema
,
1029 "sdns": sdn_new_schema
,
1030 "ns_instantiate": ns_instantiate
,
1031 "ns_action": ns_action
,
1032 "ns_scale": ns_scale
,
1033 "pdus": pdu_new_schema
,
1036 nbi_edit_input_schemas
= {
1037 "users": user_edit_schema
,
1038 "projects": project_edit_schema
,
1039 "vim_accounts": vim_account_edit_schema
,
1040 "sdns": sdn_edit_schema
,
1041 "pdus": pdu_edit_schema
,
1045 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1046 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1047 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1048 del nsi_subnet_instantiate
["required"]
1050 nsi_vld_instantiate
= {
1051 "title": "netslice vld instantiation params input schema",
1052 "$schema": "http://json-schema.org/draft-04/schema#",
1055 "name": string_schema
,
1056 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1057 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1058 "ip-profile": object_schema
,
1060 "required": ["name"],
1061 "additionalProperties": False,
1065 "title": "netslice action instantiate input schema",
1066 "$schema": "http://json-schema.org/draft-04/schema#",
1069 "lcmOperationType": string_schema
,
1070 "netsliceInstanceId": id_schema
,
1071 "nsiName": name_schema
,
1072 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1073 "nstId": string_schema
,
1074 "vimAccountId": id_schema
,
1075 "timeout_nsi_deploy": integer1_schema
,
1076 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1077 "nsi_id": id_schema
,
1078 "additionalParamsForNsi": object_schema
,
1079 "netslice-subnet": {
1082 "items": nsi_subnet_instantiate
,
1084 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1086 "required": ["nsiName", "nstId", "vimAccountId"],
1087 "additionalProperties": False,
1094 nsinstancesubscriptionfilter_schema
= {
1095 "title": "instance identifier schema",
1096 "$schema": "http://json-schema.org/draft-07/schema#",
1099 "nsdIds": {"type": "array"},
1100 "vnfdIds": {"type": "array"},
1101 "pnfdIds": {"type": "array"},
1102 "nsInstanceIds": {"type": "array"},
1103 "nsInstanceNames": {"type": "array"},
1108 "title": "nslcmsubscription input schema",
1109 "$schema": "http://json-schema.org/draft-07/schema#",
1112 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1113 "notificationTypes": {
1117 "NsLcmOperationOccurrenceNotification",
1118 "NsChangeNotification",
1119 "NsIdentifierCreationNotification",
1120 "NsIdentifierDeletionNotification",
1126 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1128 "operationStates": {
1134 "PARTIALLY_COMPLETED",
1142 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1143 "lcmOpNameImpactingNsComponent": {
1149 "VNF_SCALE_TO_LEVEL",
1150 "VNF_CHANGE_FLAVOUR",
1154 "VNF_CHANGE_EXT_CONN",
1164 "lcmOpOccStatusImpactingNsComponent": {
1170 "PARTIALLY_COMPLETED",
1181 "notificationTypes": {
1182 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1188 {"required": ["operationTypes"]},
1189 {"required": ["operationStates"]},
1196 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1201 {"required": ["nsComponentTypes"]},
1202 {"required": ["lcmOpNameImpactingNsComponent"]},
1203 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1210 authentication_schema
= {
1211 "title": "authentication schema for subscription",
1212 "$schema": "http://json-schema.org/draft-07/schema#",
1215 "authType": {"enum": ["basic"]},
1219 "userName": shortname_schema
,
1220 "password": passwd_schema
,
1227 "title": "subscription input schema",
1228 "$schema": "http://json-schema.org/draft-07/schema#",
1231 "filter": nslcmsub_schema
,
1232 "CallbackUri": description_schema
,
1233 "authentication": authentication_schema
,
1235 "required": ["CallbackUri"],
1239 class ValidationError(Exception):
1240 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1241 self
.http_code
= http_code
1242 Exception.__init
__(self
, message
)
1245 def validate_input(indata
, schema_to_use
):
1247 Validates input data against json schema
1248 :param indata: user input data. Should be a dictionary
1249 :param schema_to_use: jsonschema to test
1250 :return: None if ok, raises ValidationError exception on error
1254 js_v(indata
, schema_to_use
)
1256 except js_e
.ValidationError
as e
:
1258 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1261 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1262 except js_e
.SchemaError
:
1263 raise ValidationError(
1264 "Bad json schema {}".format(schema_to_use
),
1265 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1269 def is_valid_uuid(x
):
1271 Test for a valid UUID
1272 :param x: string to test
1273 :return: True if x is a valid uuid, False otherwise
1278 except (TypeError, ValueError, AttributeError):