1 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from jsonschema
import validate
as js_v
, exceptions
as js_e
17 from http
import HTTPStatus
18 from copy
import deepcopy
19 from uuid
import UUID
# To test for valid UUID
21 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
23 version_date
= "Mar 2018"
26 Validator of input data using JSON schemas for those items that not contains an OSM yang information model
30 patern_name
= "^[ -~]+$"
35 "pattern": "^[^,;()\\.\\$'\"]+$",
37 passwd_schema
= {"type": "string", "minLength": 1, "maxLength": 60}
42 "pattern": "^[^,;()'\"]+$",
44 string_schema
= {"type": "string", "minLength": 1, "maxLength": 255}
51 description_schema
= {
52 "type": ["string", "null"],
54 "pattern": "^[^'\"]+$",
56 long_description_schema
= {
57 "type": ["string", "null"],
59 "pattern": "^[^'\"]+$",
61 id_schema_fake
= {"type": "string", "minLength": 2, "maxLength": 36}
62 bool_schema
= {"type": "boolean"}
63 null_schema
= {"type": "null"}
64 # "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
67 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
71 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}",
75 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$",
77 # allows [] for wildcards. For that reason huge length limit is set
78 pci_extended_schema
= {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
79 http_schema
= {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
80 bandwidth_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
81 memory_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
82 integer0_schema
= {"type": "integer", "minimum": 0}
83 integer1_schema
= {"type": "integer", "minimum": 1}
84 path_schema
= {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
85 vlan_schema
= {"type": "integer", "minimum": 1, "maximum": 4095}
86 vlan1000_schema
= {"type": "integer", "minimum": 1000, "maximum": 4095}
89 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$",
90 } # must be unicast: LSB bit of MSB byte ==0
91 dpid_Schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
92 # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
95 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$",
99 "pattern": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))",
103 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
104 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
106 port_schema
= {"type": "integer", "minimum": 1, "maximum": 65534}
107 object_schema
= {"type": "object"}
108 schema_version_2
= {"type": "integer", "minimum": 2, "maximum": 2}
109 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
112 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
114 checksum_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
115 size_schema
= {"type": "integer", "minimum": 1, "maximum": 100}
116 array_edition_schema
= {
118 "patternProperties": {"^\\$": {}},
119 "additionalProperties": False,
122 nameshort_list_schema
= {
125 "items": shortname_schema
,
128 description_list_schema
= {
131 "items": description_schema
,
134 ns_instantiate_vdu
= {
135 "title": "ns action instantiate input schema for vdu",
136 "$schema": "http://json-schema.org/draft-04/schema#",
147 "vim-volume-id": name_schema
,
149 "required": ["name", "vim-volume-id"],
150 "additionalProperties": False,
160 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
161 "mac-address": mac_schema
,
162 "floating-ip-required": bool_schema
,
164 "required": ["name"],
165 "additionalProperties": False,
170 "additionalProperties": False,
173 ip_profile_dns_schema
= {
179 "address": {"oneOf": [ip_schema
, ipv6_schema
]},
181 "required": ["address"],
182 "additionalProperties": False,
186 ip_profile_dhcp_schema
= {
189 "enabled": {"type": "boolean"},
190 "count": integer1_schema
,
191 "start-address": ip_schema
,
193 "additionalProperties": False,
196 ip_profile_schema
= {
197 "title": "ip profile validation schema",
198 "$schema": "http://json-schema.org/draft-04/schema#",
201 "ip-version": {"enum": ["ipv4", "ipv6"]},
202 "subnet-address": ip_prefix_schema
,
203 "gateway-address": ip_schema
,
204 "dns-server": ip_profile_dns_schema
,
205 "dhcp-params": ip_profile_dhcp_schema
,
209 ip_profile_update_schema
= {
210 "title": "ip profile validation schema",
211 "$schema": "http://json-schema.org/draft-04/schema#",
214 "ip-version": {"enum": ["ipv4", "ipv6"]},
215 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
216 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
217 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
218 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
220 "additionalProperties": False,
223 provider_network_schema
= {
224 "title": "provider network validation schema",
225 "$schema": "http://json-schema.org/draft-04/schema#",
228 "physical-network": name_schema
,
229 "segmentation-id": name_schema
,
230 "sdn-ports": { # external ports to append to the SDN-assist network
235 "switch_id": shortname_schema
,
236 "switch_port": shortname_schema
,
237 "mac_address": mac_schema
,
240 "additionalProperties": True,
243 "network-type": shortname_schema
,
245 "additionalProperties": True,
248 ns_instantiate_internal_vld
= {
249 "title": "ns action instantiate input schema for vld",
250 "$schema": "http://json-schema.org/draft-04/schema#",
254 "vim-network-name": name_schema
,
255 "vim-network-id": name_schema
,
256 "ip-profile": ip_profile_update_schema
,
257 "provider-network": provider_network_schema
,
258 "internal-connection-point": {
264 "id-ref": name_schema
,
265 "ip-address": ip_schema
,
266 # "mac-address": mac_schema,
268 "required": ["id-ref"],
270 "additionalProperties": False,
274 "required": ["name"],
276 "additionalProperties": False,
279 additional_params_for_vnf
= {
284 "member-vnf-index": name_schema
,
285 "additionalParams": object_schema
,
286 "k8s-namespace": name_schema
,
287 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
288 "additionalParamsForVdu": {
293 "vdu_id": name_schema
,
294 "additionalParams": object_schema
,
295 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
297 "required": ["vdu_id"],
299 "additionalProperties": False,
302 "additionalParamsForKdu": {
307 "kdu_name": name_schema
,
308 "additionalParams": object_schema
,
309 "kdu_model": name_schema
,
310 "k8s-namespace": name_schema
,
311 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
312 "kdu-deployment-name": name_schema
,
314 "required": ["kdu_name"],
316 "additionalProperties": False,
319 "affinity-or-anti-affinity-group": {
325 "vim-affinity-group-id": name_schema
,
329 "additionalProperties": False,
333 "required": ["member-vnf-index"],
335 "additionalProperties": False,
340 "title": "ns action instantiate input schema",
341 "$schema": "http://json-schema.org/draft-04/schema#",
344 "lcmOperationType": string_schema
,
345 "nsInstanceId": id_schema
,
346 "netsliceInstanceId": id_schema
,
347 "nsName": name_schema
,
348 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
350 "vimAccountId": id_schema
,
351 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
352 "placement-engine": string_schema
,
353 "placement-constraints": object_schema
,
354 "additionalParamsForNs": object_schema
,
355 "additionalParamsForVnf": additional_params_for_vnf
,
356 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
357 "k8s-namespace": name_schema
,
358 "ssh_keys": {"type": "array", "items": {"type": "string"}},
359 "timeout_ns_deploy": integer1_schema
,
361 "vduImage": name_schema
,
368 "member-vnf-index": name_schema
,
369 "vimAccountId": id_schema
,
373 "items": ns_instantiate_vdu
,
378 "items": ns_instantiate_internal_vld
,
381 "required": ["member-vnf-index"],
383 "additionalProperties": False,
392 "name": string_schema
,
393 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
394 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
395 "ns-net": object_schema
,
396 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
397 "ip-profile": object_schema
,
398 "provider-network": provider_network_schema
,
399 "vnfd-connection-point-ref": {
405 "member-vnf-index-ref": name_schema
,
406 "vnfd-connection-point-ref": name_schema
,
407 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
408 # "mac-address": mac_schema,
411 "member-vnf-index-ref",
412 "vnfd-connection-point-ref",
415 "additionalProperties": False,
419 "required": ["name"],
420 "additionalProperties": False,
424 "required": ["nsName", "nsdId", "vimAccountId"],
425 "additionalProperties": False,
429 "title": "ns terminate input schema",
430 "$schema": "http://json-schema.org/draft-04/schema#",
433 "lcmOperationType": string_schema
,
434 "nsInstanceId": id_schema
,
435 "autoremove": bool_schema
,
436 "timeout_ns_terminate": integer1_schema
,
437 "skip_terminate_primitives": bool_schema
,
438 "netsliceInstanceId": id_schema
,
440 "additionalProperties": False,
443 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
444 "title": "ns action input schema",
445 "$schema": "http://json-schema.org/draft-04/schema#",
448 "lcmOperationType": string_schema
,
449 "nsInstanceId": id_schema
,
450 "member_vnf_index": name_schema
,
451 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
452 "vdu_id": name_schema
,
453 "vdu_count_index": integer0_schema
,
454 "kdu_name": name_schema
,
455 "primitive": name_schema
,
456 "timeout_ns_action": integer1_schema
,
457 "primitive_params": {"type": "object"},
459 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
460 "additionalProperties": False,
462 ns_scale
= { # TODO for the moment it is only VDU-scaling
463 "title": "ns scale input schema",
464 "$schema": "http://json-schema.org/draft-04/schema#",
467 "lcmOperationType": string_schema
,
468 "nsInstanceId": id_schema
,
469 "scaleType": {"enum": ["SCALE_VNF"]},
470 "timeout_ns_scale": integer1_schema
,
474 "vnfInstanceId": name_schema
,
475 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
479 "scaling-group-descriptor": name_schema
,
480 "member-vnf-index": name_schema
,
481 "scaling-policy": name_schema
,
483 "required": ["scaling-group-descriptor", "member-vnf-index"],
484 "additionalProperties": False,
487 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
488 "additionalProperties": False,
490 "scaleTime": time_schema
,
492 "required": ["scaleType", "scaleVnfData"],
493 "additionalProperties": False,
497 schema_version
= {"type": "string", "enum": ["1.0"]}
498 schema_type
= {"type": "string"}
499 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
501 vim_account_edit_schema
= {
502 "title": "vim_account edit input schema",
503 "$schema": "http://json-schema.org/draft-04/schema#",
507 "description": description_schema
,
509 "datacenter": name_schema
,
510 "vim_type": vim_type
,
511 "vim_url": description_schema
,
512 # "vim_url_admin": description_schema,
513 # "vim_tenant": name_schema,
514 "vim_tenant_name": name_schema
,
515 "vim_user": string_schema
,
516 "vim_password": passwd_schema
,
518 "config": {"type": "object"},
520 "additionalProperties": False,
523 vim_account_new_schema
= {
524 "title": "vim_account creation input schema",
525 "$schema": "http://json-schema.org/draft-04/schema#",
528 "schema_version": schema_version
,
529 "schema_type": schema_type
,
531 "description": description_schema
,
533 "datacenter": name_schema
,
534 "vim_type": vim_type
,
535 "vim_url": description_schema
,
536 # "vim_url_admin": description_schema,
537 # "vim_tenant": name_schema,
538 "vim_tenant_name": name_schema
,
539 "vim_user": string_schema
,
540 "vim_password": passwd_schema
,
542 "config": {"type": "object"},
552 "additionalProperties": False,
555 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
557 wim_account_edit_schema
= {
558 "title": "wim_account edit input schema",
559 "$schema": "http://json-schema.org/draft-04/schema#",
563 "description": description_schema
,
565 "wim_type": wim_type
,
566 "wim_url": description_schema
,
567 "user": string_schema
,
568 "password": passwd_schema
,
569 "config": {"type": "object"},
571 "additionalProperties": False,
574 wim_account_new_schema
= {
575 "title": "wim_account creation input schema",
576 "$schema": "http://json-schema.org/draft-04/schema#",
579 "schema_version": schema_version
,
580 "schema_type": schema_type
,
582 "description": description_schema
,
584 "wim_type": wim_type
,
585 "wim_url": description_schema
,
586 "user": string_schema
,
587 "password": passwd_schema
,
590 "patternProperties": {".": {"not": {"type": "null"}}},
593 "required": ["name", "wim_url", "wim_type"],
594 "additionalProperties": False,
599 "type": {"type": "string"},
600 "url": {"type": "string"},
601 "user": string_schema
,
602 "password": passwd_schema
,
603 "config": {"type": "object"},
604 "description": description_schema
,
605 # The folowing are deprecated. Maintanied for backward compatibility
609 "version": {"type": "string", "minLength": 1, "maxLength": 12},
612 "title": "sdn controller information schema",
613 "$schema": "http://json-schema.org/draft-04/schema#",
615 "properties": sdn_properties
,
616 "required": ["name", "type"],
617 "additionalProperties": False,
620 "title": "sdn controller update information schema",
621 "$schema": "http://json-schema.org/draft-04/schema#",
623 "properties": sdn_properties
,
624 # "required": ["name", "port", 'ip', 'dpid', 'type'],
625 "additionalProperties": False,
627 sdn_port_mapping_schema
= {
628 "$schema": "http://json-schema.org/draft-04/schema#",
629 "title": "sdn port mapping information schema",
634 "compute_node": shortname_schema
,
640 "pci": pci_extended_schema
,
641 "switch_port": shortname_schema
,
642 "switch_mac": mac_schema
,
648 "required": ["compute_node", "ports"],
651 sdn_external_port_schema
= {
652 "$schema": "http://json-schema.org/draft-04/schema#",
653 "title": "External port information",
656 "port": {"type": "string", "minLength": 1, "maxLength": 60},
660 "required": ["port"],
664 k8scluster_nets_schema
= {
665 "title": "k8scluster nets input schema",
666 "$schema": "http://json-schema.org/draft-04/schema#",
668 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
670 "additionalProperties": False,
672 k8scluster_new_schema
= {
673 "title": "k8scluster creation input schema",
674 "$schema": "http://json-schema.org/draft-04/schema#",
677 "schema_version": schema_version
,
678 "schema_type": schema_type
,
680 "description": description_schema
,
681 "credentials": object_schema
,
682 "vim_account": id_schema
,
684 "k8s_version": string_schema
,
685 "nets": k8scluster_nets_schema
,
686 "namespace": name_schema
,
687 "cni": nameshort_list_schema
,
689 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
690 "additionalProperties": False,
692 k8scluster_edit_schema
= {
693 "title": "vim_account edit input schema",
694 "$schema": "http://json-schema.org/draft-04/schema#",
698 "description": description_schema
,
699 "credentials": object_schema
,
700 "vim_account": id_schema
,
702 "k8s_version": string_schema
,
703 "nets": k8scluster_nets_schema
,
704 "namespace": name_schema
,
705 "cni": nameshort_list_schema
,
707 "additionalProperties": False,
712 "title": "vca creation input schema",
713 "$schema": "http://json-schema.org/draft-04/schema#",
716 "schema_version": schema_version
,
717 "schema_type": schema_type
,
719 "description": description_schema
,
720 "endpoints": description_list_schema
,
721 "user": string_schema
,
722 "secret": passwd_schema
,
723 "cacert": long_description_schema
,
724 "lxd-cloud": shortname_schema
,
725 "lxd-credentials": shortname_schema
,
726 "k8s-cloud": shortname_schema
,
727 "k8s-credentials": shortname_schema
,
728 "model-config": object_schema
,
741 "additionalProperties": False,
744 "title": "vca creation input schema",
745 "$schema": "http://json-schema.org/draft-04/schema#",
749 "description": description_schema
,
750 "endpoints": description_list_schema
,
751 "port": integer1_schema
,
752 "user": string_schema
,
753 "secret": passwd_schema
,
754 "cacert": long_description_schema
,
755 "lxd-cloud": shortname_schema
,
756 "lxd-credentials": shortname_schema
,
757 "k8s-cloud": shortname_schema
,
758 "k8s-credentials": shortname_schema
,
759 "model-config": object_schema
,
761 "additionalProperties": False,
765 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
766 k8srepo_properties
= {
768 "description": description_schema
,
769 "type": k8srepo_types
,
770 "url": description_schema
,
772 k8srepo_new_schema
= {
773 "title": "k8scluster creation input schema",
774 "$schema": "http://json-schema.org/draft-04/schema#",
776 "properties": k8srepo_properties
,
777 "required": ["name", "type", "url"],
778 "additionalProperties": False,
780 k8srepo_edit_schema
= {
781 "title": "vim_account edit input schema",
782 "$schema": "http://json-schema.org/draft-04/schema#",
784 "properties": k8srepo_properties
,
785 "additionalProperties": False,
789 osmrepo_types
= {"enum": ["osm"]}
790 osmrepo_properties
= {
792 "description": description_schema
,
793 "type": osmrepo_types
,
794 "url": description_schema
795 # "user": string_schema,
796 # "password": passwd_schema
798 osmrepo_new_schema
= {
799 "title": "osm repo creation input schema",
800 "$schema": "http://json-schema.org/draft-04/schema#",
802 "properties": osmrepo_properties
,
803 "required": ["name", "type", "url"],
804 "additionalProperties": False,
806 osmrepo_edit_schema
= {
807 "title": "osm repo edit input schema",
808 "$schema": "http://json-schema.org/draft-04/schema#",
810 "properties": osmrepo_properties
,
811 "additionalProperties": False,
818 "name": shortname_schema
,
820 "type": {"enum": ["overlay", "underlay"]},
821 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
822 # TODO, add user, password, ssh-key
823 "mac-address": mac_schema
,
824 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
825 "vim-network-id": shortname_schema
,
826 # # provide this in case SDN assist must deal with this interface
827 # "switch-dpid": dpid_Schema,
828 # "switch-port": shortname_schema,
829 # "switch-mac": shortname_schema,
830 # "switch-vlan": vlan_schema,
832 "required": ["name", "mgmt", "ip-address"],
833 "additionalProperties": False,
836 "title": "pdu creation 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": nameshort_list_schema
,
845 "vim_accounts": nameshort_list_schema
,
846 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
848 "required": ["name", "type", "interfaces"],
849 "additionalProperties": False,
852 "title": "pdu edit input schema",
853 "$schema": "http://json-schema.org/draft-04/schema#",
856 "name": shortname_schema
,
857 "type": shortname_schema
,
858 "description": description_schema
,
859 "shared": bool_schema
,
860 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
861 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
864 array_edition_schema
,
865 {"type": "array", "items": pdu_interface
, "minItems": 1},
869 "additionalProperties": False,
874 vnfpkgop_new_schema
= {
875 "title": "VNF PKG operation creation input schema",
876 "$schema": "http://json-schema.org/draft-04/schema#",
879 "lcmOperationType": string_schema
,
880 "vnfPkgId": id_schema
,
881 "kdu_name": name_schema
,
882 "primitive": name_schema
,
883 "primitive_params": {"type": "object"},
892 "additionalProperties": False,
896 project_role_mappings
= {
897 "title": "list pf projects/roles",
898 "$schema": "http://json-schema.org/draft-04/schema#",
902 "properties": {"project": shortname_schema
, "role": shortname_schema
},
903 "required": ["project", "role"],
904 "additionalProperties": False,
908 project_role_mappings_optional
= {
909 "title": "list of projects/roles or projects only",
910 "$schema": "http://json-schema.org/draft-04/schema#",
914 "properties": {"project": shortname_schema
, "role": shortname_schema
},
915 "required": ["project"],
916 "additionalProperties": False,
921 "$schema": "http://json-schema.org/draft-04/schema#",
922 "title": "New user schema",
925 "username": string_schema
,
926 "domain_name": shortname_schema
,
927 "password": passwd_schema
,
928 "projects": nameshort_list_schema
,
929 "project_role_mappings": project_role_mappings
,
931 "required": ["username", "password"],
932 "additionalProperties": False,
935 "$schema": "http://json-schema.org/draft-04/schema#",
936 "title": "User edit schema for administrators",
939 "password": passwd_schema
,
940 "username": string_schema
, # To allow User Name modification
941 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
942 "project_role_mappings": project_role_mappings
,
943 "add_project_role_mappings": project_role_mappings
,
944 "remove_project_role_mappings": project_role_mappings_optional
,
947 "additionalProperties": False,
951 topics_with_quota
= [
967 project_new_schema
= {
968 "$schema": "http://json-schema.org/draft-04/schema#",
969 "title": "New project schema for administrators",
972 "name": shortname_schema
,
973 "admin": bool_schema
,
974 "domain_name": shortname_schema
,
977 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
978 "additionalProperties": False,
981 "required": ["name"],
982 "additionalProperties": False,
984 project_edit_schema
= {
985 "$schema": "http://json-schema.org/draft-04/schema#",
986 "title": "Project edit schema for administrators",
989 "admin": bool_schema
,
990 "name": shortname_schema
, # To allow Project Name modification
994 topic
: {"oneOf": [integer0_schema
, null_schema
]}
995 for topic
in topics_with_quota
997 "additionalProperties": False,
1000 "additionalProperties": False,
1005 roles_new_schema
= {
1006 "$schema": "http://json-schema.org/draft-04/schema#",
1007 "title": "New role schema for administrators",
1010 "name": shortname_schema
,
1013 "patternProperties": {
1016 # "minProperties": 1,
1019 "required": ["name"],
1020 "additionalProperties": False,
1022 roles_edit_schema
= {
1023 "$schema": "http://json-schema.org/draft-04/schema#",
1024 "title": "Roles edit schema for administrators",
1027 "name": shortname_schema
,
1030 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1031 # "minProperties": 1,
1034 "additionalProperties": False,
1040 nbi_new_input_schemas
= {
1041 "users": user_new_schema
,
1042 "projects": project_new_schema
,
1043 "vim_accounts": vim_account_new_schema
,
1044 "sdns": sdn_new_schema
,
1045 "ns_instantiate": ns_instantiate
,
1046 "ns_action": ns_action
,
1047 "ns_scale": ns_scale
,
1048 "pdus": pdu_new_schema
,
1051 nbi_edit_input_schemas
= {
1052 "users": user_edit_schema
,
1053 "projects": project_edit_schema
,
1054 "vim_accounts": vim_account_edit_schema
,
1055 "sdns": sdn_edit_schema
,
1056 "pdus": pdu_edit_schema
,
1060 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1061 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1062 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1063 del nsi_subnet_instantiate
["required"]
1065 nsi_vld_instantiate
= {
1066 "title": "netslice vld instantiation params input schema",
1067 "$schema": "http://json-schema.org/draft-04/schema#",
1070 "name": string_schema
,
1071 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1072 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1073 "ip-profile": object_schema
,
1075 "required": ["name"],
1076 "additionalProperties": False,
1080 "title": "netslice action instantiate input schema",
1081 "$schema": "http://json-schema.org/draft-04/schema#",
1084 "lcmOperationType": string_schema
,
1085 "netsliceInstanceId": id_schema
,
1086 "nsiName": name_schema
,
1087 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1088 "nstId": string_schema
,
1089 "vimAccountId": id_schema
,
1090 "timeout_nsi_deploy": integer1_schema
,
1091 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1092 "nsi_id": id_schema
,
1093 "additionalParamsForNsi": object_schema
,
1094 "netslice-subnet": {
1097 "items": nsi_subnet_instantiate
,
1099 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1101 "required": ["nsiName", "nstId", "vimAccountId"],
1102 "additionalProperties": False,
1109 nsinstancesubscriptionfilter_schema
= {
1110 "title": "instance identifier schema",
1111 "$schema": "http://json-schema.org/draft-07/schema#",
1114 "nsdIds": {"type": "array"},
1115 "vnfdIds": {"type": "array"},
1116 "pnfdIds": {"type": "array"},
1117 "nsInstanceIds": {"type": "array"},
1118 "nsInstanceNames": {"type": "array"},
1123 "title": "nslcmsubscription input schema",
1124 "$schema": "http://json-schema.org/draft-07/schema#",
1127 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1128 "notificationTypes": {
1132 "NsLcmOperationOccurrenceNotification",
1133 "NsChangeNotification",
1134 "NsIdentifierCreationNotification",
1135 "NsIdentifierDeletionNotification",
1141 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1143 "operationStates": {
1149 "PARTIALLY_COMPLETED",
1157 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1158 "lcmOpNameImpactingNsComponent": {
1164 "VNF_SCALE_TO_LEVEL",
1165 "VNF_CHANGE_FLAVOUR",
1169 "VNF_CHANGE_EXT_CONN",
1179 "lcmOpOccStatusImpactingNsComponent": {
1185 "PARTIALLY_COMPLETED",
1196 "notificationTypes": {
1197 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1203 {"required": ["operationTypes"]},
1204 {"required": ["operationStates"]},
1211 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1216 {"required": ["nsComponentTypes"]},
1217 {"required": ["lcmOpNameImpactingNsComponent"]},
1218 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1225 authentication_schema
= {
1226 "title": "authentication schema for subscription",
1227 "$schema": "http://json-schema.org/draft-07/schema#",
1230 "authType": {"enum": ["basic"]},
1234 "userName": string_schema
,
1235 "password": passwd_schema
,
1242 "title": "subscription input schema",
1243 "$schema": "http://json-schema.org/draft-07/schema#",
1246 "filter": nslcmsub_schema
,
1247 "CallbackUri": description_schema
,
1248 "authentication": authentication_schema
,
1250 "required": ["CallbackUri"],
1254 class ValidationError(Exception):
1255 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1256 self
.http_code
= http_code
1257 Exception.__init
__(self
, message
)
1260 def validate_input(indata
, schema_to_use
):
1262 Validates input data against json schema
1263 :param indata: user input data. Should be a dictionary
1264 :param schema_to_use: jsonschema to test
1265 :return: None if ok, raises ValidationError exception on error
1269 js_v(indata
, schema_to_use
)
1271 except js_e
.ValidationError
as e
:
1273 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1276 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1277 except js_e
.SchemaError
:
1278 raise ValidationError(
1279 "Bad json schema {}".format(schema_to_use
),
1280 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1284 def is_valid_uuid(x
):
1286 Test for a valid UUID
1287 :param x: string to test
1288 :return: True if x is a valid uuid, False otherwise
1293 except (TypeError, ValueError, AttributeError):