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": ip_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": ip_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 vdu",
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,
320 "required": ["member-vnf-index"],
322 "additionalProperties": False,
327 "title": "ns action instantiate input schema",
328 "$schema": "http://json-schema.org/draft-04/schema#",
331 "lcmOperationType": string_schema
,
332 "nsInstanceId": id_schema
,
333 "netsliceInstanceId": id_schema
,
334 "nsName": name_schema
,
335 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
337 "vimAccountId": id_schema
,
338 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
339 "placement-engine": string_schema
,
340 "placement-constraints": object_schema
,
341 "additionalParamsForNs": object_schema
,
342 "additionalParamsForVnf": additional_params_for_vnf
,
343 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
344 "k8s-namespace": name_schema
,
345 "ssh_keys": {"type": "array", "items": {"type": "string"}},
346 "timeout_ns_deploy": integer1_schema
,
348 "vduImage": name_schema
,
355 "member-vnf-index": name_schema
,
356 "vimAccountId": id_schema
,
360 "items": ns_instantiate_vdu
,
365 "items": ns_instantiate_internal_vld
,
368 "required": ["member-vnf-index"],
370 "additionalProperties": False,
379 "name": string_schema
,
380 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
381 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
382 "ns-net": object_schema
,
383 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
384 "ip-profile": object_schema
,
385 "provider-network": provider_network_schema
,
386 "vnfd-connection-point-ref": {
392 "member-vnf-index-ref": name_schema
,
393 "vnfd-connection-point-ref": name_schema
,
394 "ip-address": ip_schema
,
395 # "mac-address": mac_schema,
398 "member-vnf-index-ref",
399 "vnfd-connection-point-ref",
402 "additionalProperties": False,
406 "required": ["name"],
407 "additionalProperties": False,
411 "required": ["nsName", "nsdId", "vimAccountId"],
412 "additionalProperties": False,
416 "title": "ns terminate input schema",
417 "$schema": "http://json-schema.org/draft-04/schema#",
420 "lcmOperationType": string_schema
,
421 "nsInstanceId": id_schema
,
422 "autoremove": bool_schema
,
423 "timeout_ns_terminate": integer1_schema
,
424 "skip_terminate_primitives": bool_schema
,
425 "netsliceInstanceId": id_schema
,
427 "additionalProperties": False,
430 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
431 "title": "ns action input schema",
432 "$schema": "http://json-schema.org/draft-04/schema#",
435 "lcmOperationType": string_schema
,
436 "nsInstanceId": id_schema
,
437 "member_vnf_index": name_schema
,
438 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
439 "vdu_id": name_schema
,
440 "vdu_count_index": integer0_schema
,
441 "kdu_name": name_schema
,
442 "primitive": name_schema
,
443 "timeout_ns_action": integer1_schema
,
444 "primitive_params": {"type": "object"},
446 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
447 "additionalProperties": False,
449 ns_scale
= { # TODO for the moment it is only VDU-scaling
450 "title": "ns scale input schema",
451 "$schema": "http://json-schema.org/draft-04/schema#",
454 "lcmOperationType": string_schema
,
455 "nsInstanceId": id_schema
,
456 "scaleType": {"enum": ["SCALE_VNF"]},
457 "timeout_ns_scale": integer1_schema
,
461 "vnfInstanceId": name_schema
,
462 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
466 "scaling-group-descriptor": name_schema
,
467 "member-vnf-index": name_schema
,
468 "scaling-policy": name_schema
,
470 "required": ["scaling-group-descriptor", "member-vnf-index"],
471 "additionalProperties": False,
474 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
475 "additionalProperties": False,
477 "scaleTime": time_schema
,
479 "required": ["scaleType", "scaleVnfData"],
480 "additionalProperties": False,
484 schema_version
= {"type": "string", "enum": ["1.0"]}
485 schema_type
= {"type": "string"}
486 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
488 vim_account_edit_schema
= {
489 "title": "vim_account edit input schema",
490 "$schema": "http://json-schema.org/draft-04/schema#",
494 "description": description_schema
,
496 "datacenter": name_schema
,
497 "vim_type": vim_type
,
498 "vim_url": description_schema
,
499 # "vim_url_admin": description_schema,
500 # "vim_tenant": name_schema,
501 "vim_tenant_name": name_schema
,
502 "vim_user": string_schema
,
503 "vim_password": passwd_schema
,
505 "config": {"type": "object"},
507 "additionalProperties": False,
510 vim_account_new_schema
= {
511 "title": "vim_account creation input schema",
512 "$schema": "http://json-schema.org/draft-04/schema#",
515 "schema_version": schema_version
,
516 "schema_type": schema_type
,
518 "description": description_schema
,
520 "datacenter": name_schema
,
521 "vim_type": vim_type
,
522 "vim_url": description_schema
,
523 # "vim_url_admin": description_schema,
524 # "vim_tenant": name_schema,
525 "vim_tenant_name": name_schema
,
526 "vim_user": string_schema
,
527 "vim_password": passwd_schema
,
529 "config": {"type": "object"},
539 "additionalProperties": False,
542 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
544 wim_account_edit_schema
= {
545 "title": "wim_account edit input schema",
546 "$schema": "http://json-schema.org/draft-04/schema#",
550 "description": description_schema
,
552 "wim_type": wim_type
,
553 "wim_url": description_schema
,
554 "user": string_schema
,
555 "password": passwd_schema
,
556 "config": {"type": "object"},
558 "additionalProperties": False,
561 wim_account_new_schema
= {
562 "title": "wim_account creation input schema",
563 "$schema": "http://json-schema.org/draft-04/schema#",
566 "schema_version": schema_version
,
567 "schema_type": schema_type
,
569 "description": description_schema
,
571 "wim_type": wim_type
,
572 "wim_url": description_schema
,
573 "user": string_schema
,
574 "password": passwd_schema
,
577 "patternProperties": {".": {"not": {"type": "null"}}},
580 "required": ["name", "wim_url", "wim_type"],
581 "additionalProperties": False,
586 "type": {"type": "string"},
587 "url": {"type": "string"},
588 "user": string_schema
,
589 "password": passwd_schema
,
590 "config": {"type": "object"},
591 "description": description_schema
,
592 # The folowing are deprecated. Maintanied for backward compatibility
596 "version": {"type": "string", "minLength": 1, "maxLength": 12},
599 "title": "sdn controller information schema",
600 "$schema": "http://json-schema.org/draft-04/schema#",
602 "properties": sdn_properties
,
603 "required": ["name", "type"],
604 "additionalProperties": False,
607 "title": "sdn controller update information schema",
608 "$schema": "http://json-schema.org/draft-04/schema#",
610 "properties": sdn_properties
,
611 # "required": ["name", "port", 'ip', 'dpid', 'type'],
612 "additionalProperties": False,
614 sdn_port_mapping_schema
= {
615 "$schema": "http://json-schema.org/draft-04/schema#",
616 "title": "sdn port mapping information schema",
621 "compute_node": shortname_schema
,
627 "pci": pci_extended_schema
,
628 "switch_port": shortname_schema
,
629 "switch_mac": mac_schema
,
635 "required": ["compute_node", "ports"],
638 sdn_external_port_schema
= {
639 "$schema": "http://json-schema.org/draft-04/schema#",
640 "title": "External port information",
643 "port": {"type": "string", "minLength": 1, "maxLength": 60},
647 "required": ["port"],
651 k8scluster_nets_schema
= {
652 "title": "k8scluster nets input schema",
653 "$schema": "http://json-schema.org/draft-04/schema#",
655 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
657 "additionalProperties": False,
659 k8scluster_new_schema
= {
660 "title": "k8scluster creation input schema",
661 "$schema": "http://json-schema.org/draft-04/schema#",
664 "schema_version": schema_version
,
665 "schema_type": schema_type
,
667 "description": description_schema
,
668 "credentials": object_schema
,
669 "vim_account": id_schema
,
671 "k8s_version": string_schema
,
672 "nets": k8scluster_nets_schema
,
673 "namespace": name_schema
,
674 "cni": nameshort_list_schema
,
676 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
677 "additionalProperties": False,
679 k8scluster_edit_schema
= {
680 "title": "vim_account edit input schema",
681 "$schema": "http://json-schema.org/draft-04/schema#",
685 "description": description_schema
,
686 "credentials": object_schema
,
687 "vim_account": id_schema
,
689 "k8s_version": string_schema
,
690 "nets": k8scluster_nets_schema
,
691 "namespace": name_schema
,
692 "cni": nameshort_list_schema
,
694 "additionalProperties": False,
699 "title": "vca creation input schema",
700 "$schema": "http://json-schema.org/draft-04/schema#",
703 "schema_version": schema_version
,
704 "schema_type": schema_type
,
706 "description": description_schema
,
707 "endpoints": description_list_schema
,
708 "user": string_schema
,
709 "secret": passwd_schema
,
710 "cacert": long_description_schema
,
711 "lxd-cloud": shortname_schema
,
712 "lxd-credentials": shortname_schema
,
713 "k8s-cloud": shortname_schema
,
714 "k8s-credentials": shortname_schema
,
715 "model-config": object_schema
,
728 "additionalProperties": False,
731 "title": "vca creation input schema",
732 "$schema": "http://json-schema.org/draft-04/schema#",
736 "description": description_schema
,
737 "endpoints": description_list_schema
,
738 "port": integer1_schema
,
739 "user": string_schema
,
740 "secret": passwd_schema
,
741 "cacert": long_description_schema
,
742 "lxd-cloud": shortname_schema
,
743 "lxd-credentials": shortname_schema
,
744 "k8s-cloud": shortname_schema
,
745 "k8s-credentials": shortname_schema
,
746 "model-config": object_schema
,
748 "additionalProperties": False,
752 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
753 k8srepo_properties
= {
755 "description": description_schema
,
756 "type": k8srepo_types
,
757 "url": description_schema
,
759 k8srepo_new_schema
= {
760 "title": "k8scluster creation input schema",
761 "$schema": "http://json-schema.org/draft-04/schema#",
763 "properties": k8srepo_properties
,
764 "required": ["name", "type", "url"],
765 "additionalProperties": False,
767 k8srepo_edit_schema
= {
768 "title": "vim_account edit input schema",
769 "$schema": "http://json-schema.org/draft-04/schema#",
771 "properties": k8srepo_properties
,
772 "additionalProperties": False,
776 osmrepo_types
= {"enum": ["osm"]}
777 osmrepo_properties
= {
779 "description": description_schema
,
780 "type": osmrepo_types
,
781 "url": description_schema
782 # "user": string_schema,
783 # "password": passwd_schema
785 osmrepo_new_schema
= {
786 "title": "osm repo creation input schema",
787 "$schema": "http://json-schema.org/draft-04/schema#",
789 "properties": osmrepo_properties
,
790 "required": ["name", "type", "url"],
791 "additionalProperties": False,
793 osmrepo_edit_schema
= {
794 "title": "osm repo edit input schema",
795 "$schema": "http://json-schema.org/draft-04/schema#",
797 "properties": osmrepo_properties
,
798 "additionalProperties": False,
805 "name": shortname_schema
,
807 "type": {"enum": ["overlay", "underlay"]},
808 "ip-address": {"oneOf": [ip_schema
, ipv6_schema
]},
809 # TODO, add user, password, ssh-key
810 "mac-address": mac_schema
,
811 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
812 "vim-network-id": shortname_schema
,
813 # # provide this in case SDN assist must deal with this interface
814 # "switch-dpid": dpid_Schema,
815 # "switch-port": shortname_schema,
816 # "switch-mac": shortname_schema,
817 # "switch-vlan": vlan_schema,
819 "required": ["name", "mgmt", "ip-address"],
820 "additionalProperties": False,
823 "title": "pdu creation input schema",
824 "$schema": "http://json-schema.org/draft-04/schema#",
827 "name": shortname_schema
,
828 "type": shortname_schema
,
829 "description": description_schema
,
830 "shared": bool_schema
,
831 "vims": nameshort_list_schema
,
832 "vim_accounts": nameshort_list_schema
,
833 "interfaces": {"type": "array", "items": pdu_interface
, "minItems": 1},
835 "required": ["name", "type", "interfaces"],
836 "additionalProperties": False,
839 "title": "pdu edit input schema",
840 "$schema": "http://json-schema.org/draft-04/schema#",
843 "name": shortname_schema
,
844 "type": shortname_schema
,
845 "description": description_schema
,
846 "shared": bool_schema
,
847 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
848 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
851 array_edition_schema
,
852 {"type": "array", "items": pdu_interface
, "minItems": 1},
856 "additionalProperties": False,
861 vnfpkgop_new_schema
= {
862 "title": "VNF PKG operation creation input schema",
863 "$schema": "http://json-schema.org/draft-04/schema#",
866 "lcmOperationType": string_schema
,
867 "vnfPkgId": id_schema
,
868 "kdu_name": name_schema
,
869 "primitive": name_schema
,
870 "primitive_params": {"type": "object"},
879 "additionalProperties": False,
883 project_role_mappings
= {
884 "title": "list pf projects/roles",
885 "$schema": "http://json-schema.org/draft-04/schema#",
889 "properties": {"project": shortname_schema
, "role": shortname_schema
},
890 "required": ["project", "role"],
891 "additionalProperties": False,
895 project_role_mappings_optional
= {
896 "title": "list of projects/roles or projects only",
897 "$schema": "http://json-schema.org/draft-04/schema#",
901 "properties": {"project": shortname_schema
, "role": shortname_schema
},
902 "required": ["project"],
903 "additionalProperties": False,
908 "$schema": "http://json-schema.org/draft-04/schema#",
909 "title": "New user schema",
912 "username": string_schema
,
913 "domain_name": shortname_schema
,
914 "password": passwd_schema
,
915 "projects": nameshort_list_schema
,
916 "project_role_mappings": project_role_mappings
,
918 "required": ["username", "password"],
919 "additionalProperties": False,
922 "$schema": "http://json-schema.org/draft-04/schema#",
923 "title": "User edit schema for administrators",
926 "password": passwd_schema
,
927 "username": string_schema
, # To allow User Name modification
928 "projects": {"oneOf": [nameshort_list_schema
, array_edition_schema
]},
929 "project_role_mappings": project_role_mappings
,
930 "add_project_role_mappings": project_role_mappings
,
931 "remove_project_role_mappings": project_role_mappings_optional
,
934 "additionalProperties": False,
938 topics_with_quota
= [
954 project_new_schema
= {
955 "$schema": "http://json-schema.org/draft-04/schema#",
956 "title": "New project schema for administrators",
959 "name": shortname_schema
,
960 "admin": bool_schema
,
961 "domain_name": shortname_schema
,
964 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
965 "additionalProperties": False,
968 "required": ["name"],
969 "additionalProperties": False,
971 project_edit_schema
= {
972 "$schema": "http://json-schema.org/draft-04/schema#",
973 "title": "Project edit schema for administrators",
976 "admin": bool_schema
,
977 "name": shortname_schema
, # To allow Project Name modification
981 topic
: {"oneOf": [integer0_schema
, null_schema
]}
982 for topic
in topics_with_quota
984 "additionalProperties": False,
987 "additionalProperties": False,
993 "$schema": "http://json-schema.org/draft-04/schema#",
994 "title": "New role schema for administrators",
997 "name": shortname_schema
,
1000 "patternProperties": {
1003 # "minProperties": 1,
1006 "required": ["name"],
1007 "additionalProperties": False,
1009 roles_edit_schema
= {
1010 "$schema": "http://json-schema.org/draft-04/schema#",
1011 "title": "Roles edit schema for administrators",
1014 "name": shortname_schema
,
1017 "patternProperties": {".": {"oneOf": [bool_schema
, null_schema
]}},
1018 # "minProperties": 1,
1021 "additionalProperties": False,
1027 nbi_new_input_schemas
= {
1028 "users": user_new_schema
,
1029 "projects": project_new_schema
,
1030 "vim_accounts": vim_account_new_schema
,
1031 "sdns": sdn_new_schema
,
1032 "ns_instantiate": ns_instantiate
,
1033 "ns_action": ns_action
,
1034 "ns_scale": ns_scale
,
1035 "pdus": pdu_new_schema
,
1038 nbi_edit_input_schemas
= {
1039 "users": user_edit_schema
,
1040 "projects": project_edit_schema
,
1041 "vim_accounts": vim_account_edit_schema
,
1042 "sdns": sdn_edit_schema
,
1043 "pdus": pdu_edit_schema
,
1047 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
1048 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
1049 nsi_subnet_instantiate
["properties"]["id"] = name_schema
1050 del nsi_subnet_instantiate
["required"]
1052 nsi_vld_instantiate
= {
1053 "title": "netslice vld instantiation params input schema",
1054 "$schema": "http://json-schema.org/draft-04/schema#",
1057 "name": string_schema
,
1058 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1059 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1060 "ip-profile": object_schema
,
1062 "required": ["name"],
1063 "additionalProperties": False,
1067 "title": "netslice action instantiate input schema",
1068 "$schema": "http://json-schema.org/draft-04/schema#",
1071 "lcmOperationType": string_schema
,
1072 "netsliceInstanceId": id_schema
,
1073 "nsiName": name_schema
,
1074 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1075 "nstId": string_schema
,
1076 "vimAccountId": id_schema
,
1077 "timeout_nsi_deploy": integer1_schema
,
1078 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1079 "nsi_id": id_schema
,
1080 "additionalParamsForNsi": object_schema
,
1081 "netslice-subnet": {
1084 "items": nsi_subnet_instantiate
,
1086 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate
},
1088 "required": ["nsiName", "nstId", "vimAccountId"],
1089 "additionalProperties": False,
1096 nsinstancesubscriptionfilter_schema
= {
1097 "title": "instance identifier schema",
1098 "$schema": "http://json-schema.org/draft-07/schema#",
1101 "nsdIds": {"type": "array"},
1102 "vnfdIds": {"type": "array"},
1103 "pnfdIds": {"type": "array"},
1104 "nsInstanceIds": {"type": "array"},
1105 "nsInstanceNames": {"type": "array"},
1110 "title": "nslcmsubscription input schema",
1111 "$schema": "http://json-schema.org/draft-07/schema#",
1114 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1115 "notificationTypes": {
1119 "NsLcmOperationOccurrenceNotification",
1120 "NsChangeNotification",
1121 "NsIdentifierCreationNotification",
1122 "NsIdentifierDeletionNotification",
1128 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
1130 "operationStates": {
1136 "PARTIALLY_COMPLETED",
1144 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
1145 "lcmOpNameImpactingNsComponent": {
1151 "VNF_SCALE_TO_LEVEL",
1152 "VNF_CHANGE_FLAVOUR",
1156 "VNF_CHANGE_EXT_CONN",
1166 "lcmOpOccStatusImpactingNsComponent": {
1172 "PARTIALLY_COMPLETED",
1183 "notificationTypes": {
1184 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1190 {"required": ["operationTypes"]},
1191 {"required": ["operationStates"]},
1198 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
1203 {"required": ["nsComponentTypes"]},
1204 {"required": ["lcmOpNameImpactingNsComponent"]},
1205 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1212 authentication_schema
= {
1213 "title": "authentication schema for subscription",
1214 "$schema": "http://json-schema.org/draft-07/schema#",
1217 "authType": {"enum": ["basic"]},
1221 "userName": string_schema
,
1222 "password": passwd_schema
,
1229 "title": "subscription input schema",
1230 "$schema": "http://json-schema.org/draft-07/schema#",
1233 "filter": nslcmsub_schema
,
1234 "CallbackUri": description_schema
,
1235 "authentication": authentication_schema
,
1237 "required": ["CallbackUri"],
1241 class ValidationError(Exception):
1242 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1243 self
.http_code
= http_code
1244 Exception.__init
__(self
, message
)
1247 def validate_input(indata
, schema_to_use
):
1249 Validates input data against json schema
1250 :param indata: user input data. Should be a dictionary
1251 :param schema_to_use: jsonschema to test
1252 :return: None if ok, raises ValidationError exception on error
1256 js_v(indata
, schema_to_use
)
1258 except js_e
.ValidationError
as e
:
1260 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1263 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1264 except js_e
.SchemaError
:
1265 raise ValidationError(
1266 "Bad json schema {}".format(schema_to_use
),
1267 http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
,
1271 def is_valid_uuid(x
):
1273 Test for a valid UUID
1274 :param x: string to test
1275 :return: True if x is a valid uuid, False otherwise
1280 except (TypeError, ValueError, AttributeError):