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 long_description_schema
= {"type": ["string", "null"], "maxLength": 3000, "pattern": "^[^'\"]+$"}
38 id_schema_fake
= {"type": "string", "minLength": 2, "maxLength": 36}
39 bool_schema
= {"type": "boolean"}
40 null_schema
= {"type": "null"}
41 # "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}$"
42 id_schema
= {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
43 time_schema
= {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"}
44 pci_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"}
45 # allows [] for wildcards. For that reason huge length limit is set
46 pci_extended_schema
= {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
47 http_schema
= {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
48 bandwidth_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
49 memory_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
50 integer0_schema
= {"type": "integer", "minimum": 0}
51 integer1_schema
= {"type": "integer", "minimum": 1}
52 path_schema
= {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
53 vlan_schema
= {"type": "integer", "minimum": 1, "maximum": 4095}
54 vlan1000_schema
= {"type": "integer", "minimum": 1000, "maximum": 4095}
55 mac_schema
= {"type": "string",
56 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0
57 dpid_Schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
58 # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
59 ip_schema
= {"type": "string",
60 "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]?)$"}
61 ip_prefix_schema
= {"type": "string",
62 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
63 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
64 port_schema
= {"type": "integer", "minimum": 1, "maximum": 65534}
65 object_schema
= {"type": "object"}
66 schema_version_2
= {"type": "integer", "minimum": 2, "maximum": 2}
67 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
68 log_level_schema
= {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
69 checksum_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
70 size_schema
= {"type": "integer", "minimum": 1, "maximum": 100}
71 array_edition_schema
= {
73 "patternProperties": {
76 "additionalProperties": False,
79 nameshort_list_schema
= {
82 "items": shortname_schema
,
85 description_list_schema
= {
88 "items": description_schema
,
91 ns_instantiate_vdu
= {
92 "title": "ns action instantiate input schema for vdu",
93 "$schema": "http://json-schema.org/draft-04/schema#",
104 "vim-volume-id": name_schema
,
106 "required": ["name", "vim-volume-id"],
107 "additionalProperties": False
117 "ip-address": ip_schema
,
118 "mac-address": mac_schema
,
119 "floating-ip-required": bool_schema
,
121 "required": ["name"],
122 "additionalProperties": False
127 "additionalProperties": False
130 ip_profile_dns_schema
= {
136 "address": ip_schema
,
138 "required": ["address"],
139 "additionalProperties": False
143 ip_profile_dhcp_schema
= {
146 "enabled": {"type": "boolean"},
147 "count": integer1_schema
,
148 "start-address": ip_schema
150 "additionalProperties": False,
153 ip_profile_schema
= {
154 "title": "ip profile validation schema",
155 "$schema": "http://json-schema.org/draft-04/schema#",
158 "ip-version": {"enum": ["ipv4", "ipv6"]},
159 "subnet-address": ip_prefix_schema
,
160 "gateway-address": ip_schema
,
161 "dns-server": ip_profile_dns_schema
,
162 "dhcp-params": ip_profile_dhcp_schema
,
166 ip_profile_update_schema
= {
167 "title": "ip profile validation schema",
168 "$schema": "http://json-schema.org/draft-04/schema#",
171 "ip-version": {"enum": ["ipv4", "ipv6"]},
172 "subnet-address": {"oneOf": [null_schema
, ip_prefix_schema
]},
173 "gateway-address": {"oneOf": [null_schema
, ip_schema
]},
174 "dns-server": {"oneOf": [null_schema
, ip_profile_dns_schema
]},
176 "dhcp-params": {"oneOf": [null_schema
, ip_profile_dhcp_schema
]},
178 "additionalProperties": False
181 provider_network_schema
= {
182 "title": "provider network validation schema",
183 "$schema": "http://json-schema.org/draft-04/schema#",
186 "physical-network": name_schema
,
187 "segmentation-id": name_schema
,
188 "sdn-ports": { # external ports to append to the SDN-assist network
193 "switch_id": shortname_schema
,
194 "switch_port": shortname_schema
,
195 "mac_address": mac_schema
,
198 "additionalProperties": True
201 "network-type": shortname_schema
,
203 "additionalProperties": True
206 ns_instantiate_internal_vld
= {
207 "title": "ns action instantiate input schema for vdu",
208 "$schema": "http://json-schema.org/draft-04/schema#",
212 "vim-network-name": name_schema
,
213 "vim-network-id": name_schema
,
214 "ip-profile": ip_profile_update_schema
,
215 "provider-network": provider_network_schema
,
216 "internal-connection-point": {
222 "id-ref": name_schema
,
223 "ip-address": ip_schema
,
224 # "mac-address": mac_schema,
226 "required": ["id-ref"],
228 "additionalProperties": False
232 "required": ["name"],
234 "additionalProperties": False
237 additional_params_for_vnf
= {
242 "member-vnf-index": name_schema
,
243 "additionalParams": object_schema
,
244 "k8s-namespace": name_schema
,
245 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
246 "additionalParamsForVdu": {
251 "vdu_id": name_schema
,
252 "additionalParams": object_schema
,
253 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
255 "required": ["vdu_id"],
257 "additionalProperties": False,
260 "additionalParamsForKdu": {
265 "kdu_name": name_schema
,
266 "additionalParams": object_schema
,
267 "kdu_model": name_schema
,
268 "k8s-namespace": name_schema
,
269 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
271 "required": ["kdu_name"],
273 "additionalProperties": False,
277 "required": ["member-vnf-index"],
279 "additionalProperties": False
284 "title": "ns action instantiate input schema",
285 "$schema": "http://json-schema.org/draft-04/schema#",
288 "lcmOperationType": string_schema
,
289 "nsInstanceId": id_schema
,
290 "netsliceInstanceId": id_schema
,
291 "nsName": name_schema
,
292 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
295 "vimAccountId": id_schema
,
296 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
297 "placement-engine": string_schema
,
298 "placement-constraints": object_schema
,
299 "additionalParamsForNs": object_schema
,
300 "additionalParamsForVnf": additional_params_for_vnf
,
301 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
302 "k8s-namespace": name_schema
,
303 "ssh_keys": {"type": "array", "items": {"type": "string"}},
304 "timeout_ns_deploy": integer1_schema
,
306 "vduImage": name_schema
,
313 "member-vnf-index": name_schema
,
314 "vimAccountId": id_schema
,
319 "items": ns_instantiate_vdu
,
324 "items": ns_instantiate_internal_vld
327 "required": ["member-vnf-index"],
329 "additionalProperties": False
338 "name": string_schema
,
339 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
340 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
341 "ns-net": object_schema
,
342 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
343 "ip-profile": object_schema
,
344 "provider-network": provider_network_schema
,
345 "vnfd-connection-point-ref": {
351 "member-vnf-index-ref": name_schema
,
352 "vnfd-connection-point-ref": name_schema
,
353 "ip-address": ip_schema
,
354 # "mac-address": mac_schema,
356 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
358 "additionalProperties": False
362 "required": ["name"],
363 "additionalProperties": False
367 "required": ["nsName", "nsdId", "vimAccountId"],
368 "additionalProperties": False
372 "title": "ns terminate input schema",
373 "$schema": "http://json-schema.org/draft-04/schema#",
376 "lcmOperationType": string_schema
,
377 "nsInstanceId": id_schema
,
378 "autoremove": bool_schema
,
379 "timeout_ns_terminate": integer1_schema
,
380 "skip_terminate_primitives": bool_schema
,
381 "netsliceInstanceId": id_schema
,
383 "additionalProperties": False
386 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
387 "title": "ns action input schema",
388 "$schema": "http://json-schema.org/draft-04/schema#",
391 "lcmOperationType": string_schema
,
392 "nsInstanceId": id_schema
,
393 "member_vnf_index": name_schema
,
394 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
395 "vdu_id": name_schema
,
396 "vdu_count_index": integer0_schema
,
397 "kdu_name": name_schema
,
398 "primitive": name_schema
,
399 "timeout_ns_action": integer1_schema
,
400 "primitive_params": {"type": "object"},
402 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
403 "additionalProperties": False
405 ns_scale
= { # TODO for the moment it is only VDU-scaling
406 "title": "ns scale input schema",
407 "$schema": "http://json-schema.org/draft-04/schema#",
410 "lcmOperationType": string_schema
,
411 "nsInstanceId": id_schema
,
412 "scaleType": {"enum": ["SCALE_VNF"]},
413 "timeout_ns_scale": integer1_schema
,
417 "vnfInstanceId": name_schema
,
418 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
422 "scaling-group-descriptor": name_schema
,
423 "member-vnf-index": name_schema
,
424 "scaling-policy": name_schema
,
426 "required": ["scaling-group-descriptor", "member-vnf-index"],
427 "additionalProperties": False
430 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
431 "additionalProperties": False
433 "scaleTime": time_schema
,
435 "required": ["scaleType", "scaleVnfData"],
436 "additionalProperties": False
440 schema_version
= {"type": "string", "enum": ["1.0"]}
441 schema_type
= {"type": "string"}
442 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
444 vim_account_edit_schema
= {
445 "title": "vim_account edit input schema",
446 "$schema": "http://json-schema.org/draft-04/schema#",
450 "description": description_schema
,
452 "datacenter": name_schema
,
453 "vim_type": vim_type
,
454 "vim_url": description_schema
,
455 # "vim_url_admin": description_schema,
456 # "vim_tenant": name_schema,
457 "vim_tenant_name": name_schema
,
458 "vim_user": shortname_schema
,
459 "vim_password": passwd_schema
,
461 "config": {"type": "object"}
463 "additionalProperties": False
466 vim_account_new_schema
= {
467 "title": "vim_account creation input schema",
468 "$schema": "http://json-schema.org/draft-04/schema#",
471 "schema_version": schema_version
,
472 "schema_type": schema_type
,
474 "description": description_schema
,
476 "datacenter": name_schema
,
477 "vim_type": vim_type
,
478 "vim_url": description_schema
,
479 # "vim_url_admin": description_schema,
480 # "vim_tenant": name_schema,
481 "vim_tenant_name": name_schema
,
482 "vim_user": shortname_schema
,
483 "vim_password": passwd_schema
,
485 "config": {"type": "object"}
487 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
488 "additionalProperties": False
491 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
493 wim_account_edit_schema
= {
494 "title": "wim_account edit input schema",
495 "$schema": "http://json-schema.org/draft-04/schema#",
499 "description": description_schema
,
501 "wim_type": wim_type
,
502 "wim_url": description_schema
,
503 "user": shortname_schema
,
504 "password": passwd_schema
,
505 "config": {"type": "object"}
507 "additionalProperties": False
510 wim_account_new_schema
= {
511 "title": "wim_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 "wim_type": wim_type
,
521 "wim_url": description_schema
,
522 "user": shortname_schema
,
523 "password": passwd_schema
,
526 "patternProperties": {
527 ".": {"not": {"type": "null"}}
531 "required": ["name", "wim_url", "wim_type"],
532 "additionalProperties": False
537 "type": {"type": "string"},
538 "url": {"type": "string"},
539 "user": shortname_schema
,
540 "password": passwd_schema
,
541 "config": {"type": "object"},
542 "description": description_schema
,
543 # The folowing are deprecated. Maintanied for backward compatibility
547 "version": {"type": "string", "minLength": 1, "maxLength": 12},
550 "title": "sdn controller information schema",
551 "$schema": "http://json-schema.org/draft-04/schema#",
553 "properties": sdn_properties
,
554 "required": ["name", 'type'],
555 "additionalProperties": False
558 "title": "sdn controller update information schema",
559 "$schema": "http://json-schema.org/draft-04/schema#",
561 "properties": sdn_properties
,
562 # "required": ["name", "port", 'ip', 'dpid', 'type'],
563 "additionalProperties": False
565 sdn_port_mapping_schema
= {
566 "$schema": "http://json-schema.org/draft-04/schema#",
567 "title": "sdn port mapping information schema",
572 "compute_node": shortname_schema
,
578 "pci": pci_extended_schema
,
579 "switch_port": shortname_schema
,
580 "switch_mac": mac_schema
586 "required": ["compute_node", "ports"]
589 sdn_external_port_schema
= {
590 "$schema": "http://json-schema.org/draft-04/schema#",
591 "title": "External port information",
594 "port": {"type": "string", "minLength": 1, "maxLength": 60},
602 k8scluster_nets_schema
= {
603 "title": "k8scluster nets input schema",
604 "$schema": "http://json-schema.org/draft-04/schema#",
606 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
608 "additionalProperties": False
610 k8scluster_new_schema
= {
611 "title": "k8scluster creation input schema",
612 "$schema": "http://json-schema.org/draft-04/schema#",
615 "schema_version": schema_version
,
616 "schema_type": schema_type
,
618 "description": description_schema
,
619 "credentials": object_schema
,
620 "vim_account": id_schema
,
622 "k8s_version": string_schema
,
623 "nets": k8scluster_nets_schema
,
624 "namespace": name_schema
,
625 "cni": nameshort_list_schema
,
627 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
628 "additionalProperties": False
630 k8scluster_edit_schema
= {
631 "title": "vim_account edit input schema",
632 "$schema": "http://json-schema.org/draft-04/schema#",
636 "description": description_schema
,
637 "credentials": object_schema
,
638 "vim_account": id_schema
,
640 "k8s_version": string_schema
,
641 "nets": k8scluster_nets_schema
,
642 "namespace": name_schema
,
643 "cni": nameshort_list_schema
,
645 "additionalProperties": False
650 "title": "vca creation input schema",
651 "$schema": "http://json-schema.org/draft-04/schema#",
654 "schema_version": schema_version
,
655 "schema_type": schema_type
,
657 "description": description_schema
,
658 "endpoints": description_list_schema
,
659 "user": shortname_schema
,
660 "secret": passwd_schema
,
661 "cacert": long_description_schema
,
662 "lxd-cloud": shortname_schema
,
663 "lxd-credentials": shortname_schema
,
664 "k8s-cloud": shortname_schema
,
665 "k8s-credentials": shortname_schema
,
666 "model-config": object_schema
,
679 "additionalProperties": False,
682 "title": "vca creation input schema",
683 "$schema": "http://json-schema.org/draft-04/schema#",
687 "description": description_schema
,
688 "endpoints": description_list_schema
,
689 "port": integer1_schema
,
690 "user": shortname_schema
,
691 "secret": passwd_schema
,
692 "cacert": long_description_schema
,
693 "lxd-cloud": shortname_schema
,
694 "lxd-credentials": shortname_schema
,
695 "k8s-cloud": shortname_schema
,
696 "k8s-credentials": shortname_schema
,
697 "model-config": object_schema
,
699 "additionalProperties": False,
703 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
704 k8srepo_properties
= {
706 "description": description_schema
,
707 "type": k8srepo_types
,
708 "url": description_schema
,
710 k8srepo_new_schema
= {
711 "title": "k8scluster creation input schema",
712 "$schema": "http://json-schema.org/draft-04/schema#",
714 "properties": k8srepo_properties
,
715 "required": ["name", "type", "url"],
716 "additionalProperties": False
718 k8srepo_edit_schema
= {
719 "title": "vim_account edit input schema",
720 "$schema": "http://json-schema.org/draft-04/schema#",
722 "properties": k8srepo_properties
,
723 "additionalProperties": False
727 osmrepo_types
= {"enum": ["osm"]}
728 osmrepo_properties
= {
730 "description": description_schema
,
731 "type": osmrepo_types
,
732 "url": description_schema
733 # "user": shortname_schema,
734 # "password": passwd_schema
736 osmrepo_new_schema
= {
737 "title": "osm repo creation input schema",
738 "$schema": "http://json-schema.org/draft-04/schema#",
740 "properties": osmrepo_properties
,
741 "required": ["name", "type", "url"],
742 "additionalProperties": False
744 osmrepo_edit_schema
= {
745 "title": "osm repo edit input schema",
746 "$schema": "http://json-schema.org/draft-04/schema#",
748 "properties": osmrepo_properties
,
749 "additionalProperties": False
756 "name": shortname_schema
,
758 "type": {"enum": ["overlay", 'underlay']},
759 "ip-address": ip_schema
,
760 # TODO, add user, password, ssh-key
761 "mac-address": mac_schema
,
762 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
763 "vim-network-id": shortname_schema
,
764 # # provide this in case SDN assist must deal with this interface
765 # "switch-dpid": dpid_Schema,
766 # "switch-port": shortname_schema,
767 # "switch-mac": shortname_schema,
768 # "switch-vlan": vlan_schema,
770 "required": ["name", "mgmt", "ip-address"],
771 "additionalProperties": False
774 "title": "pdu creation input schema",
775 "$schema": "http://json-schema.org/draft-04/schema#",
778 "name": shortname_schema
,
779 "type": shortname_schema
,
780 "description": description_schema
,
781 "shared": bool_schema
,
782 "vims": nameshort_list_schema
,
783 "vim_accounts": nameshort_list_schema
,
786 "items": pdu_interface
,
790 "required": ["name", "type", "interfaces"],
791 "additionalProperties": False
794 "title": "pdu edit input schema",
795 "$schema": "http://json-schema.org/draft-04/schema#",
798 "name": shortname_schema
,
799 "type": shortname_schema
,
800 "description": description_schema
,
801 "shared": bool_schema
,
802 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
803 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
804 "interfaces": {"oneOf": [
805 array_edition_schema
,
808 "items": pdu_interface
,
813 "additionalProperties": False,
818 vnfpkgop_new_schema
= {
819 "title": "VNF PKG operation creation input schema",
820 "$schema": "http://json-schema.org/draft-04/schema#",
823 "lcmOperationType": string_schema
,
824 "vnfPkgId": id_schema
,
825 "kdu_name": name_schema
,
826 "primitive": name_schema
,
827 "primitive_params": {"type": "object"},
829 "required": ["lcmOperationType", "vnfPkgId", "kdu_name", "primitive", "primitive_params"],
830 "additionalProperties": False
834 project_role_mappings
= {
835 "title": "list pf projects/roles",
836 "$schema": "http://json-schema.org/draft-04/schema#",
841 "project": shortname_schema
,
842 "role": shortname_schema
844 "required": ["project", "role"],
845 "additionalProperties": False
849 project_role_mappings_optional
= {
850 "title": "list of projects/roles or projects only",
851 "$schema": "http://json-schema.org/draft-04/schema#",
856 "project": shortname_schema
,
857 "role": shortname_schema
859 "required": ["project"],
860 "additionalProperties": False
865 "$schema": "http://json-schema.org/draft-04/schema#",
866 "title": "New user schema",
869 "username": shortname_schema
,
870 "domain_name": shortname_schema
,
871 "password": passwd_schema
,
872 "projects": nameshort_list_schema
,
873 "project_role_mappings": project_role_mappings
,
875 "required": ["username", "password"],
876 "additionalProperties": False
879 "$schema": "http://json-schema.org/draft-04/schema#",
880 "title": "User edit schema for administrators",
883 "password": passwd_schema
,
884 "username": shortname_schema
, # To allow User Name modification
887 nameshort_list_schema
,
891 "project_role_mappings": project_role_mappings
,
892 "add_project_role_mappings": project_role_mappings
,
893 "remove_project_role_mappings": project_role_mappings_optional
,
896 "additionalProperties": False
900 topics_with_quota
= ["vnfds", "nsds", "slice_templates", "pduds", "ns_instances", "slice_instances", "vim_accounts",
901 "wim_accounts", "sdn_controllers", "k8sclusters", "vca", "k8srepos", "osmrepos", "ns_subscriptions"]
902 project_new_schema
= {
903 "$schema": "http://json-schema.org/draft-04/schema#",
904 "title": "New project schema for administrators",
907 "name": shortname_schema
,
908 "admin": bool_schema
,
909 "domain_name": shortname_schema
,
912 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
913 "additionalProperties": False
916 "required": ["name"],
917 "additionalProperties": False
919 project_edit_schema
= {
920 "$schema": "http://json-schema.org/draft-04/schema#",
921 "title": "Project edit schema for administrators",
924 "admin": bool_schema
,
925 "name": shortname_schema
, # To allow Project Name modification
928 "properties": {topic
: {"oneOf": [integer0_schema
, null_schema
]} for topic
in topics_with_quota
},
929 "additionalProperties": False
932 "additionalProperties": False,
938 "$schema": "http://json-schema.org/draft-04/schema#",
939 "title": "New role schema for administrators",
942 "name": shortname_schema
,
945 "patternProperties": {
948 # "minProperties": 1,
951 "required": ["name"],
952 "additionalProperties": False
954 roles_edit_schema
= {
955 "$schema": "http://json-schema.org/draft-04/schema#",
956 "title": "Roles edit schema for administrators",
959 "name": shortname_schema
,
962 "patternProperties": {
964 "oneOf": [bool_schema
, null_schema
]
967 # "minProperties": 1,
970 "additionalProperties": False,
976 nbi_new_input_schemas
= {
977 "users": user_new_schema
,
978 "projects": project_new_schema
,
979 "vim_accounts": vim_account_new_schema
,
980 "sdns": sdn_new_schema
,
981 "ns_instantiate": ns_instantiate
,
982 "ns_action": ns_action
,
983 "ns_scale": ns_scale
,
984 "pdus": pdu_new_schema
,
987 nbi_edit_input_schemas
= {
988 "users": user_edit_schema
,
989 "projects": project_edit_schema
,
990 "vim_accounts": vim_account_edit_schema
,
991 "sdns": sdn_edit_schema
,
992 "pdus": pdu_edit_schema
,
996 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
997 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
998 nsi_subnet_instantiate
["properties"]["id"] = name_schema
999 del nsi_subnet_instantiate
["required"]
1001 nsi_vld_instantiate
= {
1002 "title": "netslice vld instantiation params input schema",
1003 "$schema": "http://json-schema.org/draft-04/schema#",
1006 "name": string_schema
,
1007 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
1008 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
1009 "ip-profile": object_schema
,
1011 "required": ["name"],
1012 "additionalProperties": False
1016 "title": "netslice action instantiate input schema",
1017 "$schema": "http://json-schema.org/draft-04/schema#",
1020 "lcmOperationType": string_schema
,
1021 "netsliceInstanceId": id_schema
,
1022 "nsiName": name_schema
,
1023 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
1024 "nstId": string_schema
,
1025 "vimAccountId": id_schema
,
1026 "timeout_nsi_deploy": integer1_schema
,
1027 "ssh_keys": {"type": "array", "items": {"type": "string"}},
1028 "nsi_id": id_schema
,
1029 "additionalParamsForNsi": object_schema
,
1030 "netslice-subnet": {
1033 "items": nsi_subnet_instantiate
1038 "items": nsi_vld_instantiate
1041 "required": ["nsiName", "nstId", "vimAccountId"],
1042 "additionalProperties": False
1053 nsinstancesubscriptionfilter_schema
= {
1054 "title": "instance identifier schema",
1055 "$schema": "http://json-schema.org/draft-07/schema#",
1058 "nsdIds": {"type": "array"},
1059 "vnfdIds": {"type": "array"},
1060 "pnfdIds": {"type": "array"},
1061 "nsInstanceIds": {"type": "array"},
1062 "nsInstanceNames": {"type": "array"},
1067 "title": "nslcmsubscription input schema",
1068 "$schema": "http://json-schema.org/draft-07/schema#",
1071 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1072 "notificationTypes": {
1075 "enum": ['NsLcmOperationOccurrenceNotification', 'NsChangeNotification',
1076 'NsIdentifierCreationNotification', 'NsIdentifierDeletionNotification']
1082 "enum": ['INSTANTIATE', 'SCALE', 'TERMINATE', 'UPDATE', 'HEAL']
1085 "operationStates": {
1088 "enum": ['PROCESSING', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED',
1089 'FAILED_TEMP', 'ROLLING_BACK', 'ROLLED_BACK']
1092 "nsComponentTypes": {
1095 "enum": ['VNF', 'NS', 'PNF']
1098 "lcmOpNameImpactingNsComponent": {
1101 "enum": ['VNF_INSTANTIATE', 'VNF_SCALE', 'VNF_SCALE_TO_LEVEL', 'VNF_CHANGE_FLAVOUR',
1102 'VNF_TERMINATE', 'VNF_HEAL', 'VNF_OPERATE', 'VNF_CHANGE_EXT_CONN', 'VNF_MODIFY_INFO',
1103 'NS_INSTANTIATE', 'NS_SCALE', 'NS_UPDATE', 'NS_TERMINATE', 'NS_HEAL']
1106 "lcmOpOccStatusImpactingNsComponent": {
1109 "enum": ['START', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED', 'ROLLED_BACK']
1117 "notificationTypes": {
1118 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1124 {"required": ["operationTypes"]},
1125 {"required": ["operationStates"]},
1132 "notificationTypes": {
1133 "contains": {"const": "NsChangeNotification"}
1139 {"required": ["nsComponentTypes"]},
1140 {"required": ["lcmOpNameImpactingNsComponent"]},
1141 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1148 authentication_schema
= {
1149 "title": "authentication schema for subscription",
1150 "$schema": "http://json-schema.org/draft-07/schema#",
1153 "authType": {"enum": ["basic"]},
1157 "userName": shortname_schema
,
1158 "password": passwd_schema
,
1165 "title": "subscription input schema",
1166 "$schema": "http://json-schema.org/draft-07/schema#",
1169 "filter": nslcmsub_schema
,
1170 "CallbackUri": description_schema
,
1171 "authentication": authentication_schema
1173 "required": ["CallbackUri"],
1177 class ValidationError(Exception):
1178 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1179 self
.http_code
= http_code
1180 Exception.__init
__(self
, message
)
1183 def validate_input(indata
, schema_to_use
):
1185 Validates input data against json schema
1186 :param indata: user input data. Should be a dictionary
1187 :param schema_to_use: jsonschema to test
1188 :return: None if ok, raises ValidationError exception on error
1192 js_v(indata
, schema_to_use
)
1194 except js_e
.ValidationError
as e
:
1196 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1199 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1200 except js_e
.SchemaError
:
1201 raise ValidationError("Bad json schema {}".format(schema_to_use
), http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
)
1204 def is_valid_uuid(x
):
1206 Test for a valid UUID
1207 :param x: string to test
1208 :return: True if x is a valid uuid, False otherwise
1213 except (TypeError, ValueError, AttributeError):