1 # -*- coding: utf-8 -*-
4 # Copyright 2015 Telefónica Investigación 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
284 "type": {"type": "string", "enum": ["usb", "disk"]},
287 "additionalProperties": False,
297 "admin_state_up": {"type": "boolean"},
298 "hugepages": integer0_schema
,
299 "hugepages_consumed": integer0_schema
, # ignored, just for compatibility with host-list
300 "numa_socket": integer0_schema
,
301 "memory": integer1_schema
,
308 "core_id": integer0_schema
,
309 "thread_id": integer0_schema
,
310 "status": {"type": "string", "enum": ["noteligible"]},
311 "instance_id": {"type": "string"}, # ignored, just for compatibility with host-list
312 "v_thread_id": {"type": "integer"} # ignored, just for compatibility with host-list
314 "additionalProperties": False,
315 "required": ["core_id", "thread_id"]
324 "source_name": nameshort_schema
,
326 "Mbps": integer0_schema
,
334 "source_name": {"oneOf": [integer0_schema
, nameshort_schema
]},
336 "vlan": integer0_schema
, # ignored, just for backward compatibility
339 "additionalProperties": False,
340 "required": ["source_name", "mac", "pci"]
343 "switch_port": nameshort_schema
,
344 "switch_dpid": nameshort_schema
,
345 "switch_mac": mac_schema
,
347 "additionalProperties": False,
348 "required": ["source_name", "mac", "Mbps", "pci"]
352 "additionalProperties": False,
353 "required": ["cores", "numa_socket"]
357 "additionalProperties": False,
358 "required": ["name", "user", "ip_name"]
362 "title":"hosts creation information schema",
363 "$schema": "http://json-schema.org/draft-04/schema#",
369 "ip_name":nameshort_schema
,
371 "description":description_schema
,
372 "user":nameshort_schema
,
373 "password":nameshort_schema
,
374 "admin_state_up":{"type":"boolean"},
380 "numa_socket": integer0_schema
,
381 "admin_state_up":{"type":"boolean"},
387 "source_name": nameshort_schema
,
388 "switch_dpid": nameshort_schema
,
389 "switch_port": nameshort_schema
,
391 "required": ["source_name"],
395 "required": ["numa_socket"],
396 "additionalProperties": False,
401 "additionalProperties": False
404 "required": ["host"],
406 "additionalProperties": False
410 "title":"hosts creation information schema",
411 "$schema": "http://json-schema.org/draft-04/schema#",
414 "host": host_data_schema
,
415 "host-data":host_data_schema
417 "required": ["host"],
420 "additionalProperties": False
424 flavor_new_schema
= {
425 "title":"flavor creation information schema",
426 "$schema": "http://json-schema.org/draft-04/schema#",
434 "description":description_schema
,
435 "ram":integer0_schema
,
436 "vcpus":integer0_schema
,
437 "extended": extended_schema
,
438 "public": yes_no_schema
443 "required": ["flavor"],
444 "additionalProperties": False
446 flavor_update_schema
= {
447 "title":"flavor update information schema",
448 "$schema": "http://json-schema.org/draft-04/schema#",
455 "description":description_schema
,
456 "ram":integer0_schema
,
457 "vcpus":integer0_schema
,
458 "extended": extended_schema
,
459 "public": yes_no_schema
462 "additionalProperties": False
465 "required": ["flavor"],
466 "additionalProperties": False
470 "title":"image creation information schema",
471 "$schema": "http://json-schema.org/draft-04/schema#",
478 "path": {"oneOf": [path_schema
, http_schema
]},
479 "description":description_schema
,
481 "metadata":metadata_schema
,
482 "public": yes_no_schema
484 "required": ["name","path"]
487 "required": ["image"],
488 "additionalProperties": False
491 image_update_schema
= {
492 "title":"image update information schema",
493 "$schema": "http://json-schema.org/draft-04/schema#",
499 "path":{"oneOf": [path_schema
, http_schema
]},
500 "description":description_schema
,
502 "metadata":metadata_schema
,
503 "public": yes_no_schema
506 "additionalProperties": False
509 "required": ["image"],
510 "additionalProperties": False
519 "bandwidth":bandwidth_schema
,
522 "mac_address": mac_schema
,
523 "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]},
524 "type": {"type":"string", "enum":["virtual","PF","VF","VFnotShared"]}
526 "additionalProperties": False,
531 server_new_schema
= {
532 "title":"server creation information schema",
533 "$schema": "http://json-schema.org/draft-04/schema#",
541 "description":description_schema
,
542 "start":{"type":"string", "enum":["yes","no","paused"]},
544 "flavorRef":id_schema
,
545 "imageRef":id_schema
,
546 "extended": extended_schema
,
547 "networks":networks_schema
549 "required": ["name","flavorRef","imageRef"]
552 "required": ["server"],
553 "additionalProperties": False
556 server_action_schema
= {
557 "title":"server action information schema",
558 "$schema": "http://json-schema.org/draft-04/schema#",
561 "start":{"oneOf":[{"type": "null"}, {"type":"string", "enum":["rebuild","null"] }]},
562 "pause":{"type": "null"},
563 "resume":{"type": "null"},
564 "shutoff":{"type": "null"},
565 "shutdown":{"type": "null"},
566 "forceOff":{"type": "null"},
567 "terminate":{"type": "null"},
572 "description":description_schema
,
574 "metadata":metadata_schema
,
575 "imageRef": id_schema
,
576 "disk": {"oneOf":[{"type": "null"}, {"type":"string"}] },
580 "rebuild":{"type": ["object","null"]},
582 "type": ["object","null"],
584 # "type":{"type":"string", "enum":["SOFT"] }
586 # "minProperties": 1,
587 # "maxProperties": 1,
588 # "additionalProperties": False
593 "additionalProperties": False
596 network_new_schema
= {
597 "title": "network creation information schema",
598 "$schema": "http://json-schema.org/draft-04/schema#",
606 "type": {"type":"string", "enum": ["bridge_man", "bridge_data", "data", "ptp"]},
607 "shared": {"type": "boolean"},
608 "tenant_id": id_schema
,
609 "admin_state_up": {"type": "boolean"},
610 "provider:vlan": vlan_schema
,
611 "provider:physical": net_bind_schema
,
612 "region": nameshort_schema
,
614 "enable_dhcp": {"type": "boolean"},
615 "dhcp_first_ip": ip_schema
,
616 "dhcp_last_ip": ip_schema
,
617 "dns": {"type": "array", "items": [ip_schema
]},
618 "links": {"type": "array", "items": {"type": "object", "properties": {
620 "iface": name_schema
,
621 "vlan": vlan_schema
},
622 "required": ["iface"],
623 "additionalProperties": False
627 "routes": {"type": "object", "properties": {"default": ip_schema
}, "patternProperties": {
628 "^([0-9]{1,3}.){3}[0-9]{1,3}/[0-9]{1,2}$": ip_schema
,
630 "additionalProperties": False
633 "bind_net": name_schema
, # can be name, or uuid
634 "bind_type": {"oneOf": [{"type": "null"}, {"type": "string", "pattern": "^vlan:[0-9]{1,4}$"}]}
639 "required": ["network"],
640 "additionalProperties": False
643 network_update_schema
= {
644 "title":"network update information schema",
645 "$schema": "http://json-schema.org/draft-04/schema#",
652 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
653 "shared":{"type":"boolean"},
654 "tenant_id":id_schema
,
655 "admin_state_up":{"type":"boolean"},
656 "provider:vlan":vlan_schema
,
657 "provider:physical":net_bind_schema
,
659 "enable_dhcp": {"type":"boolean"},
660 # "dhcp_first_ip": ip_schema,
661 # "dhcp_last_ip": ip_schema,
662 "bind_net":name_schema
, #can be name, or uuid
663 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
666 "additionalProperties": False
669 "required": ["network"],
670 "additionalProperties": False
675 "title":"port creation information schema",
676 "$schema": "http://json-schema.org/draft-04/schema#",
683 "name":nameshort_schema
,
684 "network_id":{"oneOf":[{"type": "null"}, id_schema
]},
685 "tenant_id":id_schema
,
686 "mac_address": {"oneOf":[{"type": "null"}, mac_schema
] },
687 "admin_state_up":{"type":"boolean"},
688 "bandwidth":bandwidth_schema
,
689 "binding:switch_port":nameshort_schema
,
690 "binding:vlan": {"oneOf":[{"type": "null"}, vlan_schema
]}
695 "required": ["port"],
696 "additionalProperties": False
699 port_update_schema
= {
700 "title":"port update information schema",
701 "$schema": "http://json-schema.org/draft-04/schema#",
707 "name":nameshort_schema
,
708 "network_id":{"anyOf":[{"type":"null"}, id_schema
] }
711 "additionalProperties": False
714 "required": ["port"],
715 "additionalProperties": False
719 "title":"localinfo information schema",
720 "$schema": "http://json-schema.org/draft-04/schema#",
723 "files":{ "type": "object"},
724 "inc_files":{ "type": "object"},
725 "server_files":{ "type": "object"}
727 "required": ["files"]
731 "title":"host information schema",
732 "$schema": "http://json-schema.org/draft-04/schema#",
737 "patternProperties":{
738 ".":{ "type": "string"}
743 "required": ["iface_names"]
746 openflow_controller_schema
= {
747 "title": "network creation information schema",
748 "$schema": "http://json-schema.org/draft-04/schema#",
755 "dpid": nameshort_schema
,
756 "ip": nameshort_schema
,
758 "type": nameshort_schema
,
759 "version": nametiny_schema
,
760 "user": nameshort_schema
,
761 "password": nameshort_schema
763 "required": ["dpid", "type", "ip", "port", "name"]
767 "additionalProperties": False
770 of_port_new_schema
= {
771 "title": "OF port mapping",
775 "region": nameshort_schema
,
776 "compute_node": nameshort_schema
,
777 "pci": pci_extended_schema
,
778 "switch_dpid": nameshort_schema
,
779 "switch_port": nameshort_schema
,
780 "switch_mac": mac_schema
782 "required": ["region", "compute_node", "pci", "switch_dpid"]
785 of_port_map_new_schema
= {
786 "title": "OF port mapping",
787 "$schema": "http://json-schema.org/draft-04/schema#",
790 "of_port_mapings": {"type": "array", "items": of_port_new_schema
, "minLenght":1},
792 "required": ["of_port_mapings"],
793 "additionalProperties": False