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
]},
333 "vimAccountId": id_schema
,
334 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
335 "placement-engine": string_schema
,
336 "placement-constraints": object_schema
,
337 "additionalParamsForNs": object_schema
,
338 "additionalParamsForVnf": additional_params_for_vnf
,
339 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
340 "k8s-namespace": name_schema
,
341 "ssh_keys": {"type": "array", "items": {"type": "string"}},
342 "timeout_ns_deploy": integer1_schema
,
344 "vduImage": name_schema
,
351 "member-vnf-index": name_schema
,
352 "vimAccountId": id_schema
,
356 "items": ns_instantiate_vdu
,
361 "items": ns_instantiate_internal_vld
,
364 "required": ["member-vnf-index"],
366 "additionalProperties": False,
375 "name": string_schema
,
376 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
377 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
378 "ns-net": object_schema
,
379 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
380 "ip-profile": object_schema
,
381 "provider-network": provider_network_schema
,
382 "vnfd-connection-point-ref": {
388 "member-vnf-index-ref": name_schema
,
389 "vnfd-connection-point-ref": name_schema
,
390 "ip-address": ip_schema
,
391 # "mac-address": mac_schema,
394 "member-vnf-index-ref",
395 "vnfd-connection-point-ref",
398 "additionalProperties": False,
402 "required": ["name"],
403 "additionalProperties": False,
407 "required": ["nsName", "nsdId", "vimAccountId"],
408 "additionalProperties": False,
412 "title": "ns terminate input schema",
413 "$schema": "http://json-schema.org/draft-04/schema#",
416 "lcmOperationType": string_schema
,
417 "nsInstanceId": id_schema
,
418 "autoremove": bool_schema
,
419 "timeout_ns_terminate": integer1_schema
,
420 "skip_terminate_primitives": bool_schema
,
421 "netsliceInstanceId": id_schema
,
423 "additionalProperties": False,
426 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
427 "title": "ns action input schema",
428 "$schema": "http://json-schema.org/draft-04/schema#",
431 "lcmOperationType": string_schema
,
432 "nsInstanceId": id_schema
,
433 "member_vnf_index": name_schema
,
434 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
435 "vdu_id": name_schema
,
436 "vdu_count_index": integer0_schema
,
437 "kdu_name": name_schema
,
438 "primitive": name_schema
,
439 "timeout_ns_action": integer1_schema
,
440 "primitive_params": {"type": "object"},
442 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
443 "additionalProperties": False,
445 ns_scale
= { # TODO for the moment it is only VDU-scaling
446 "title": "ns scale input schema",
447 "$schema": "http://json-schema.org/draft-04/schema#",
450 "lcmOperationType": string_schema
,
451 "nsInstanceId": id_schema
,
452 "scaleType": {"enum": ["SCALE_VNF"]},
453 "timeout_ns_scale": integer1_schema
,
457 "vnfInstanceId": name_schema
,
458 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
462 "scaling-group-descriptor": name_schema
,
463 "member-vnf-index": name_schema
,
464 "scaling-policy": name_schema
,
466 "required": ["scaling-group-descriptor", "member-vnf-index"],
467 "additionalProperties": False,
470 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
471 "additionalProperties": False,
473 "scaleTime": time_schema
,
475 "required": ["scaleType", "scaleVnfData"],
476 "additionalProperties": False,
480 schema_version
= {"type": "string", "enum": ["1.0"]}
481 schema_type
= {"type": "string"}
482 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
484 vim_account_edit_schema
= {
485 "title": "vim_account edit input schema",
486 "$schema": "http://json-schema.org/draft-04/schema#",
490 "description": description_schema
,
492 "datacenter": name_schema
,
493 "vim_type": vim_type
,
494 "vim_url": description_schema
,
495 # "vim_url_admin": description_schema,
496 # "vim_tenant": name_schema,
497 "vim_tenant_name": name_schema
,
498 "vim_user": string_schema
,
499 "vim_password": passwd_schema
,
501 "config": {"type": "object"},
503 "additionalProperties": False,
506 vim_account_new_schema
= {
507 "title": "vim_account creation input schema",
508 "$schema": "http://json-schema.org/draft-04/schema#",
511 "schema_version": schema_version
,
512 "schema_type": schema_type
,
514 "description": description_schema
,
516 "datacenter": name_schema
,
517 "vim_type": vim_type
,
518 "vim_url": description_schema
,
519 # "vim_url_admin": description_schema,
520 # "vim_tenant": name_schema,
521 "vim_tenant_name": name_schema
,
522 "vim_user": string_schema
,
523 "vim_password": passwd_schema
,
525 "config": {"type": "object"},
535 "additionalProperties": False,
538 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
540 wim_account_edit_schema
= {
541 "title": "wim_account edit input schema",
542 "$schema": "http://json-schema.org/draft-04/schema#",
546 "description": description_schema
,
548 "wim_type": wim_type
,
549 "wim_url": description_schema
,
550 "user": string_schema
,
551 "password": passwd_schema
,
552 "config": {"type": "object"},
554 "additionalProperties": False,
557 wim_account_new_schema
= {
558 "title": "wim_account creation input schema",
559 "$schema": "http://json-schema.org/draft-04/schema#",
562 "schema_version": schema_version
,
563 "schema_type": schema_type
,
565 "description": description_schema
,
567 "wim_type": wim_type
,
568 "wim_url": description_schema
,
569 "user": string_schema
,
570 "password": passwd_schema
,
573 "patternProperties": {".": {"not": {"type": "null"}}},
576 "required": ["name", "wim_url", "wim_type"],
577 "additionalProperties": False,
582 "type": {"type": "string"},
583 "url": {"type": "string"},
584 "user": string_schema
,
585 "password": passwd_schema
,
586 "config": {"type": "object"},
587 "description": description_schema
,
588 # The folowing are deprecated. Maintanied for backward compatibility
592 "version": {"type": "string", "minLength": 1, "maxLength": 12},
595 "title": "sdn controller information schema",
596 "$schema": "http://json-schema.org/draft-04/schema#",
598 "properties": sdn_properties
,
599 "required": ["name", "type"],
600 "additionalProperties": False,
603 "title": "sdn controller update information schema",
604 "$schema": "http://json-schema.org/draft-04/schema#",
606 "properties": sdn_properties
,
607 # "required": ["name", "port", 'ip', 'dpid', 'type'],
608 "additionalProperties": False,
610 sdn_port_mapping_schema
= {
611 "$schema": "http://json-schema.org/draft-04/schema#",
612 "title": "sdn port mapping information schema",
617 "compute_node": shortname_schema
,
623 "pci": pci_extended_schema
,
624 "switch_port": shortname_schema
,
625 "switch_mac": mac_schema
,
631 "required": ["compute_node", "ports"],
634 sdn_external_port_schema
= {
635 "$schema": "http://json-schema.org/draft-04/schema#",
636 "title": "External port information",
639 "port": {"type": "string", "minLength": 1, "maxLength": 60},
643 "required": ["port"],
647 k8scluster_nets_schema
= {
648 "title": "k8scluster nets input schema",
649 "$schema": "http://json-schema.org/draft-04/schema#",
651 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
653 "additionalProperties": False,
655 k8scluster_new_schema
= {
656 "title": "k8scluster creation input schema",
657 "$schema": "http://json-schema.org/draft-04/schema#",
660 "schema_version": schema_version
,
661 "schema_type": schema_type
,
663 "description": description_schema
,
664 "credentials": object_schema
,
665 "vim_account": id_schema
,
667 "k8s_version": string_schema
,
668 "nets": k8scluster_nets_schema
,
669 "namespace": name_schema
,
670 "cni": nameshort_list_schema
,
672 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
673 "additionalProperties": False,
675 k8scluster_edit_schema
= {
676 "title": "vim_account edit input schema",
677 "$schema": "http://json-schema.org/draft-04/schema#",
681 "description": description_schema
,
682 "credentials": object_schema
,
683 "vim_account": id_schema
,
685 "k8s_version": string_schema
,
686 "nets": k8scluster_nets_schema
,
687 "namespace": name_schema
,
688 "cni": nameshort_list_schema
,
690 "additionalProperties": False,
695 "title": "vca creation input schema",
696 "$schema": "http://json-schema.org/draft-04/schema#",
699 "schema_version": schema_version
,
700 "schema_type": schema_type
,
702 "description": description_schema
,
703 "endpoints": description_list_schema
,
704 "user": string_schema
,
705 "secret": passwd_schema
,
706 "cacert": long_description_schema
,
707 "lxd-cloud": shortname_schema
,
708 "lxd-credentials": shortname_schema
,
709 "k8s-cloud": shortname_schema
,
710 "k8s-credentials": shortname_schema
,
711 "model-config": object_schema
,
724 "additionalProperties": False,
727 "title": "vca creation input schema",
728 "$schema": "http://json-schema.org/draft-04/schema#",
732 "description": description_schema
,
733 "endpoints": description_list_schema
,
734 "port": integer1_schema
,
735 "user": string_schema
,
736 "secret": passwd_schema
,
737 "cacert": long_description_schema
,
738 "lxd-cloud": shortname_schema
,
739 "lxd-credentials": shortname_schema
,
740 "k8s-cloud": shortname_schema
,
741 "k8s-credentials": shortname_schema
,
742 "model-config": object_schema
,
744 "additionalProperties": False,
748 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
749 k8srepo_properties
= {
751 "description": description_schema
,
752 "type": k8srepo_types
,
753 "url": description_schema
,
755 k8srepo_new_schema
= {
756 "title": "k8scluster creation input schema",
757 "$schema": "http://json-schema.org/draft-04/schema#",
759 "properties": k8srepo_properties
,
760 "required": ["name", "type", "url"],
761 "additionalProperties": False,
763 k8srepo_edit_schema
= {
764 "title": "vim_account edit input schema",
765 "$schema": "http://json-schema.org/draft-04/schema#",
767 "properties": k8srepo_properties
,
768 "additionalProperties": False,
772 osmrepo_types
= {"enum": ["osm"]}
773 osmrepo_properties
= {
775 "description": description_schema
,
776 "type": osmrepo_types
,
777 "url": description_schema
778 # "user": string_schema,
779 # "password": passwd_schema
781 osmrepo_new_schema
= {
782 "title": "osm repo creation input schema",
783 "$schema": "http://json-schema.org/draft-04/schema#",
785 "properties": osmrepo_properties
,
786 "required": ["name", "type", "url"],
787 "additionalProperties": False,
789 osmrepo_edit_schema
= {
790 "title": "osm repo edit input schema",
791 "$schema": "http://json-schema.org/draft-04/schema#",
793 "properties": osmrepo_properties
,
794 "additionalProperties": False,
801 "name": shortname_schema
,
803 "type": {"enum": ["overlay", "underlay"]},
804 "ip-address": ip_schema
,
805 # TODO, add user, password, ssh-key
806 "mac-address": mac_schema
,
807 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
808 "vim-network-id": shortname_schema
,
809 # # provide this in case SDN assist must deal with this interface
810 # "switch-dpid": dpid_Schema,
811 # "switch-port": shortname_schema,
812 # "switch-mac": shortname_schema,
813 # "switch-vlan": vlan_schema,
815 "required": ["name", "mgmt", "ip-address"],
816 "additionalProperties": False,
819 "title": "pdu creation input schema",
820 "$schema": "http://json-schema.org/draft-04/schema#",
823 "name": shortname_schema
,
824 "type": shortname_schema
,
825 "description": description_schema
,
826 "shared": bool_schema
,
827 "vims": nameshort_list_schema
,
828 "vim_accounts": nameshort_list_schema
,
829 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
831 "required": ["name", "type", "interfaces"],
832 "additionalProperties": False,
835 "title": "pdu edit input schema",
836 "$schema": "http://json-schema.org/draft-04/schema#",
839 "name": shortname_schema
,
840 "type": shortname_schema
,
841 "description": description_schema
,
842 "shared": bool_schema
,
843 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
844 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
847 array_edition_schema
,
848 {"type": "array", "items": pdu_interface
, "minItems": 1},
852 "additionalProperties": False,
857 vnfpkgop_new_schema
= {
858 "title": "VNF PKG operation creation input schema",
859 "$schema": "http://json-schema.org/draft-04/schema#",
862 "lcmOperationType": string_schema
,
863 "vnfPkgId": id_schema
,
864 "kdu_name": name_schema
,
865 "primitive": name_schema
,
866 "primitive_params": {"type": "object"},
875 "additionalProperties": False,
879 project_role_mappings
= {
880 "title": "list pf projects/roles",
881 "$schema": "http://json-schema.org/draft-04/schema#",
885 "properties": {"project": shortname_schema
, "role": shortname_schema
},
886 "required": ["project", "role"],
887 "additionalProperties": False,
891 project_role_mappings_optional
= {
892 "title": "list of projects/roles or projects only",
893 "$schema": "http://json-schema.org/draft-04/schema#",
897 "properties": {"project": shortname_schema
, "role": shortname_schema
},
898 "required": ["project"],
899 "additionalProperties": False,
904 "$schema": "http://json-schema.org/draft-04/schema#",
905 "title": "New user schema",
908 "username": string_schema
,
909 "domain_name": shortname_schema
,
910 "password": passwd_schema
,
911 "projects": nameshort_list_schema
,
912 "project_role_mappings": project_role_mappings
,
914 "required": ["username", "password"],
915 "additionalProperties": False,
918 "$schema": "http://json-schema.org/draft-04/schema#",
919 "title": "User edit schema for administrators",
922 "password": passwd_schema
,
923 "username": string_schema
, # To allow User Name modification
924 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
925 "project_role_mappings": project_role_mappings
,
926 "add_project_role_mappings": project_role_mappings
,
927 "remove_project_role_mappings": project_role_mappings_optional
,
930 "additionalProperties": False,
934 topics_with_quota
= [
950 project_new_schema
= {
951 "$schema": "http://json-schema.org/draft-04/schema#",
952 "title": "New project schema for administrators",
955 "name": shortname_schema
,
956 "admin": bool_schema
,
957 "domain_name": shortname_schema
,
960 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
961 "additionalProperties": False,
964 "required": ["name"],
965 "additionalProperties": False,
967 project_edit_schema
= {
968 "$schema": "http://json-schema.org/draft-04/schema#",
969 "title": "Project edit schema for administrators",
972 "admin": bool_schema
,
973 "name": shortname_schema
, # To allow Project Name modification
977 topic
: {"oneOf": [integer0_schema
, null_schema
]}
978 for topic
in topics_with_quota
980 "additionalProperties": False,
983 "additionalProperties": False,
989 "$schema": "http://json-schema.org/draft-04/schema#",
990 "title": "New role schema for administrators",
993 "name": shortname_schema
,
996 "patternProperties": {
999 # "minProperties": 1,
1002 "required": ["name"],
1003 "additionalProperties": False,
1005 roles_edit_schema
= {
1006 "$schema": "http://json-schema.org/draft-04/schema#",
1007 "title": "Roles edit schema for administrators",
1010 "name": shortname_schema
,
1013 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1014 # "minProperties": 1,
1017 "additionalProperties": False,
1023 nbi_new_input_schemas
= {
1024 "users": user_new_schema
,
1025 "projects": project_new_schema
,
1026 "vim_accounts": vim_account_new_schema
,
1027 "sdns": sdn_new_schema
,
1028 "ns_instantiate": ns_instantiate
,
1029 "ns_action": ns_action
,
1030 "ns_scale": ns_scale
,
1031 "pdus": pdu_new_schema
,
1034 nbi_edit_input_schemas
= {
1035 "users": user_edit_schema
,
1036 "projects": project_edit_schema
,
1037 "vim_accounts": vim_account_edit_schema
,
1038 "sdns": sdn_edit_schema
,
1039 "pdus": pdu_edit_schema
,
1043 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1044 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1045 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1046 del nsi_subnet_instantiate
["required"]
1048 nsi_vld_instantiate
= {
1049 "title": "netslice vld instantiation params input schema",
1050 "$schema": "http://json-schema.org/draft-04/schema#",
1053 "name": string_schema
,
1054 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1055 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1056 "ip-profile": object_schema
,
1058 "required": ["name"],
1059 "additionalProperties": False,
1063 "title": "netslice action instantiate input schema",
1064 "$schema": "http://json-schema.org/draft-04/schema#",
1067 "lcmOperationType": string_schema
,
1068 "netsliceInstanceId": id_schema
,
1069 "nsiName": name_schema
,
1070 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1071 "nstId": string_schema
,
1072 "vimAccountId": id_schema
,
1073 "timeout_nsi_deploy": integer1_schema
,
1074 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1075 "nsi_id": id_schema
,
1076 "additionalParamsForNsi": object_schema
,
1077 "netslice-subnet": {
1080 "items": nsi_subnet_instantiate
,
1082 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1084 "required": ["nsiName", "nstId", "vimAccountId"],
1085 "additionalProperties": False,
1092 nsinstancesubscriptionfilter_schema
= {
1093 "title": "instance identifier schema",
1094 "$schema": "http://json-schema.org/draft-07/schema#",
1097 "nsdIds": {"type": "array"},
1098 "vnfdIds": {"type": "array"},
1099 "pnfdIds": {"type": "array"},
1100 "nsInstanceIds": {"type": "array"},
1101 "nsInstanceNames": {"type": "array"},
1106 "title": "nslcmsubscription input schema",
1107 "$schema": "http://json-schema.org/draft-07/schema#",
1110 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1111 "notificationTypes": {
1115 "NsLcmOperationOccurrenceNotification",
1116 "NsChangeNotification",
1117 "NsIdentifierCreationNotification",
1118 "NsIdentifierDeletionNotification",
1124 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1126 "operationStates": {
1132 "PARTIALLY_COMPLETED",
1140 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1141 "lcmOpNameImpactingNsComponent": {
1147 "VNF_SCALE_TO_LEVEL",
1148 "VNF_CHANGE_FLAVOUR",
1152 "VNF_CHANGE_EXT_CONN",
1162 "lcmOpOccStatusImpactingNsComponent": {
1168 "PARTIALLY_COMPLETED",
1179 "notificationTypes": {
1180 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1186 {"required": ["operationTypes"]},
1187 {"required": ["operationStates"]},
1194 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1199 {"required": ["nsComponentTypes"]},
1200 {"required": ["lcmOpNameImpactingNsComponent"]},
1201 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1208 authentication_schema
= {
1209 "title": "authentication schema for subscription",
1210 "$schema": "http://json-schema.org/draft-07/schema#",
1213 "authType": {"enum": ["basic"]},
1217 "userName": string_schema
,
1218 "password": passwd_schema
,
1225 "title": "subscription input schema",
1226 "$schema": "http://json-schema.org/draft-07/schema#",
1229 "filter": nslcmsub_schema
,
1230 "CallbackUri": description_schema
,
1231 "authentication": authentication_schema
,
1233 "required": ["CallbackUri"],
1237 class ValidationError(Exception):
1238 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1239 self
.http_code
= http_code
1240 Exception.__init
__(self
, message
)
1243 def validate_input(indata
, schema_to_use
):
1245 Validates input data against json schema
1246 :param indata: user input data. Should be a dictionary
1247 :param schema_to_use: jsonschema to test
1248 :return: None if ok, raises ValidationError exception on error
1252 js_v(indata
, schema_to_use
)
1254 except js_e
.ValidationError
as e
:
1256 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1259 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1260 except js_e
.SchemaError
:
1261 raise ValidationError(
1262 "Bad json schema {}".format(schema_to_use
),
1263 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1267 def is_valid_uuid(x
):
1269 Test for a valid UUID
1270 :param x: string to test
1271 :return: True if x is a valid uuid, False otherwise
1276 except (TypeError, ValueError, AttributeError):