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
= "^[ -~]+$"
31 shortname_schema
= {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()\\.\\$'\"]+$"}
32 passwd_schema
= {"type": "string", "minLength": 1, "maxLength": 60}
33 name_schema
= {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
34 string_schema
= {"type": "string", "minLength": 1, "maxLength": 255}
35 xml_text_schema
= {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
36 description_schema
= {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
37 id_schema_fake
= {"type": "string", "minLength": 2, "maxLength": 36}
38 bool_schema
= {"type": "boolean"}
39 null_schema
= {"type": "null"}
40 # "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}$"
41 id_schema
= {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
42 time_schema
= {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"}
43 pci_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"}
44 # allows [] for wildcards. For that reason huge length limit is set
45 pci_extended_schema
= {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
46 http_schema
= {"type": "string", "pattern": "^https?://[^'\"=]+$"}
47 bandwidth_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
48 memory_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
49 integer0_schema
= {"type": "integer", "minimum": 0}
50 integer1_schema
= {"type": "integer", "minimum": 1}
51 path_schema
= {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
52 vlan_schema
= {"type": "integer", "minimum": 1, "maximum": 4095}
53 vlan1000_schema
= {"type": "integer", "minimum": 1000, "maximum": 4095}
54 mac_schema
= {"type": "string",
55 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0
56 dpid_Schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
57 # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
58 ip_schema
= {"type": "string",
59 "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]?)$"}
60 ip_prefix_schema
= {"type": "string",
61 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
62 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
63 port_schema
= {"type": "integer", "minimum": 1, "maximum": 65534}
64 object_schema
= {"type": "object"}
65 schema_version_2
= {"type": "integer", "minimum": 2, "maximum": 2}
66 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
67 log_level_schema
= {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
68 checksum_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
69 size_schema
= {"type": "integer", "minimum": 1, "maximum": 100}
70 array_edition_schema
= {
72 "patternProperties": {
75 "additionalProperties": False,
78 nameshort_list_schema
= {
81 "items": shortname_schema
,
85 ns_instantiate_vdu
= {
86 "title": "ns action instantiate input schema for vdu",
87 "$schema": "http://json-schema.org/draft-04/schema#",
98 "vim-volume-id": name_schema
,
100 "required": ["name", "vim-volume-id"],
101 "additionalProperties": False
111 "ip-address": ip_schema
,
112 "mac-address": mac_schema
,
113 "floating-ip-required": bool_schema
,
115 "required": ["name"],
116 "additionalProperties": False
121 "additionalProperties": False
124 ip_profile_dns_schema
= {
130 "address": ip_schema
,
132 "required": ["address"],
133 "additionalProperties": False
137 ip_profile_dhcp_schema
= {
140 "enabled": {"type": "boolean"},
141 "count": integer1_schema
,
142 "start-address": ip_schema
144 "additionalProperties": False,
147 ip_profile_schema
= {
148 "title": "ip profile validation schema",
149 "$schema": "http://json-schema.org/draft-04/schema#",
152 "ip-version": {"enum": ["ipv4", "ipv6"]},
153 "subnet-address": ip_prefix_schema
,
154 "gateway-address": ip_schema
,
155 "dns-server": ip_profile_dns_schema
,
156 "dhcp-params": ip_profile_dhcp_schema
,
160 ip_profile_update_schema
= {
161 "title": "ip profile validation schema",
162 "$schema": "http://json-schema.org/draft-04/schema#",
165 "ip-version": {"enum": ["ipv4", "ipv6"]},
166 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
167 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
168 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
170 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
172 "additionalProperties": False
175 provider_network_schema
= {
176 "title": "provider network validation schema",
177 "$schema": "http://json-schema.org/draft-04/schema#",
180 "physical-network": name_schema
,
181 "segmentation-id": name_schema
,
182 "sdn-ports": { # external ports to append to the SDN-assist network
187 "switch_id": shortname_schema
,
188 "switch_port": shortname_schema
,
189 "mac_address": mac_schema
,
192 "additionalProperties": True
195 "network-type": shortname_schema
,
197 "additionalProperties": True
200 ns_instantiate_internal_vld
= {
201 "title": "ns action instantiate input schema for vdu",
202 "$schema": "http://json-schema.org/draft-04/schema#",
206 "vim-network-name": name_schema
,
207 "vim-network-id": name_schema
,
208 "ip-profile": ip_profile_update_schema
,
209 "provider-network": provider_network_schema
,
210 "internal-connection-point": {
216 "id-ref": name_schema
,
217 "ip-address": ip_schema
,
218 # "mac-address": mac_schema,
220 "required": ["id-ref"],
222 "additionalProperties": False
226 "required": ["name"],
228 "additionalProperties": False
231 additional_params_for_vnf
= {
236 "member-vnf-index": name_schema
,
237 "additionalParams": object_schema
,
238 "k8s-namespace": name_schema
,
239 "additionalParamsForVdu": {
244 "vdu_id": name_schema
,
245 "additionalParams": object_schema
,
247 "required": ["vdu_id", "additionalParams"],
248 "additionalProperties": False,
251 "additionalParamsForKdu": {
256 "kdu_name": name_schema
,
257 "additionalParams": object_schema
,
258 "kdu_model": name_schema
,
259 "k8s-namespace": name_schema
,
261 "required": ["kdu_name"],
263 "additionalProperties": False,
267 "required": ["member-vnf-index"],
269 "additionalProperties": False
274 "title": "ns action instantiate input schema",
275 "$schema": "http://json-schema.org/draft-04/schema#",
278 "lcmOperationType": string_schema
,
279 "nsInstanceId": id_schema
,
280 "netsliceInstanceId": id_schema
,
281 "nsName": name_schema
,
282 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
284 "vimAccountId": id_schema
,
285 "wimAccountId": {"OneOf": [id_schema
, bool_schema
, null_schema
]},
286 "placement-engine": string_schema
,
287 "placement-constraints": object_schema
,
288 "additionalParamsForNs": object_schema
,
289 "additionalParamsForVnf": additional_params_for_vnf
,
290 "k8s-namespace": name_schema
,
291 "ssh_keys": {"type": "array", "items": {"type": "string"}},
292 "timeout_ns_deploy": integer1_schema
,
294 "vduImage": name_schema
,
301 "member-vnf-index": name_schema
,
302 "vimAccountId": id_schema
,
306 "items": ns_instantiate_vdu
,
311 "items": ns_instantiate_internal_vld
314 "required": ["member-vnf-index"],
316 "additionalProperties": False
325 "name": string_schema
,
326 "vim-network-name": {"OneOf": [string_schema
, object_schema
]},
327 "vim-network-id": {"OneOf": [string_schema
, object_schema
]},
328 "ns-net": object_schema
,
329 "wimAccountId": {"OneOf": [id_schema
, bool_schema
, null_schema
]},
330 "ip-profile": object_schema
,
331 "provider-network": provider_network_schema
,
332 "vnfd-connection-point-ref": {
338 "member-vnf-index-ref": name_schema
,
339 "vnfd-connection-point-ref": name_schema
,
340 "ip-address": ip_schema
,
341 # "mac-address": mac_schema,
343 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
345 "additionalProperties": False
349 "required": ["name"],
350 "additionalProperties": False
354 "required": ["nsName", "nsdId", "vimAccountId"],
355 "additionalProperties": False
359 "title": "ns terminate input schema",
360 "$schema": "http://json-schema.org/draft-04/schema#",
363 "lcmOperationType": string_schema
,
364 "nsInstanceId": id_schema
,
365 "autoremove": bool_schema
,
366 "timeout_ns_terminate": integer1_schema
,
367 "skip_terminate_primitives": bool_schema
,
369 "additionalProperties": False
372 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
373 "title": "ns action input schema",
374 "$schema": "http://json-schema.org/draft-04/schema#",
377 "lcmOperationType": string_schema
,
378 "nsInstanceId": id_schema
,
379 "member_vnf_index": name_schema
,
380 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
381 "vdu_id": name_schema
,
382 "vdu_count_index": integer0_schema
,
383 "kdu_name": name_schema
,
384 "primitive": name_schema
,
385 "timeout_ns_action": integer1_schema
,
386 "primitive_params": {"type": "object"},
388 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
389 "additionalProperties": False
391 ns_scale
= { # TODO for the moment it is only VDU-scaling
392 "title": "ns scale input schema",
393 "$schema": "http://json-schema.org/draft-04/schema#",
396 "lcmOperationType": string_schema
,
397 "nsInstanceId": id_schema
,
398 "scaleType": {"enum": ["SCALE_VNF"]},
399 "timeout_ns_scale": integer1_schema
,
403 "vnfInstanceId": name_schema
,
404 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
408 "scaling-group-descriptor": name_schema
,
409 "member-vnf-index": name_schema
,
410 "scaling-policy": name_schema
,
412 "required": ["scaling-group-descriptor", "member-vnf-index"],
413 "additionalProperties": False
416 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
417 "additionalProperties": False
419 "scaleTime": time_schema
,
421 "required": ["scaleType", "scaleVnfData"],
422 "additionalProperties": False
426 schema_version
= {"type": "string", "enum": ["1.0"]}
427 schema_type
= {"type": "string"}
428 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
430 vim_account_edit_schema
= {
431 "title": "vim_account edit input schema",
432 "$schema": "http://json-schema.org/draft-04/schema#",
436 "description": description_schema
,
438 "datacenter": name_schema
,
439 "vim_type": vim_type
,
440 "vim_url": description_schema
,
441 # "vim_url_admin": description_schema,
442 # "vim_tenant": name_schema,
443 "vim_tenant_name": name_schema
,
444 "vim_user": shortname_schema
,
445 "vim_password": passwd_schema
,
446 "config": {"type": "object"}
448 "additionalProperties": False
451 vim_account_new_schema
= {
452 "title": "vim_account creation input schema",
453 "$schema": "http://json-schema.org/draft-04/schema#",
456 "schema_version": schema_version
,
457 "schema_type": schema_type
,
459 "description": description_schema
,
461 "datacenter": name_schema
,
462 "vim_type": vim_type
,
463 "vim_url": description_schema
,
464 # "vim_url_admin": description_schema,
465 # "vim_tenant": name_schema,
466 "vim_tenant_name": name_schema
,
467 "vim_user": shortname_schema
,
468 "vim_password": passwd_schema
,
469 "config": {"type": "object"}
471 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
472 "additionalProperties": False
475 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
477 wim_account_edit_schema
= {
478 "title": "wim_account edit input schema",
479 "$schema": "http://json-schema.org/draft-04/schema#",
483 "description": description_schema
,
485 "wim_type": wim_type
,
486 "wim_url": description_schema
,
487 "user": shortname_schema
,
488 "password": passwd_schema
,
489 "config": {"type": "object"}
491 "additionalProperties": False
494 wim_account_new_schema
= {
495 "title": "wim_account creation input schema",
496 "$schema": "http://json-schema.org/draft-04/schema#",
499 "schema_version": schema_version
,
500 "schema_type": schema_type
,
502 "description": description_schema
,
504 "wim_type": wim_type
,
505 "wim_url": description_schema
,
506 "user": shortname_schema
,
507 "password": passwd_schema
,
510 "patternProperties": {
511 ".": {"not": {"type": "null"}}
515 "required": ["name", "wim_url", "wim_type"],
516 "additionalProperties": False
521 "type": {"type": "string"},
522 "url": {"type": "string"},
523 "user": shortname_schema
,
524 "password": passwd_schema
,
525 "config": {"type": "object"},
526 "description": description_schema
,
527 # The folowing are deprecated. Maintanied for backward compatibility
531 "version": {"type": "string", "minLength": 1, "maxLength": 12},
534 "title": "sdn controller information schema",
535 "$schema": "http://json-schema.org/draft-04/schema#",
537 "properties": sdn_properties
,
538 "required": ["name", 'type'],
539 "additionalProperties": False
542 "title": "sdn controller update information schema",
543 "$schema": "http://json-schema.org/draft-04/schema#",
545 "properties": sdn_properties
,
546 # "required": ["name", "port", 'ip', 'dpid', 'type'],
547 "additionalProperties": False
549 sdn_port_mapping_schema
= {
550 "$schema": "http://json-schema.org/draft-04/schema#",
551 "title": "sdn port mapping information schema",
556 "compute_node": shortname_schema
,
562 "pci": pci_extended_schema
,
563 "switch_port": shortname_schema
,
564 "switch_mac": mac_schema
570 "required": ["compute_node", "ports"]
573 sdn_external_port_schema
= {
574 "$schema": "http://json-schema.org/draft-04/schema#",
575 "title": "External port information",
578 "port": {"type": "string", "minLength": 1, "maxLength": 60},
586 k8scluster_nets_schema
= {
587 "title": "k8scluster nets input schema",
588 "$schema": "http://json-schema.org/draft-04/schema#",
590 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
592 "additionalProperties": False
594 k8scluster_new_schema
= {
595 "title": "k8scluster creation input schema",
596 "$schema": "http://json-schema.org/draft-04/schema#",
599 "schema_version": schema_version
,
600 "schema_type": schema_type
,
602 "description": description_schema
,
603 "credentials": object_schema
,
604 "vim_account": id_schema
,
605 "k8s_version": string_schema
,
606 "nets": k8scluster_nets_schema
,
607 "namespace": name_schema
,
608 "cni": nameshort_list_schema
,
610 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
611 "additionalProperties": False
613 k8scluster_edit_schema
= {
614 "title": "vim_account edit input schema",
615 "$schema": "http://json-schema.org/draft-04/schema#",
619 "description": description_schema
,
620 "credentials": object_schema
,
621 "vim_account": id_schema
,
622 "k8s_version": string_schema
,
623 "nets": k8scluster_nets_schema
,
624 "namespace": name_schema
,
625 "cni": nameshort_list_schema
,
627 "additionalProperties": False
631 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
632 k8srepo_properties
= {
634 "description": description_schema
,
635 "type": k8srepo_types
,
636 "url": description_schema
,
638 k8srepo_new_schema
= {
639 "title": "k8scluster creation input schema",
640 "$schema": "http://json-schema.org/draft-04/schema#",
642 "properties": k8srepo_properties
,
643 "required": ["name", "type", "url"],
644 "additionalProperties": False
646 k8srepo_edit_schema
= {
647 "title": "vim_account edit input schema",
648 "$schema": "http://json-schema.org/draft-04/schema#",
650 "properties": k8srepo_properties
,
651 "additionalProperties": False
658 "name": shortname_schema
,
660 "type": {"enum": ["overlay", 'underlay']},
661 "ip-address": ip_schema
,
662 # TODO, add user, password, ssh-key
663 "mac-address": mac_schema
,
664 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
665 "vim-network-id": shortname_schema
,
666 # # provide this in case SDN assist must deal with this interface
667 # "switch-dpid": dpid_Schema,
668 # "switch-port": shortname_schema,
669 # "switch-mac": shortname_schema,
670 # "switch-vlan": vlan_schema,
672 "required": ["name", "mgmt", "ip-address"],
673 "additionalProperties": False
676 "title": "pdu creation input schema",
677 "$schema": "http://json-schema.org/draft-04/schema#",
680 "name": shortname_schema
,
681 "type": shortname_schema
,
682 "description": description_schema
,
683 "shared": bool_schema
,
684 "vims": nameshort_list_schema
,
685 "vim_accounts": nameshort_list_schema
,
688 "items": pdu_interface
,
692 "required": ["name", "type", "interfaces"],
693 "additionalProperties": False
696 "title": "pdu edit input schema",
697 "$schema": "http://json-schema.org/draft-04/schema#",
700 "name": shortname_schema
,
701 "type": shortname_schema
,
702 "description": description_schema
,
703 "shared": bool_schema
,
704 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
705 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
706 "interfaces": {"oneOf": [
707 array_edition_schema
,
710 "items": pdu_interface
,
715 "additionalProperties": False,
720 vnfpkgop_new_schema
= {
721 "title": "VNF PKG operation creation input schema",
722 "$schema": "http://json-schema.org/draft-04/schema#",
725 "lcmOperationType": string_schema
,
726 "vnfPkgId": id_schema
,
727 "kdu_name": name_schema
,
728 "primitive": name_schema
,
729 "primitive_params": {"type": "object"},
731 "required": ["lcmOperationType", "vnfPkgId", "kdu_name", "primitive", "primitive_params"],
732 "additionalProperties": False
736 project_role_mappings
= {
737 "title": "list pf projects/roles",
738 "$schema": "http://json-schema.org/draft-04/schema#",
743 "project": shortname_schema
,
744 "role": shortname_schema
746 "required": ["project", "role"],
747 "additionalProperties": False
751 project_role_mappings_optional
= {
752 "title": "list of projects/roles or projects only",
753 "$schema": "http://json-schema.org/draft-04/schema#",
758 "project": shortname_schema
,
759 "role": shortname_schema
761 "required": ["project"],
762 "additionalProperties": False
767 "$schema": "http://json-schema.org/draft-04/schema#",
768 "title": "New user schema",
771 "username": shortname_schema
,
772 "domain_name": shortname_schema
,
773 "password": passwd_schema
,
774 "projects": nameshort_list_schema
,
775 "project_role_mappings": project_role_mappings
,
777 "required": ["username", "password"],
778 "additionalProperties": False
781 "$schema": "http://json-schema.org/draft-04/schema#",
782 "title": "User edit schema for administrators",
785 "password": passwd_schema
,
786 "username": shortname_schema
, # To allow User Name modification
789 nameshort_list_schema
,
793 "project_role_mappings": project_role_mappings
,
794 "add_project_role_mappings": project_role_mappings
,
795 "remove_project_role_mappings": project_role_mappings_optional
,
798 "additionalProperties": False
802 topics_with_quota
= ["vnfds", "nsds", "nsts", "pdus", "nsrs", "nsis", "vim_accounts", "wim_accounts", "sdns",
803 "k8sclusters", "k8srepos"]
804 project_new_schema
= {
805 "$schema": "http://json-schema.org/draft-04/schema#",
806 "title": "New project schema for administrators",
809 "name": shortname_schema
,
810 "admin": bool_schema
,
811 "domain_name": shortname_schema
,
814 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
815 "additionalProperties": False
818 "required": ["name"],
819 "additionalProperties": False
821 project_edit_schema
= {
822 "$schema": "http://json-schema.org/draft-04/schema#",
823 "title": "Project edit schema for administrators",
826 "admin": bool_schema
,
827 "name": shortname_schema
, # To allow Project Name modification
830 "properties": {topic
: {"oneOf": [integer0_schema
, null_schema
]} for topic
in topics_with_quota
},
831 "additionalProperties": False
834 "additionalProperties": False,
840 "$schema": "http://json-schema.org/draft-04/schema#",
841 "title": "New role schema for administrators",
844 "name": shortname_schema
,
847 "patternProperties": {
850 # "minProperties": 1,
853 "required": ["name"],
854 "additionalProperties": False
856 roles_edit_schema
= {
857 "$schema": "http://json-schema.org/draft-04/schema#",
858 "title": "Roles edit schema for administrators",
861 "name": shortname_schema
,
864 "patternProperties": {
866 "oneOf": [bool_schema
, null_schema
]
869 # "minProperties": 1,
872 "additionalProperties": False,
878 nbi_new_input_schemas
= {
879 "users": user_new_schema
,
880 "projects": project_new_schema
,
881 "vim_accounts": vim_account_new_schema
,
882 "sdns": sdn_new_schema
,
883 "ns_instantiate": ns_instantiate
,
884 "ns_action": ns_action
,
885 "ns_scale": ns_scale
,
886 "pdus": pdu_new_schema
,
889 nbi_edit_input_schemas
= {
890 "users": user_edit_schema
,
891 "projects": project_edit_schema
,
892 "vim_accounts": vim_account_edit_schema
,
893 "sdns": sdn_edit_schema
,
894 "pdus": pdu_edit_schema
,
898 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
899 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
900 nsi_subnet_instantiate
["properties"]["id"] = name_schema
901 del nsi_subnet_instantiate
["required"]
903 nsi_vld_instantiate
= {
904 "title": "netslice vld instantiation params input schema",
905 "$schema": "http://json-schema.org/draft-04/schema#",
908 "name": string_schema
,
909 "vim-network-name": {"OneOf": [string_schema
, object_schema
]},
910 "vim-network-id": {"OneOf": [string_schema
, object_schema
]},
911 "ip-profile": object_schema
,
913 "required": ["name"],
914 "additionalProperties": False
918 "title": "netslice action instantiate input schema",
919 "$schema": "http://json-schema.org/draft-04/schema#",
922 "lcmOperationType": string_schema
,
923 "netsliceInstanceId": id_schema
,
924 "nsiName": name_schema
,
925 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
926 "nstId": string_schema
,
927 "vimAccountId": id_schema
,
928 "timeout_nsi_deploy": integer1_schema
,
929 "ssh_keys": {"type": "string"},
931 "additionalParamsForNsi": object_schema
,
935 "items": nsi_subnet_instantiate
940 "items": nsi_vld_instantiate
943 "required": ["nsiName", "nstId", "vimAccountId"],
944 "additionalProperties": False
956 class ValidationError(Exception):
957 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
958 self
.http_code
= http_code
959 Exception.__init
__(self
, message
)
962 def validate_input(indata
, schema_to_use
):
964 Validates input data against json schema
965 :param indata: user input data. Should be a dictionary
966 :param schema_to_use: jsonschema to test
967 :return: None if ok, raises ValidationError exception on error
971 js_v(indata
, schema_to_use
)
973 except js_e
.ValidationError
as e
:
975 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
978 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
979 except js_e
.SchemaError
:
980 raise ValidationError("Bad json schema {}".format(schema_to_use
), http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
)
983 def is_valid_uuid(x
):
985 Test for a valid UUID
986 :param x: string to test
987 :return: True if x is a valid uuid, False otherwise
992 except (TypeError, ValueError, AttributeError):