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
309 "required": ["kdu_name"],
311 "additionalProperties": False,
315 "required": ["member-vnf-index"],
317 "additionalProperties": False,
322 "title": "ns action instantiate input schema",
323 "$schema": "http://json-schema.org/draft-04/schema#",
326 "lcmOperationType": string_schema
,
327 "nsInstanceId": id_schema
,
328 "netsliceInstanceId": id_schema
,
329 "nsName": name_schema
,
330 "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
,
357 "items": ns_instantiate_vdu
,
362 "items": ns_instantiate_internal_vld
,
365 "required": ["member-vnf-index"],
367 "additionalProperties": False,
376 "name": string_schema
,
377 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
378 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
379 "ns-net": object_schema
,
380 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
381 "ip-profile": object_schema
,
382 "provider-network": provider_network_schema
,
383 "vnfd-connection-point-ref": {
389 "member-vnf-index-ref": name_schema
,
390 "vnfd-connection-point-ref": name_schema
,
391 "ip-address": ip_schema
,
392 # "mac-address": mac_schema,
395 "member-vnf-index-ref",
396 "vnfd-connection-point-ref",
399 "additionalProperties": False,
403 "required": ["name"],
404 "additionalProperties": False,
408 "required": ["nsName", "nsdId", "vimAccountId"],
409 "additionalProperties": False,
413 "title": "ns terminate input schema",
414 "$schema": "http://json-schema.org/draft-04/schema#",
417 "lcmOperationType": string_schema
,
418 "nsInstanceId": id_schema
,
419 "autoremove": bool_schema
,
420 "timeout_ns_terminate": integer1_schema
,
421 "skip_terminate_primitives": bool_schema
,
422 "netsliceInstanceId": id_schema
,
424 "additionalProperties": False,
427 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
428 "title": "ns action input schema",
429 "$schema": "http://json-schema.org/draft-04/schema#",
432 "lcmOperationType": string_schema
,
433 "nsInstanceId": id_schema
,
434 "member_vnf_index": name_schema
,
435 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
436 "vdu_id": name_schema
,
437 "vdu_count_index": integer0_schema
,
438 "kdu_name": name_schema
,
439 "primitive": name_schema
,
440 "timeout_ns_action": integer1_schema
,
441 "primitive_params": {"type": "object"},
443 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
444 "additionalProperties": False,
446 ns_scale
= { # TODO for the moment it is only VDU-scaling
447 "title": "ns scale input schema",
448 "$schema": "http://json-schema.org/draft-04/schema#",
451 "lcmOperationType": string_schema
,
452 "nsInstanceId": id_schema
,
453 "scaleType": {"enum": ["SCALE_VNF"]},
454 "timeout_ns_scale": integer1_schema
,
458 "vnfInstanceId": name_schema
,
459 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
463 "scaling-group-descriptor": name_schema
,
464 "member-vnf-index": name_schema
,
465 "scaling-policy": name_schema
,
467 "required": ["scaling-group-descriptor", "member-vnf-index"],
468 "additionalProperties": False,
471 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
472 "additionalProperties": False,
474 "scaleTime": time_schema
,
476 "required": ["scaleType", "scaleVnfData"],
477 "additionalProperties": False,
481 schema_version
= {"type": "string", "enum": ["1.0"]}
482 schema_type
= {"type": "string"}
483 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
485 vim_account_edit_schema
= {
486 "title": "vim_account edit input schema",
487 "$schema": "http://json-schema.org/draft-04/schema#",
491 "description": description_schema
,
493 "datacenter": name_schema
,
494 "vim_type": vim_type
,
495 "vim_url": description_schema
,
496 # "vim_url_admin": description_schema,
497 # "vim_tenant": name_schema,
498 "vim_tenant_name": name_schema
,
499 "vim_user": shortname_schema
,
500 "vim_password": passwd_schema
,
502 "config": {"type": "object"},
504 "additionalProperties": False,
507 vim_account_new_schema
= {
508 "title": "vim_account creation input schema",
509 "$schema": "http://json-schema.org/draft-04/schema#",
512 "schema_version": schema_version
,
513 "schema_type": schema_type
,
515 "description": description_schema
,
517 "datacenter": name_schema
,
518 "vim_type": vim_type
,
519 "vim_url": description_schema
,
520 # "vim_url_admin": description_schema,
521 # "vim_tenant": name_schema,
522 "vim_tenant_name": name_schema
,
523 "vim_user": shortname_schema
,
524 "vim_password": passwd_schema
,
526 "config": {"type": "object"},
536 "additionalProperties": False,
539 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
541 wim_account_edit_schema
= {
542 "title": "wim_account edit input schema",
543 "$schema": "http://json-schema.org/draft-04/schema#",
547 "description": description_schema
,
549 "wim_type": wim_type
,
550 "wim_url": description_schema
,
551 "user": shortname_schema
,
552 "password": passwd_schema
,
553 "config": {"type": "object"},
555 "additionalProperties": False,
558 wim_account_new_schema
= {
559 "title": "wim_account creation input schema",
560 "$schema": "http://json-schema.org/draft-04/schema#",
563 "schema_version": schema_version
,
564 "schema_type": schema_type
,
566 "description": description_schema
,
568 "wim_type": wim_type
,
569 "wim_url": description_schema
,
570 "user": shortname_schema
,
571 "password": passwd_schema
,
574 "patternProperties": {".": {"not": {"type": "null"}}},
577 "required": ["name", "wim_url", "wim_type"],
578 "additionalProperties": False,
583 "type": {"type": "string"},
584 "url": {"type": "string"},
585 "user": shortname_schema
,
586 "password": passwd_schema
,
587 "config": {"type": "object"},
588 "description": description_schema
,
589 # The folowing are deprecated. Maintanied for backward compatibility
593 "version": {"type": "string", "minLength": 1, "maxLength": 12},
596 "title": "sdn controller information schema",
597 "$schema": "http://json-schema.org/draft-04/schema#",
599 "properties": sdn_properties
,
600 "required": ["name", "type"],
601 "additionalProperties": False,
604 "title": "sdn controller update information schema",
605 "$schema": "http://json-schema.org/draft-04/schema#",
607 "properties": sdn_properties
,
608 # "required": ["name", "port", 'ip', 'dpid', 'type'],
609 "additionalProperties": False,
611 sdn_port_mapping_schema
= {
612 "$schema": "http://json-schema.org/draft-04/schema#",
613 "title": "sdn port mapping information schema",
618 "compute_node": shortname_schema
,
624 "pci": pci_extended_schema
,
625 "switch_port": shortname_schema
,
626 "switch_mac": mac_schema
,
632 "required": ["compute_node", "ports"],
635 sdn_external_port_schema
= {
636 "$schema": "http://json-schema.org/draft-04/schema#",
637 "title": "External port information",
640 "port": {"type": "string", "minLength": 1, "maxLength": 60},
644 "required": ["port"],
648 k8scluster_nets_schema
= {
649 "title": "k8scluster nets input schema",
650 "$schema": "http://json-schema.org/draft-04/schema#",
652 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
654 "additionalProperties": False,
656 k8scluster_new_schema
= {
657 "title": "k8scluster creation input schema",
658 "$schema": "http://json-schema.org/draft-04/schema#",
661 "schema_version": schema_version
,
662 "schema_type": schema_type
,
664 "description": description_schema
,
665 "credentials": object_schema
,
666 "vim_account": id_schema
,
668 "k8s_version": string_schema
,
669 "nets": k8scluster_nets_schema
,
670 "namespace": name_schema
,
671 "cni": nameshort_list_schema
,
673 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
674 "additionalProperties": False,
676 k8scluster_edit_schema
= {
677 "title": "vim_account edit input schema",
678 "$schema": "http://json-schema.org/draft-04/schema#",
682 "description": description_schema
,
683 "credentials": object_schema
,
684 "vim_account": id_schema
,
686 "k8s_version": string_schema
,
687 "nets": k8scluster_nets_schema
,
688 "namespace": name_schema
,
689 "cni": nameshort_list_schema
,
691 "additionalProperties": False,
696 "title": "vca creation input schema",
697 "$schema": "http://json-schema.org/draft-04/schema#",
700 "schema_version": schema_version
,
701 "schema_type": schema_type
,
703 "description": description_schema
,
704 "endpoints": description_list_schema
,
705 "user": shortname_schema
,
706 "secret": passwd_schema
,
707 "cacert": long_description_schema
,
708 "lxd-cloud": shortname_schema
,
709 "lxd-credentials": shortname_schema
,
710 "k8s-cloud": shortname_schema
,
711 "k8s-credentials": shortname_schema
,
712 "model-config": object_schema
,
725 "additionalProperties": False,
728 "title": "vca creation input schema",
729 "$schema": "http://json-schema.org/draft-04/schema#",
733 "description": description_schema
,
734 "endpoints": description_list_schema
,
735 "port": integer1_schema
,
736 "user": shortname_schema
,
737 "secret": passwd_schema
,
738 "cacert": long_description_schema
,
739 "lxd-cloud": shortname_schema
,
740 "lxd-credentials": shortname_schema
,
741 "k8s-cloud": shortname_schema
,
742 "k8s-credentials": shortname_schema
,
743 "model-config": object_schema
,
745 "additionalProperties": False,
749 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
750 k8srepo_properties
= {
752 "description": description_schema
,
753 "type": k8srepo_types
,
754 "url": description_schema
,
756 k8srepo_new_schema
= {
757 "title": "k8scluster creation input schema",
758 "$schema": "http://json-schema.org/draft-04/schema#",
760 "properties": k8srepo_properties
,
761 "required": ["name", "type", "url"],
762 "additionalProperties": False,
764 k8srepo_edit_schema
= {
765 "title": "vim_account edit input schema",
766 "$schema": "http://json-schema.org/draft-04/schema#",
768 "properties": k8srepo_properties
,
769 "additionalProperties": False,
773 osmrepo_types
= {"enum": ["osm"]}
774 osmrepo_properties
= {
776 "description": description_schema
,
777 "type": osmrepo_types
,
778 "url": description_schema
779 # "user": shortname_schema,
780 # "password": passwd_schema
782 osmrepo_new_schema
= {
783 "title": "osm repo creation input schema",
784 "$schema": "http://json-schema.org/draft-04/schema#",
786 "properties": osmrepo_properties
,
787 "required": ["name", "type", "url"],
788 "additionalProperties": False,
790 osmrepo_edit_schema
= {
791 "title": "osm repo edit input schema",
792 "$schema": "http://json-schema.org/draft-04/schema#",
794 "properties": osmrepo_properties
,
795 "additionalProperties": False,
802 "name": shortname_schema
,
804 "type": {"enum": ["overlay", "underlay"]},
805 "ip-address": ip_schema
,
806 # TODO, add user, password, ssh-key
807 "mac-address": mac_schema
,
808 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
809 "vim-network-id": shortname_schema
,
810 # # provide this in case SDN assist must deal with this interface
811 # "switch-dpid": dpid_Schema,
812 # "switch-port": shortname_schema,
813 # "switch-mac": shortname_schema,
814 # "switch-vlan": vlan_schema,
816 "required": ["name", "mgmt", "ip-address"],
817 "additionalProperties": False,
820 "title": "pdu creation input schema",
821 "$schema": "http://json-schema.org/draft-04/schema#",
824 "name": shortname_schema
,
825 "type": shortname_schema
,
826 "description": description_schema
,
827 "shared": bool_schema
,
828 "vims": nameshort_list_schema
,
829 "vim_accounts": nameshort_list_schema
,
830 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
832 "required": ["name", "type", "interfaces"],
833 "additionalProperties": False,
836 "title": "pdu edit input schema",
837 "$schema": "http://json-schema.org/draft-04/schema#",
840 "name": shortname_schema
,
841 "type": shortname_schema
,
842 "description": description_schema
,
843 "shared": bool_schema
,
844 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
845 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
848 array_edition_schema
,
849 {"type": "array", "items": pdu_interface
, "minItems": 1},
853 "additionalProperties": False,
858 vnfpkgop_new_schema
= {
859 "title": "VNF PKG operation creation input schema",
860 "$schema": "http://json-schema.org/draft-04/schema#",
863 "lcmOperationType": string_schema
,
864 "vnfPkgId": id_schema
,
865 "kdu_name": name_schema
,
866 "primitive": name_schema
,
867 "primitive_params": {"type": "object"},
876 "additionalProperties": False,
880 project_role_mappings
= {
881 "title": "list pf projects/roles",
882 "$schema": "http://json-schema.org/draft-04/schema#",
886 "properties": {"project": shortname_schema
, "role": shortname_schema
},
887 "required": ["project", "role"],
888 "additionalProperties": False,
892 project_role_mappings_optional
= {
893 "title": "list of projects/roles or projects only",
894 "$schema": "http://json-schema.org/draft-04/schema#",
898 "properties": {"project": shortname_schema
, "role": shortname_schema
},
899 "required": ["project"],
900 "additionalProperties": False,
905 "$schema": "http://json-schema.org/draft-04/schema#",
906 "title": "New user schema",
909 "username": shortname_schema
,
910 "domain_name": shortname_schema
,
911 "password": passwd_schema
,
912 "projects": nameshort_list_schema
,
913 "project_role_mappings": project_role_mappings
,
915 "required": ["username", "password"],
916 "additionalProperties": False,
919 "$schema": "http://json-schema.org/draft-04/schema#",
920 "title": "User edit schema for administrators",
923 "password": passwd_schema
,
924 "username": shortname_schema
, # To allow User Name modification
925 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
926 "project_role_mappings": project_role_mappings
,
927 "add_project_role_mappings": project_role_mappings
,
928 "remove_project_role_mappings": project_role_mappings_optional
,
931 "additionalProperties": False,
935 topics_with_quota
= [
951 project_new_schema
= {
952 "$schema": "http://json-schema.org/draft-04/schema#",
953 "title": "New project schema for administrators",
956 "name": shortname_schema
,
957 "admin": bool_schema
,
958 "domain_name": shortname_schema
,
961 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
962 "additionalProperties": False,
965 "required": ["name"],
966 "additionalProperties": False,
968 project_edit_schema
= {
969 "$schema": "http://json-schema.org/draft-04/schema#",
970 "title": "Project edit schema for administrators",
973 "admin": bool_schema
,
974 "name": shortname_schema
, # To allow Project Name modification
978 topic
: {"oneOf": [integer0_schema
, null_schema
]}
979 for topic
in topics_with_quota
981 "additionalProperties": False,
984 "additionalProperties": False,
990 "$schema": "http://json-schema.org/draft-04/schema#",
991 "title": "New role schema for administrators",
994 "name": shortname_schema
,
997 "patternProperties": {
1000 # "minProperties": 1,
1003 "required": ["name"],
1004 "additionalProperties": False,
1006 roles_edit_schema
= {
1007 "$schema": "http://json-schema.org/draft-04/schema#",
1008 "title": "Roles edit schema for administrators",
1011 "name": shortname_schema
,
1014 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1015 # "minProperties": 1,
1018 "additionalProperties": False,
1024 nbi_new_input_schemas
= {
1025 "users": user_new_schema
,
1026 "projects": project_new_schema
,
1027 "vim_accounts": vim_account_new_schema
,
1028 "sdns": sdn_new_schema
,
1029 "ns_instantiate": ns_instantiate
,
1030 "ns_action": ns_action
,
1031 "ns_scale": ns_scale
,
1032 "pdus": pdu_new_schema
,
1035 nbi_edit_input_schemas
= {
1036 "users": user_edit_schema
,
1037 "projects": project_edit_schema
,
1038 "vim_accounts": vim_account_edit_schema
,
1039 "sdns": sdn_edit_schema
,
1040 "pdus": pdu_edit_schema
,
1044 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1045 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1046 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1047 del nsi_subnet_instantiate
["required"]
1049 nsi_vld_instantiate
= {
1050 "title": "netslice vld instantiation params input schema",
1051 "$schema": "http://json-schema.org/draft-04/schema#",
1054 "name": string_schema
,
1055 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1056 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1057 "ip-profile": object_schema
,
1059 "required": ["name"],
1060 "additionalProperties": False,
1064 "title": "netslice action instantiate input schema",
1065 "$schema": "http://json-schema.org/draft-04/schema#",
1068 "lcmOperationType": string_schema
,
1069 "netsliceInstanceId": id_schema
,
1070 "nsiName": name_schema
,
1071 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1072 "nstId": string_schema
,
1073 "vimAccountId": id_schema
,
1074 "timeout_nsi_deploy": integer1_schema
,
1075 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1076 "nsi_id": id_schema
,
1077 "additionalParamsForNsi": object_schema
,
1078 "netslice-subnet": {
1081 "items": nsi_subnet_instantiate
,
1083 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1085 "required": ["nsiName", "nstId", "vimAccountId"],
1086 "additionalProperties": False,
1093 nsinstancesubscriptionfilter_schema
= {
1094 "title": "instance identifier schema",
1095 "$schema": "http://json-schema.org/draft-07/schema#",
1098 "nsdIds": {"type": "array"},
1099 "vnfdIds": {"type": "array"},
1100 "pnfdIds": {"type": "array"},
1101 "nsInstanceIds": {"type": "array"},
1102 "nsInstanceNames": {"type": "array"},
1107 "title": "nslcmsubscription input schema",
1108 "$schema": "http://json-schema.org/draft-07/schema#",
1111 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1112 "notificationTypes": {
1116 "NsLcmOperationOccurrenceNotification",
1117 "NsChangeNotification",
1118 "NsIdentifierCreationNotification",
1119 "NsIdentifierDeletionNotification",
1125 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1127 "operationStates": {
1133 "PARTIALLY_COMPLETED",
1141 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1142 "lcmOpNameImpactingNsComponent": {
1148 "VNF_SCALE_TO_LEVEL",
1149 "VNF_CHANGE_FLAVOUR",
1153 "VNF_CHANGE_EXT_CONN",
1163 "lcmOpOccStatusImpactingNsComponent": {
1169 "PARTIALLY_COMPLETED",
1180 "notificationTypes": {
1181 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1187 {"required": ["operationTypes"]},
1188 {"required": ["operationStates"]},
1195 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1200 {"required": ["nsComponentTypes"]},
1201 {"required": ["lcmOpNameImpactingNsComponent"]},
1202 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1209 authentication_schema
= {
1210 "title": "authentication schema for subscription",
1211 "$schema": "http://json-schema.org/draft-07/schema#",
1214 "authType": {"enum": ["basic"]},
1218 "userName": shortname_schema
,
1219 "password": passwd_schema
,
1226 "title": "subscription input schema",
1227 "$schema": "http://json-schema.org/draft-07/schema#",
1230 "filter": nslcmsub_schema
,
1231 "CallbackUri": description_schema
,
1232 "authentication": authentication_schema
,
1234 "required": ["CallbackUri"],
1238 class ValidationError(Exception):
1239 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1240 self
.http_code
= http_code
1241 Exception.__init
__(self
, message
)
1244 def validate_input(indata
, schema_to_use
):
1246 Validates input data against json schema
1247 :param indata: user input data. Should be a dictionary
1248 :param schema_to_use: jsonschema to test
1249 :return: None if ok, raises ValidationError exception on error
1253 js_v(indata
, schema_to_use
)
1255 except js_e
.ValidationError
as e
:
1257 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1260 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1261 except js_e
.SchemaError
:
1262 raise ValidationError(
1263 "Bad json schema {}".format(schema_to_use
),
1264 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1268 def is_valid_uuid(x
):
1270 Test for a valid UUID
1271 :param x: string to test
1272 :return: True if x is a valid uuid, False otherwise
1277 except (TypeError, ValueError, AttributeError):