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?|http)://[^'\"=]+$"}
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 "config-units": integer1_schema
, # number of configuration units of this vnf, by default 1
240 "additionalParamsForVdu": {
245 "vdu_id": name_schema
,
246 "additionalParams": object_schema
,
247 "config-units": integer1_schema
, # number of configuration units of this vdu, by default 1
249 "required": ["vdu_id"],
251 "additionalProperties": False,
254 "additionalParamsForKdu": {
259 "kdu_name": name_schema
,
260 "additionalParams": object_schema
,
261 "kdu_model": name_schema
,
262 "k8s-namespace": name_schema
,
263 "config-units": integer1_schema
, # number of configuration units of this knf, by default 1
264 "kdu-deployment-name": name_schema
,
266 "required": ["kdu_name"],
268 "additionalProperties": False,
272 "required": ["member-vnf-index"],
274 "additionalProperties": False
279 "title": "ns action instantiate input schema",
280 "$schema": "http://json-schema.org/draft-04/schema#",
283 "lcmOperationType": string_schema
,
284 "nsInstanceId": id_schema
,
285 "netsliceInstanceId": id_schema
,
286 "nsName": name_schema
,
287 "nsDescription": {"oneOf": [description_schema
, null_schema
]},
289 "vimAccountId": id_schema
,
290 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
291 "placement-engine": string_schema
,
292 "placement-constraints": object_schema
,
293 "additionalParamsForNs": object_schema
,
294 "additionalParamsForVnf": additional_params_for_vnf
,
295 "config-units": integer1_schema
, # number of configuration units of this ns, by default 1
296 "k8s-namespace": name_schema
,
297 "ssh_keys": {"type": "array", "items": {"type": "string"}},
298 "timeout_ns_deploy": integer1_schema
,
300 "vduImage": name_schema
,
307 "member-vnf-index": name_schema
,
308 "vimAccountId": id_schema
,
312 "items": ns_instantiate_vdu
,
317 "items": ns_instantiate_internal_vld
320 "required": ["member-vnf-index"],
322 "additionalProperties": False
331 "name": string_schema
,
332 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
333 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
334 "ns-net": object_schema
,
335 "wimAccountId": {"oneOf": [id_schema
, bool_schema
, null_schema
]},
336 "ip-profile": object_schema
,
337 "provider-network": provider_network_schema
,
338 "vnfd-connection-point-ref": {
344 "member-vnf-index-ref": name_schema
,
345 "vnfd-connection-point-ref": name_schema
,
346 "ip-address": ip_schema
,
347 # "mac-address": mac_schema,
349 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
351 "additionalProperties": False
355 "required": ["name"],
356 "additionalProperties": False
360 "required": ["nsName", "nsdId", "vimAccountId"],
361 "additionalProperties": False
365 "title": "ns terminate input schema",
366 "$schema": "http://json-schema.org/draft-04/schema#",
369 "lcmOperationType": string_schema
,
370 "nsInstanceId": id_schema
,
371 "autoremove": bool_schema
,
372 "timeout_ns_terminate": integer1_schema
,
373 "skip_terminate_primitives": bool_schema
,
374 "netsliceInstanceId": id_schema
,
376 "additionalProperties": False
379 ns_action
= { # TODO for the moment it is only contemplated the vnfd primitive execution
380 "title": "ns action input schema",
381 "$schema": "http://json-schema.org/draft-04/schema#",
384 "lcmOperationType": string_schema
,
385 "nsInstanceId": id_schema
,
386 "member_vnf_index": name_schema
,
387 "vnf_member_index": name_schema
, # TODO for backward compatibility. To remove in future
388 "vdu_id": name_schema
,
389 "vdu_count_index": integer0_schema
,
390 "kdu_name": name_schema
,
391 "primitive": name_schema
,
392 "timeout_ns_action": integer1_schema
,
393 "primitive_params": {"type": "object"},
395 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
396 "additionalProperties": False
398 ns_scale
= { # TODO for the moment it is only VDU-scaling
399 "title": "ns scale input schema",
400 "$schema": "http://json-schema.org/draft-04/schema#",
403 "lcmOperationType": string_schema
,
404 "nsInstanceId": id_schema
,
405 "scaleType": {"enum": ["SCALE_VNF"]},
406 "timeout_ns_scale": integer1_schema
,
410 "vnfInstanceId": name_schema
,
411 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
415 "scaling-group-descriptor": name_schema
,
416 "member-vnf-index": name_schema
,
417 "scaling-policy": name_schema
,
419 "required": ["scaling-group-descriptor", "member-vnf-index"],
420 "additionalProperties": False
423 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
424 "additionalProperties": False
426 "scaleTime": time_schema
,
428 "required": ["scaleType", "scaleVnfData"],
429 "additionalProperties": False
433 schema_version
= {"type": "string", "enum": ["1.0"]}
434 schema_type
= {"type": "string"}
435 vim_type
= shortname_schema
# {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
437 vim_account_edit_schema
= {
438 "title": "vim_account edit input schema",
439 "$schema": "http://json-schema.org/draft-04/schema#",
443 "description": description_schema
,
445 "datacenter": name_schema
,
446 "vim_type": vim_type
,
447 "vim_url": description_schema
,
448 # "vim_url_admin": description_schema,
449 # "vim_tenant": name_schema,
450 "vim_tenant_name": name_schema
,
451 "vim_user": shortname_schema
,
452 "vim_password": passwd_schema
,
453 "config": {"type": "object"}
455 "additionalProperties": False
458 vim_account_new_schema
= {
459 "title": "vim_account creation input schema",
460 "$schema": "http://json-schema.org/draft-04/schema#",
463 "schema_version": schema_version
,
464 "schema_type": schema_type
,
466 "description": description_schema
,
468 "datacenter": name_schema
,
469 "vim_type": vim_type
,
470 "vim_url": description_schema
,
471 # "vim_url_admin": description_schema,
472 # "vim_tenant": name_schema,
473 "vim_tenant_name": name_schema
,
474 "vim_user": shortname_schema
,
475 "vim_password": passwd_schema
,
476 "config": {"type": "object"}
478 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
479 "additionalProperties": False
482 wim_type
= shortname_schema
# {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
484 wim_account_edit_schema
= {
485 "title": "wim_account edit input schema",
486 "$schema": "http://json-schema.org/draft-04/schema#",
490 "description": description_schema
,
492 "wim_type": wim_type
,
493 "wim_url": description_schema
,
494 "user": shortname_schema
,
495 "password": passwd_schema
,
496 "config": {"type": "object"}
498 "additionalProperties": False
501 wim_account_new_schema
= {
502 "title": "wim_account creation input schema",
503 "$schema": "http://json-schema.org/draft-04/schema#",
506 "schema_version": schema_version
,
507 "schema_type": schema_type
,
509 "description": description_schema
,
511 "wim_type": wim_type
,
512 "wim_url": description_schema
,
513 "user": shortname_schema
,
514 "password": passwd_schema
,
517 "patternProperties": {
518 ".": {"not": {"type": "null"}}
522 "required": ["name", "wim_url", "wim_type"],
523 "additionalProperties": False
528 "type": {"type": "string"},
529 "url": {"type": "string"},
530 "user": shortname_schema
,
531 "password": passwd_schema
,
532 "config": {"type": "object"},
533 "description": description_schema
,
534 # The folowing are deprecated. Maintanied for backward compatibility
538 "version": {"type": "string", "minLength": 1, "maxLength": 12},
541 "title": "sdn controller information schema",
542 "$schema": "http://json-schema.org/draft-04/schema#",
544 "properties": sdn_properties
,
545 "required": ["name", 'type'],
546 "additionalProperties": False
549 "title": "sdn controller update information schema",
550 "$schema": "http://json-schema.org/draft-04/schema#",
552 "properties": sdn_properties
,
553 # "required": ["name", "port", 'ip', 'dpid', 'type'],
554 "additionalProperties": False
556 sdn_port_mapping_schema
= {
557 "$schema": "http://json-schema.org/draft-04/schema#",
558 "title": "sdn port mapping information schema",
563 "compute_node": shortname_schema
,
569 "pci": pci_extended_schema
,
570 "switch_port": shortname_schema
,
571 "switch_mac": mac_schema
577 "required": ["compute_node", "ports"]
580 sdn_external_port_schema
= {
581 "$schema": "http://json-schema.org/draft-04/schema#",
582 "title": "External port information",
585 "port": {"type": "string", "minLength": 1, "maxLength": 60},
593 k8scluster_nets_schema
= {
594 "title": "k8scluster nets input schema",
595 "$schema": "http://json-schema.org/draft-04/schema#",
597 "patternProperties": {".": {"oneOf": [name_schema
, null_schema
]}},
599 "additionalProperties": False
601 k8scluster_new_schema
= {
602 "title": "k8scluster creation input schema",
603 "$schema": "http://json-schema.org/draft-04/schema#",
606 "schema_version": schema_version
,
607 "schema_type": schema_type
,
609 "description": description_schema
,
610 "credentials": object_schema
,
611 "vim_account": id_schema
,
612 "k8s_version": string_schema
,
613 "nets": k8scluster_nets_schema
,
614 "namespace": name_schema
,
615 "cni": nameshort_list_schema
,
617 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
618 "additionalProperties": False
620 k8scluster_edit_schema
= {
621 "title": "vim_account edit input schema",
622 "$schema": "http://json-schema.org/draft-04/schema#",
626 "description": description_schema
,
627 "credentials": object_schema
,
628 "vim_account": id_schema
,
629 "k8s_version": string_schema
,
630 "nets": k8scluster_nets_schema
,
631 "namespace": name_schema
,
632 "cni": nameshort_list_schema
,
634 "additionalProperties": False
638 k8srepo_types
= {"enum": ["helm-chart", "juju-bundle"]}
639 k8srepo_properties
= {
641 "description": description_schema
,
642 "type": k8srepo_types
,
643 "url": description_schema
,
645 k8srepo_new_schema
= {
646 "title": "k8scluster creation input schema",
647 "$schema": "http://json-schema.org/draft-04/schema#",
649 "properties": k8srepo_properties
,
650 "required": ["name", "type", "url"],
651 "additionalProperties": False
653 k8srepo_edit_schema
= {
654 "title": "vim_account edit input schema",
655 "$schema": "http://json-schema.org/draft-04/schema#",
657 "properties": k8srepo_properties
,
658 "additionalProperties": False
662 osmrepo_types
= {"enum": ["osm"]}
663 osmrepo_properties
= {
665 "description": description_schema
,
666 "type": osmrepo_types
,
667 "url": description_schema
668 # "user": shortname_schema,
669 # "password": passwd_schema
671 osmrepo_new_schema
= {
672 "title": "osm repo creation input schema",
673 "$schema": "http://json-schema.org/draft-04/schema#",
675 "properties": osmrepo_properties
,
676 "required": ["name", "type", "url"],
677 "additionalProperties": False
679 osmrepo_edit_schema
= {
680 "title": "osm repo edit input schema",
681 "$schema": "http://json-schema.org/draft-04/schema#",
683 "properties": osmrepo_properties
,
684 "additionalProperties": False
691 "name": shortname_schema
,
693 "type": {"enum": ["overlay", 'underlay']},
694 "ip-address": ip_schema
,
695 # TODO, add user, password, ssh-key
696 "mac-address": mac_schema
,
697 "vim-network-name": shortname_schema
, # interface is connected to one vim network, or switch port
698 "vim-network-id": shortname_schema
,
699 # # provide this in case SDN assist must deal with this interface
700 # "switch-dpid": dpid_Schema,
701 # "switch-port": shortname_schema,
702 # "switch-mac": shortname_schema,
703 # "switch-vlan": vlan_schema,
705 "required": ["name", "mgmt", "ip-address"],
706 "additionalProperties": False
709 "title": "pdu creation input schema",
710 "$schema": "http://json-schema.org/draft-04/schema#",
713 "name": shortname_schema
,
714 "type": shortname_schema
,
715 "description": description_schema
,
716 "shared": bool_schema
,
717 "vims": nameshort_list_schema
,
718 "vim_accounts": nameshort_list_schema
,
721 "items": pdu_interface
,
725 "required": ["name", "type", "interfaces"],
726 "additionalProperties": False
729 "title": "pdu edit input schema",
730 "$schema": "http://json-schema.org/draft-04/schema#",
733 "name": shortname_schema
,
734 "type": shortname_schema
,
735 "description": description_schema
,
736 "shared": bool_schema
,
737 "vims": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
738 "vim_accounts": {"oneOf": [array_edition_schema
, nameshort_list_schema
]},
739 "interfaces": {"oneOf": [
740 array_edition_schema
,
743 "items": pdu_interface
,
748 "additionalProperties": False,
753 vnfpkgop_new_schema
= {
754 "title": "VNF PKG operation creation input schema",
755 "$schema": "http://json-schema.org/draft-04/schema#",
758 "lcmOperationType": string_schema
,
759 "vnfPkgId": id_schema
,
760 "kdu_name": name_schema
,
761 "primitive": name_schema
,
762 "primitive_params": {"type": "object"},
764 "required": ["lcmOperationType", "vnfPkgId", "kdu_name", "primitive", "primitive_params"],
765 "additionalProperties": False
769 project_role_mappings
= {
770 "title": "list pf projects/roles",
771 "$schema": "http://json-schema.org/draft-04/schema#",
776 "project": shortname_schema
,
777 "role": shortname_schema
779 "required": ["project", "role"],
780 "additionalProperties": False
784 project_role_mappings_optional
= {
785 "title": "list of projects/roles or projects only",
786 "$schema": "http://json-schema.org/draft-04/schema#",
791 "project": shortname_schema
,
792 "role": shortname_schema
794 "required": ["project"],
795 "additionalProperties": False
800 "$schema": "http://json-schema.org/draft-04/schema#",
801 "title": "New user schema",
804 "username": shortname_schema
,
805 "domain_name": shortname_schema
,
806 "password": passwd_schema
,
807 "projects": nameshort_list_schema
,
808 "project_role_mappings": project_role_mappings
,
810 "required": ["username", "password"],
811 "additionalProperties": False
814 "$schema": "http://json-schema.org/draft-04/schema#",
815 "title": "User edit schema for administrators",
818 "password": passwd_schema
,
819 "username": shortname_schema
, # To allow User Name modification
822 nameshort_list_schema
,
826 "project_role_mappings": project_role_mappings
,
827 "add_project_role_mappings": project_role_mappings
,
828 "remove_project_role_mappings": project_role_mappings_optional
,
831 "additionalProperties": False
835 topics_with_quota
= ["vnfds", "nsds", "slice_templates", "pduds", "ns_instances", "slice_instances", "vim_accounts",
836 "wim_accounts", "sdn_controllers", "k8sclusters", "k8srepos", "osmrepos", "ns_subscriptions"]
837 project_new_schema
= {
838 "$schema": "http://json-schema.org/draft-04/schema#",
839 "title": "New project schema for administrators",
842 "name": shortname_schema
,
843 "admin": bool_schema
,
844 "domain_name": shortname_schema
,
847 "properties": {topic
: integer0_schema
for topic
in topics_with_quota
},
848 "additionalProperties": False
851 "required": ["name"],
852 "additionalProperties": False
854 project_edit_schema
= {
855 "$schema": "http://json-schema.org/draft-04/schema#",
856 "title": "Project edit schema for administrators",
859 "admin": bool_schema
,
860 "name": shortname_schema
, # To allow Project Name modification
863 "properties": {topic
: {"oneOf": [integer0_schema
, null_schema
]} for topic
in topics_with_quota
},
864 "additionalProperties": False
867 "additionalProperties": False,
873 "$schema": "http://json-schema.org/draft-04/schema#",
874 "title": "New role schema for administrators",
877 "name": shortname_schema
,
880 "patternProperties": {
883 # "minProperties": 1,
886 "required": ["name"],
887 "additionalProperties": False
889 roles_edit_schema
= {
890 "$schema": "http://json-schema.org/draft-04/schema#",
891 "title": "Roles edit schema for administrators",
894 "name": shortname_schema
,
897 "patternProperties": {
899 "oneOf": [bool_schema
, null_schema
]
902 # "minProperties": 1,
905 "additionalProperties": False,
911 nbi_new_input_schemas
= {
912 "users": user_new_schema
,
913 "projects": project_new_schema
,
914 "vim_accounts": vim_account_new_schema
,
915 "sdns": sdn_new_schema
,
916 "ns_instantiate": ns_instantiate
,
917 "ns_action": ns_action
,
918 "ns_scale": ns_scale
,
919 "pdus": pdu_new_schema
,
922 nbi_edit_input_schemas
= {
923 "users": user_edit_schema
,
924 "projects": project_edit_schema
,
925 "vim_accounts": vim_account_edit_schema
,
926 "sdns": sdn_edit_schema
,
927 "pdus": pdu_edit_schema
,
931 nsi_subnet_instantiate
= deepcopy(ns_instantiate
)
932 nsi_subnet_instantiate
["title"] = "netslice subnet instantiation params input schema"
933 nsi_subnet_instantiate
["properties"]["id"] = name_schema
934 del nsi_subnet_instantiate
["required"]
936 nsi_vld_instantiate
= {
937 "title": "netslice vld instantiation params input schema",
938 "$schema": "http://json-schema.org/draft-04/schema#",
941 "name": string_schema
,
942 "vim-network-name": {"oneOf": [string_schema
, object_schema
]},
943 "vim-network-id": {"oneOf": [string_schema
, object_schema
]},
944 "ip-profile": object_schema
,
946 "required": ["name"],
947 "additionalProperties": False
951 "title": "netslice action instantiate input schema",
952 "$schema": "http://json-schema.org/draft-04/schema#",
955 "lcmOperationType": string_schema
,
956 "netsliceInstanceId": id_schema
,
957 "nsiName": name_schema
,
958 "nsiDescription": {"oneOf": [description_schema
, null_schema
]},
959 "nstId": string_schema
,
960 "vimAccountId": id_schema
,
961 "timeout_nsi_deploy": integer1_schema
,
962 "ssh_keys": {"type": "array", "items": {"type": "string"}},
964 "additionalParamsForNsi": object_schema
,
968 "items": nsi_subnet_instantiate
973 "items": nsi_vld_instantiate
976 "required": ["nsiName", "nstId", "vimAccountId"],
977 "additionalProperties": False
988 nsinstancesubscriptionfilter_schema
= {
989 "title": "instance identifier schema",
990 "$schema": "http://json-schema.org/draft-07/schema#",
993 "nsdIds": {"type": "array"},
994 "vnfdIds": {"type": "array"},
995 "pnfdIds": {"type": "array"},
996 "nsInstanceIds": {"type": "array"},
997 "nsInstanceNames": {"type": "array"},
1002 "title": "nslcmsubscription input schema",
1003 "$schema": "http://json-schema.org/draft-07/schema#",
1006 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema
,
1007 "notificationTypes": {
1010 "enum": ['NsLcmOperationOccurrenceNotification', 'NsChangeNotification',
1011 'NsIdentifierCreationNotification', 'NsIdentifierDeletionNotification']
1017 "enum": ['INSTANTIATE', 'SCALE', 'TERMINATE', 'UPDATE', 'HEAL']
1020 "operationStates": {
1023 "enum": ['PROCESSING', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED',
1024 'FAILED_TEMP', 'ROLLING_BACK', 'ROLLED_BACK']
1027 "nsComponentTypes": {
1030 "enum": ['VNF', 'NS', 'PNF']
1033 "lcmOpNameImpactingNsComponent": {
1036 "enum": ['VNF_INSTANTIATE', 'VNF_SCALE', 'VNF_SCALE_TO_LEVEL', 'VNF_CHANGE_FLAVOUR',
1037 'VNF_TERMINATE', 'VNF_HEAL', 'VNF_OPERATE', 'VNF_CHANGE_EXT_CONN', 'VNF_MODIFY_INFO',
1038 'NS_INSTANTIATE', 'NS_SCALE', 'NS_UPDATE', 'NS_TERMINATE', 'NS_HEAL']
1041 "lcmOpOccStatusImpactingNsComponent": {
1044 "enum": ['START', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED', 'ROLLED_BACK']
1052 "notificationTypes": {
1053 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1059 {"required": ["operationTypes"]},
1060 {"required": ["operationStates"]},
1067 "notificationTypes": {
1068 "contains": {"const": "NsChangeNotification"}
1074 {"required": ["nsComponentTypes"]},
1075 {"required": ["lcmOpNameImpactingNsComponent"]},
1076 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1083 authentication_schema
= {
1084 "title": "authentication schema for subscription",
1085 "$schema": "http://json-schema.org/draft-07/schema#",
1088 "authType": {"enum": ["basic"]},
1092 "userName": shortname_schema
,
1093 "password": passwd_schema
,
1100 "title": "subscription input schema",
1101 "$schema": "http://json-schema.org/draft-07/schema#",
1104 "filter": nslcmsub_schema
,
1105 "CallbackUri": description_schema
,
1106 "authentication": authentication_schema
1108 "required": ["CallbackUri"],
1112 class ValidationError(Exception):
1113 def __init__(self
, message
, http_code
=HTTPStatus
.UNPROCESSABLE_ENTITY
):
1114 self
.http_code
= http_code
1115 Exception.__init
__(self
, message
)
1118 def validate_input(indata
, schema_to_use
):
1120 Validates input data against json schema
1121 :param indata: user input data. Should be a dictionary
1122 :param schema_to_use: jsonschema to test
1123 :return: None if ok, raises ValidationError exception on error
1127 js_v(indata
, schema_to_use
)
1129 except js_e
.ValidationError
as e
:
1131 error_pos
= "at '" + ":".join(map(str, e
.path
)) + "'"
1134 raise ValidationError("Format error {} '{}' ".format(error_pos
, e
.message
))
1135 except js_e
.SchemaError
:
1136 raise ValidationError("Bad json schema {}".format(schema_to_use
), http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
)
1139 def is_valid_uuid(x
):
1141 Test for a valid UUID
1142 :param x: string to test
1143 :return: True if x is a valid uuid, False otherwise
1148 except (TypeError, ValueError, AttributeError):