1 # -*- coding: utf-8 -*-
4 # Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
5 # This file is part of openvim
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
24 ''' Definition of dictionaries schemas used by validating input
25 These dictionaries are validated using jsonschema library
27 __author__
="Alfonso Tierno"
28 __date__
="$10-jul-2014 12:07:15$"
31 # SCHEMAS to validate input data
34 path_schema
= {"type": "string", "maxLength": 255, "pattern": "^(\.){0,2}(/[^/\"':{}\(\)]+)+$"}
35 http_schema
= {"type": "string", "pattern": "^https?://[^'\"=]+$"}
36 port_schema
= {"type": "integer","minimum": 1, "maximun": 65534}
37 ip_schema
= {"type": "string", "pattern": "^([0-9]{1,3}.){3}[0-9]{1,3}$"}
38 cidr_schema
= {"type": "string", "pattern": "^([0-9]{1,3}.){3}[0-9]{1,3}/[0-9]{1,2}$"}
39 name_schema
= {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
40 nameshort_schema
= {"type": "string", "minLength": 1, "maxLength": 64, "pattern": "^[^,;()'\"]+$"}
41 nametiny_schema
= {"type": "string", "minLength": 1, "maxLength": 12, "pattern": "^[^,;()'\"]+$"}
42 xml_text_schema
= {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
43 description_schema
= {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
44 id_schema_fake
= {"type": "string", "minLength": 2, "maxLength": 36}
45 # "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}$"
46 id_schema
= {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
47 pci_schema
= {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\.[0-9a-fA-F]$"}
48 # used by VIO neutron-port-show <host_moid>-<domain>:<bus>:<device>.<function>-<VF-id>
49 pci_extended_schema
= {"type": "string", "pattern": "^([0-9a-fA-F]{4}-)?[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}"
50 "\.[0-9a-fA-F](-[0-9a-fA-F]{3})?$"}
51 bandwidth_schema
= {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
52 integer0_schema
= {"type": "integer", "minimum": 0}
53 integer1_schema
= {"type": "integer", "minimum": 1}
54 vlan_schema
= {"type": "integer", "minimum": 1, "maximun": 4095}
55 vlan1000_schema
= {"type": "integer", "minimum": 1000, "maximun": 4095}
56 mac_schema
= {"type": "string", "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"}
57 # must be unicast LSB bit of MSB byte ==0
58 net_bind_schema
= {"oneOf": [
60 {"type": "string", "pattern":
61 "^(default|((bridge|macvtap):[0-9a-zA-Z\.\-]{1,50})|openflow:[/0-9a-zA-Z\.\-]{1,50}(:vlan)?)$"}
63 yes_no_schema
= {"type": "string", "enum": ["yes", "no"]}
64 log_level_schema
= {"type": "string", "enum":["DEBUG", "INFO", "WARNING","ERROR","CRITICAL"]}
67 "title": "main configuration information schema",
68 "$schema": "http://json-schema.org/draft-04/schema#",
71 "http_port": port_schema
,
72 "http_admin_port": port_schema
,
73 "http_host": nameshort_schema
,
74 "http_url_prefix": path_schema
, # it does not work yet; it's supposed to be the base path to be used by bottle, but it must be explicitly declared
75 "db_host": nameshort_schema
,
76 "db_user": nameshort_schema
,
77 "db_passwd": {"type": "string"},
78 "db_name": nameshort_schema
,
79 "of_controller_ip": ip_schema
,
80 "of_controller_port": port_schema
,
81 "of_controller_dpid": nameshort_schema
,
82 "of_controller_nets_with_same_vlan": {"type" : "boolean"},
83 "of_controller": nameshort_schema
, #{"type":"string", "enum":["floodlight", "opendaylight"]},
84 "of_controller_module": {"type":"string"},
85 "of_user": nameshort_schema
,
86 "of_password": nameshort_schema
,
87 "test_mode": {"type": "boolean"}, # leave for backward compatibility
88 "mode": {"type":"string", "enum":["normal", "host only", "OF only", "development", "test"] },
89 "development_bridge": {"type":"string"},
90 "tenant_id": {"type" : "string"},
91 "image_path": path_schema
, # leave for backward compatibility
92 "host_image_path": path_schema
,
93 "host_ssh_keyfile": path_schema
,
94 "network_vlan_range_start": vlan_schema
,
95 "network_vlan_range_end": vlan_schema
,
98 "patternProperties": {
101 "items": integer0_schema
,
113 "provider": {"type": "string", "enum": ["isc-dhcp-server"]},
114 "user": nameshort_schema
,
115 "password": {"type": "string"},
116 "key": path_schema
, # for backward compatibility, use keyfile instead
117 "keyfile": path_schema
,
120 "items": nameshort_schema
,
124 "items": name_schema
,
127 "required": ['host', 'provider', 'user']
129 "log_level": log_level_schema
,
130 "log_level_db": log_level_schema
,
131 "log_level_of": log_level_schema
,
132 "network_type": {"type": "string", "enum": ["ovs", "bridge"]},
133 "ovs_controller_file_path": path_schema
,
134 "ovs_controller_ip": nameshort_schema
,
135 "ovs_controller_user": nameshort_schema
,
136 "ovs_controller_password": {"type": "string"},
137 "ovs_controller_keyfile": path_schema
,
139 "patternProperties": {
140 "of_*" : {"type": ["string", "integer", "boolean"]}
142 "required": ['db_host', 'db_user', 'db_passwd', 'db_name'],
143 "additionalProperties": False
151 "architecture": {"type":"string"},
152 "use_incremental": yes_no_schema
,
154 "os_distro": {"type":"string"},
155 "os_type": {"type":"string"},
156 "os_version": {"type":"string"},
157 "bus": {"type":"string"},
158 "topology": {"type":"string", "enum": ["oneSocket", "oneSocket:hyperthreading"]}
162 tenant_new_schema
= {
163 "title":"tenant creation information schema",
164 "$schema": "http://json-schema.org/draft-04/schema#",
171 "name": nameshort_schema
,
172 "description":description_schema
,
173 "enabled":{"type" : "boolean"}
178 "required": ["tenant"],
179 "additionalProperties": False
182 tenant_edit_schema
= {
183 "title":"tenant edition information schema",
184 "$schema": "http://json-schema.org/draft-04/schema#",
191 "name":nameshort_schema
,
192 "description":description_schema
,
193 "enabled":{"type" : "boolean"}
195 "additionalProperties": False,
198 "required": ["tenant"],
199 "additionalProperties": False
208 "dedicated":{"type":"string","enum":["yes","no","yes:sriov"]},
209 "bandwidth":bandwidth_schema
,
212 "mac_address":mac_schema
214 "additionalProperties": False,
215 "required": ["dedicated", "bandwidth"]
222 "processor_ranking":integer0_schema
,
228 "type":{"type":"string", "enum":["usb","disk","cdrom","xml"]},
230 "imageRef":id_schema
,
231 "xml":xml_text_schema
,
232 "dev":nameshort_schema
,
233 "size":integer1_schema
,
235 "additionalProperties": False,
244 "memory":integer1_schema
,
245 "cores":integer1_schema
,
246 "paired-threads":integer1_schema
,
247 "threads":integer1_schema
,
248 "cores-id":{"type":"array","items":integer0_schema
},
249 "paired-threads-id":{"type":"array","items":{"type":"array","minItems":2,"maxItems":2,"items":integer0_schema
}},
250 "threads-id":{"type":"array","items":integer0_schema
},
251 "interfaces":interfaces_schema
253 "additionalProperties": False,
255 #"required": ["memory"]
259 #"additionalProperties": False,
260 #"required": ["processor_ranking"]
264 "title":"hosts manual insertion information schema",
268 "admin_state_up": {"type": "boolean"},
269 "created_at": {"type": "string"}, # ignored, just for compatibility with host-list
270 "ip_name": nameshort_schema
,
272 "description": description_schema
,
273 "user": nameshort_schema
,
274 "password": nameshort_schema
,
275 "keyfile": path_schema
,
276 "features": description_schema
,
277 "ranking": integer0_schema
,
278 "autodiscover": {"type": "boolean"}, # try to discover host parameters instead of providing in this schema
279 "hypervisors": description_schema
, #Unikernels extension
285 "type": {"type": "string", "enum": ["usb", "disk"]},
288 "additionalProperties": False,
298 "admin_state_up": {"type": "boolean"},
299 "hugepages": integer0_schema
,
300 "hugepages_consumed": integer0_schema
, # ignored, just for compatibility with host-list
301 "numa_socket": integer0_schema
,
302 "memory": integer1_schema
,
309 "core_id": integer0_schema
,
310 "thread_id": integer0_schema
,
311 "status": {"type": "string", "enum": ["noteligible"]},
312 "instance_id": {"type": "string"}, # ignored, just for compatibility with host-list
313 "v_thread_id": {"type": "integer"} # ignored, just for compatibility with host-list
315 "additionalProperties": False,
316 "required": ["core_id", "thread_id"]
325 "source_name": nameshort_schema
,
327 "Mbps": integer0_schema
,
335 "source_name": {"oneOf": [integer0_schema
, nameshort_schema
]},
337 "vlan": integer0_schema
, # ignored, just for backward compatibility
340 "additionalProperties": False,
341 "required": ["source_name", "mac", "pci"]
344 "switch_port": nameshort_schema
,
345 "switch_dpid": nameshort_schema
,
346 "switch_mac": mac_schema
,
348 "additionalProperties": False,
349 "required": ["source_name", "mac", "Mbps", "pci"]
353 "additionalProperties": False,
354 "required": ["cores", "numa_socket"]
358 "additionalProperties": False,
359 "required": ["name", "user", "ip_name"]
363 "title":"hosts creation information schema",
364 "$schema": "http://json-schema.org/draft-04/schema#",
370 "ip_name":nameshort_schema
,
372 "description":description_schema
,
373 "user":nameshort_schema
,
374 "password":nameshort_schema
,
375 "admin_state_up":{"type":"boolean"},
381 "numa_socket": integer0_schema
,
382 "admin_state_up":{"type":"boolean"},
388 "source_name": nameshort_schema
,
389 "switch_dpid": nameshort_schema
,
390 "switch_port": nameshort_schema
,
392 "required": ["source_name"],
396 "required": ["numa_socket"],
397 "additionalProperties": False,
402 "additionalProperties": False
405 "required": ["host"],
407 "additionalProperties": False
411 "title":"hosts creation information schema",
412 "$schema": "http://json-schema.org/draft-04/schema#",
415 "host": host_data_schema
,
416 "host-data":host_data_schema
418 "required": ["host"],
421 "additionalProperties": False
425 flavor_new_schema
= {
426 "title":"flavor creation information schema",
427 "$schema": "http://json-schema.org/draft-04/schema#",
435 "description":description_schema
,
436 "ram":integer0_schema
,
437 "vcpus":integer0_schema
,
438 "extended": extended_schema
,
439 "public": yes_no_schema
444 "required": ["flavor"],
445 "additionalProperties": False
447 flavor_update_schema
= {
448 "title":"flavor update information schema",
449 "$schema": "http://json-schema.org/draft-04/schema#",
456 "description":description_schema
,
457 "ram":integer0_schema
,
458 "vcpus":integer0_schema
,
459 "extended": extended_schema
,
460 "public": yes_no_schema
463 "additionalProperties": False
466 "required": ["flavor"],
467 "additionalProperties": False
471 "title":"image creation information schema",
472 "$schema": "http://json-schema.org/draft-04/schema#",
479 "path": {"oneOf": [path_schema
, http_schema
]},
480 "description":description_schema
,
482 "metadata":metadata_schema
,
483 "public": yes_no_schema
485 "required": ["name","path"]
488 "required": ["image"],
489 "additionalProperties": False
492 image_update_schema
= {
493 "title":"image update information schema",
494 "$schema": "http://json-schema.org/draft-04/schema#",
500 "path":{"oneOf": [path_schema
, http_schema
]},
501 "description":description_schema
,
503 "metadata":metadata_schema
,
504 "public": yes_no_schema
507 "additionalProperties": False
510 "required": ["image"],
511 "additionalProperties": False
520 "bandwidth":bandwidth_schema
,
523 "mac_address": mac_schema
,
524 "ip_address": ip_schema
,
525 "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]},
526 "type": {"type":"string", "enum":["virtual","PF","VF","VFnotShared"]}
528 "additionalProperties": False,
533 server_new_schema
= {
534 "title":"server creation information schema",
535 "$schema": "http://json-schema.org/draft-04/schema#",
543 "description":description_schema
,
544 "start":{"type":"string", "enum":["yes","no","paused"]},
546 "flavorRef":id_schema
,
547 "imageRef":id_schema
,
548 "hypervisor":{"type":"string", "enum":["kvm","xen-unik","xenhvm"]}, #Unikernels extension
549 "osImageType":{"type":"string", "enum":["clickos","other"]}, #Unikernels extension
550 "extended": extended_schema
,
551 "networks":networks_schema
553 "required": ["name","flavorRef","imageRef"]
556 "required": ["server"],
557 "additionalProperties": False
560 server_action_schema
= {
561 "title":"server action information schema",
562 "$schema": "http://json-schema.org/draft-04/schema#",
565 "start":{"oneOf":[{"type": "null"}, {"type":"string", "enum":["rebuild","null"] }]},
566 "pause":{"type": "null"},
567 "resume":{"type": "null"},
568 "shutoff":{"type": "null"},
569 "shutdown":{"type": "null"},
570 "forceOff":{"type": "null"},
571 "terminate":{"type": "null"},
576 "description":description_schema
,
578 "metadata":metadata_schema
,
579 "imageRef": id_schema
,
580 "disk": {"oneOf":[{"type": "null"}, {"type":"string"}] },
584 "rebuild":{"type": ["object","null"]},
586 "type": ["object","null"],
588 # "type":{"type":"string", "enum":["SOFT"] }
590 # "minProperties": 1,
591 # "maxProperties": 1,
592 # "additionalProperties": False
597 "additionalProperties": False
600 network_new_schema
= {
601 "title": "network creation information schema",
602 "$schema": "http://json-schema.org/draft-04/schema#",
610 "type": {"type":"string", "enum": ["bridge_man", "bridge_data", "data", "ptp"]},
611 "shared": {"type": "boolean"},
612 "tenant_id": id_schema
,
613 "admin_state_up": {"type": "boolean"},
614 "provider:vlan": vlan_schema
,
615 "provider:physical": net_bind_schema
,
616 "region": nameshort_schema
,
618 "enable_dhcp": {"type": "boolean"},
619 "dhcp_first_ip": ip_schema
,
620 "dhcp_last_ip": ip_schema
,
621 "dns": {"type": "array", "items": [ip_schema
]},
622 "links": {"type": "array", "items": {"type": "object", "properties": {
624 "iface": name_schema
,
625 "vlan": vlan_schema
},
626 "required": ["iface"],
627 "additionalProperties": False
631 "routes": {"type": "object", "properties": {"default": ip_schema
}, "patternProperties": {
632 "^([0-9]{1,3}.){3}[0-9]{1,3}/[0-9]{1,2}$": ip_schema
,
634 "additionalProperties": False
637 "bind_net": name_schema
, # can be name, or uuid
638 "bind_type": {"oneOf": [{"type": "null"}, {"type": "string", "pattern": "^vlan:[0-9]{1,4}$"}]}
643 "required": ["network"],
644 "additionalProperties": False
647 network_update_schema
= {
648 "title":"network update information schema",
649 "$schema": "http://json-schema.org/draft-04/schema#",
656 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
657 "shared":{"type":"boolean"},
658 "tenant_id":id_schema
,
659 "admin_state_up":{"type":"boolean"},
660 "provider:vlan":vlan_schema
,
661 "provider:physical":net_bind_schema
,
663 "enable_dhcp": {"type":"boolean"},
664 # "dhcp_first_ip": ip_schema,
665 # "dhcp_last_ip": ip_schema,
666 "bind_net":name_schema
, #can be name, or uuid
667 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
670 "additionalProperties": False
673 "required": ["network"],
674 "additionalProperties": False
679 "title":"port creation information schema",
680 "$schema": "http://json-schema.org/draft-04/schema#",
687 "name":nameshort_schema
,
688 "network_id":{"oneOf":[{"type": "null"}, id_schema
]},
689 "tenant_id":id_schema
,
690 "mac_address": {"oneOf":[{"type": "null"}, mac_schema
] },
691 "admin_state_up":{"type":"boolean"},
692 "bandwidth":bandwidth_schema
,
693 "binding:switch_port":nameshort_schema
,
694 "binding:vlan": {"oneOf":[{"type": "null"}, vlan_schema
]}
699 "required": ["port"],
700 "additionalProperties": False
703 port_update_schema
= {
704 "title":"port update information schema",
705 "$schema": "http://json-schema.org/draft-04/schema#",
711 "name":nameshort_schema
,
712 "network_id":{"anyOf":[{"type":"null"}, id_schema
] }
715 "additionalProperties": False
718 "required": ["port"],
719 "additionalProperties": False
723 "title":"localinfo information schema",
724 "$schema": "http://json-schema.org/draft-04/schema#",
727 "files":{ "type": "object"},
728 "inc_files":{ "type": "object"},
729 "server_files":{ "type": "object"}
731 "required": ["files"]
735 "title":"host information schema",
736 "$schema": "http://json-schema.org/draft-04/schema#",
741 "patternProperties":{
742 ".":{ "type": "string"}
747 "required": ["iface_names"]
750 openflow_controller_schema
= {
751 "title": "network creation information schema",
752 "$schema": "http://json-schema.org/draft-04/schema#",
759 "dpid": nameshort_schema
,
760 "ip": nameshort_schema
,
762 "type": nameshort_schema
,
763 "version": nametiny_schema
,
764 "user": nameshort_schema
,
765 "password": nameshort_schema
767 "required": ["dpid", "type", "ip", "port", "name"]
771 "additionalProperties": False
774 of_port_new_schema
= {
775 "title": "OF port mapping",
779 "region": nameshort_schema
,
780 "compute_node": nameshort_schema
,
781 "pci": pci_extended_schema
,
782 "switch_dpid": nameshort_schema
,
783 "switch_port": nameshort_schema
,
784 "switch_mac": mac_schema
786 "required": ["region", "compute_node", "pci", "switch_dpid"]
789 of_port_map_new_schema
= {
790 "title": "OF port mapping",
791 "$schema": "http://json-schema.org/draft-04/schema#",
794 "of_port_mapings": {"type": "array", "items": of_port_new_schema
, "minLenght":1},
796 "required": ["of_port_mapings"],
797 "additionalProperties": False