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", "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 } #"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}$"
45 id_schema
= {"type" : "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
46 pci_schema
={"type":"string", "pattern":"^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\.[0-9a-fA-F]$"}
47 bandwidth_schema
={"type":"string", "pattern" : "^[0-9]+ *([MG]bps)?$"}
48 integer0_schema
={"type":"integer","minimum":0}
49 integer1_schema
={"type":"integer","minimum":1}
50 vlan_schema
={"type":"integer","minimum":1,"maximun":4095}
51 vlan1000_schema
={"type":"integer","minimum":1000,"maximun":4095}
52 mac_schema
={"type":"string", "pattern":"^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} #must be unicast LSB bit of MSB byte ==0
53 net_bind_schema
={"oneOf":[{"type":"null"},{"type":"string", "pattern":"^(default|((bridge|macvtap):[0-9a-zA-Z\.\-]{1,50})|openflow:[/0-9a-zA-Z\.\-]{1,50}(:vlan)?)$"}]}
54 yes_no_schema
={"type":"string", "enum":["yes", "no"]}
55 log_level_schema
={"type":"string", "enum":["DEBUG", "INFO", "WARNING","ERROR","CRITICAL"]}
58 "title":"main configuration information schema",
59 "$schema": "http://json-schema.org/draft-04/schema#",
62 "http_port": port_schema
,
63 "http_admin_port": port_schema
,
64 "http_host": nameshort_schema
,
65 "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
66 "db_host": nameshort_schema
,
67 "db_user": nameshort_schema
,
68 "db_passwd": {"type":"string"},
69 "db_name": nameshort_schema
,
70 "of_controller_ip": ip_schema
,
71 "of_controller_port": port_schema
,
72 "of_controller_dpid": nameshort_schema
,
73 "of_controller_nets_with_same_vlan": {"type" : "boolean"},
74 "of_controller": nameshort_schema
, #{"type":"string", "enum":["floodlight", "opendaylight"]},
75 "of_controller_module": {"type":"string"},
76 #"of_user": nameshort_schema,
77 #"of_password": nameshort_schema,
78 "test_mode": {"type": "boolean"}, #leave for backward compatibility
79 "mode": {"type":"string", "enum":["normal", "host only", "OF only", "development", "test"] },
80 "development_bridge": {"type":"string"},
81 "tenant_id": {"type" : "string"},
82 "image_path": path_schema
,
83 "network_vlan_range_start": vlan_schema
,
84 "network_vlan_range_end": vlan_schema
,
87 "patternProperties": {
90 "items": integer0_schema
,
100 "host" : name_schema
,
101 "port" : port_schema
,
102 "provider" : {"type": "string", "enum": ["isc-dhcp-server"]},
103 "user" : nameshort_schema
,
104 "password" : {"type": "string"},
105 "key" : {"type": "string"},
108 "items": nameshort_schema
,
112 "items": name_schema
,
115 "required": ['host', 'provider', 'user']
117 "log_level": log_level_schema
,
118 "log_level_db": log_level_schema
,
119 "log_level_of": log_level_schema
,
120 "network_type": {"type": "string", "enum": ["ovs", "bridge"]},
121 "ovs_controller_file_path": path_schema
,
122 "ovs_controller_user": nameshort_schema
,
124 "ovs_controller_ip": nameshort_schema
126 "patternProperties": {
127 "of_*" : {"type": ["string", "integer", "boolean"]}
129 "required": ['db_host', 'db_user', 'db_passwd', 'db_name',
130 'of_controller_ip', 'of_controller_port', 'of_controller_dpid', 'of_controller'],
131 "additionalProperties": False
139 "architecture": {"type":"string"},
140 "use_incremental": yes_no_schema
,
142 "os_distro": {"type":"string"},
143 "os_type": {"type":"string"},
144 "os_version": {"type":"string"},
145 "bus": {"type":"string"},
146 "topology": {"type":"string", "enum": ["oneSocket"]}
152 tenant_new_schema
= {
153 "title":"tenant creation information schema",
154 "$schema": "http://json-schema.org/draft-04/schema#",
161 "name": nameshort_schema
,
162 "description":description_schema
,
163 "enabled":{"type" : "boolean"}
168 "required": ["tenant"],
169 "additionalProperties": False
171 tenant_edit_schema
= {
172 "title":"tenant edition information schema",
173 "$schema": "http://json-schema.org/draft-04/schema#",
180 "name":nameshort_schema
,
181 "description":description_schema
,
182 "enabled":{"type" : "boolean"}
184 "additionalProperties": False,
187 "required": ["tenant"],
188 "additionalProperties": False
197 "dedicated":{"type":"string","enum":["yes","no","yes:sriov"]},
198 "bandwidth":bandwidth_schema
,
201 "mac_address":mac_schema
203 "additionalProperties": False,
204 "required": ["dedicated", "bandwidth"]
211 "processor_ranking":integer0_schema
,
217 "type":{"type":"string", "enum":["usb","disk","cdrom","xml"]},
219 "imageRef":id_schema
,
220 "xml":xml_text_schema
,
221 "dev":nameshort_schema
223 "additionalProperties": False,
232 "memory":integer1_schema
,
233 "cores":integer1_schema
,
234 "paired-threads":integer1_schema
,
235 "threads":integer1_schema
,
236 "cores-id":{"type":"array","items":integer0_schema
},
237 "paired-threads-id":{"type":"array","items":{"type":"array","minItems":2,"maxItems":2,"items":integer0_schema
}},
238 "threads-id":{"type":"array","items":integer0_schema
},
239 "interfaces":interfaces_schema
241 "additionalProperties": False,
243 #"required": ["memory"]
247 #"additionalProperties": False,
248 #"required": ["processor_ranking"]
252 "title":"hosts manual insertion information schema",
255 "ip_name":nameshort_schema
,
257 "description":description_schema
,
258 "user":nameshort_schema
,
259 "password":nameshort_schema
,
260 "features":description_schema
,
261 "ranking":integer0_schema
,
267 "type":{"type":"string", "enum":["usb","disk"]},
270 "additionalProperties": False,
280 "admin_state_up":{"type":"boolean"},
281 "hugepages":integer0_schema
,
288 "core_id":integer0_schema
,
289 "thread_id":integer0_schema
,
290 "status": {"type":"string", "enum":["noteligible"]}
292 "additionalProperties": False,
293 "required": ["core_id","thread_id"]
302 "source_name":nameshort_schema
,
304 "Mbps":integer0_schema
,
312 "source_name":{"oneOf":[integer0_schema
, nameshort_schema
]},
314 "vlan":integer0_schema
,
317 "additionalProperties": False,
318 "required": ["source_name","mac","pci"]
321 "switch_port": nameshort_schema
,
322 "switch_dpid": nameshort_schema
,
324 "additionalProperties": False,
325 "required": ["source_name","mac","Mbps","pci"]
328 "numa_socket":integer0_schema
,
329 "memory":integer1_schema
331 "additionalProperties": False,
332 "required": ["cores","numa_socket"]
336 "additionalProperties": False,
337 "required": ["ranking", "numas","ip_name","user"]
341 "title":"hosts creation information schema",
342 "$schema": "http://json-schema.org/draft-04/schema#",
348 "ip_name":nameshort_schema
,
350 "description":description_schema
,
351 "user":nameshort_schema
,
352 "password":nameshort_schema
,
353 "admin_state_up":{"type":"boolean"},
359 "numa_socket": integer0_schema
,
360 "admin_state_up":{"type":"boolean"},
366 "source_name": nameshort_schema
,
367 "switch_dpid": nameshort_schema
,
368 "switch_port": nameshort_schema
,
370 "required": ["source_name"],
374 "required": ["numa_socket"],
375 "additionalProperties": False,
380 "additionalProperties": False
383 "required": ["host"],
385 "additionalProperties": False
389 "title":"hosts creation information schema",
390 "$schema": "http://json-schema.org/draft-04/schema#",
397 "ip_name":nameshort_schema
,
399 "description":description_schema
,
400 "user":nameshort_schema
,
401 "password":nameshort_schema
,
402 "admin_state_up":{"type":"boolean"},
404 "required": ["name","ip_name","user"]
406 "host-data":host_data_schema
408 "required": ["host"],
411 "additionalProperties": False
415 flavor_new_schema
= {
416 "title":"flavor creation information schema",
417 "$schema": "http://json-schema.org/draft-04/schema#",
425 "description":description_schema
,
426 "ram":integer0_schema
,
427 "vcpus":integer0_schema
,
428 "extended": extended_schema
,
429 "public": yes_no_schema
434 "required": ["flavor"],
435 "additionalProperties": False
437 flavor_update_schema
= {
438 "title":"flavor update information schema",
439 "$schema": "http://json-schema.org/draft-04/schema#",
446 "description":description_schema
,
447 "ram":integer0_schema
,
448 "vcpus":integer0_schema
,
449 "extended": extended_schema
,
450 "public": yes_no_schema
453 "additionalProperties": False
456 "required": ["flavor"],
457 "additionalProperties": False
461 "title":"image creation information schema",
462 "$schema": "http://json-schema.org/draft-04/schema#",
469 "path": {"oneOf": [path_schema
, http_schema
]},
470 "description":description_schema
,
472 "metadata":metadata_schema
,
473 "public": yes_no_schema
475 "required": ["name","path"]
478 "required": ["image"],
479 "additionalProperties": False
482 image_update_schema
= {
483 "title":"image update information schema",
484 "$schema": "http://json-schema.org/draft-04/schema#",
490 "path":{"oneOf": [path_schema
, http_schema
]},
491 "description":description_schema
,
493 "metadata":metadata_schema
,
494 "public": yes_no_schema
497 "additionalProperties": False
500 "required": ["image"],
501 "additionalProperties": False
510 "bandwidth":bandwidth_schema
,
513 "mac_address": mac_schema
,
514 "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]},
515 "type": {"type":"string", "enum":["virtual","PF","VF","VFnotShared"]}
517 "additionalProperties": False,
522 server_new_schema
= {
523 "title":"server creation information schema",
524 "$schema": "http://json-schema.org/draft-04/schema#",
532 "description":description_schema
,
533 "start":{"type":"string", "enum":["yes","no","paused"]},
535 "flavorRef":id_schema
,
536 "imageRef":id_schema
,
537 "extended": extended_schema
,
538 "networks":networks_schema
540 "required": ["name","flavorRef","imageRef"]
543 "required": ["server"],
544 "additionalProperties": False
547 server_action_schema
= {
548 "title":"server action information schema",
549 "$schema": "http://json-schema.org/draft-04/schema#",
552 "start":{"oneOf":[{"type": "null"}, {"type":"string", "enum":["rebuild","null"] }]},
553 "pause":{"type": "null"},
554 "resume":{"type": "null"},
555 "shutoff":{"type": "null"},
556 "shutdown":{"type": "null"},
557 "forceOff":{"type": "null"},
558 "terminate":{"type": "null"},
563 "description":description_schema
,
565 "metadata":metadata_schema
,
566 "imageRef": id_schema
,
567 "disk": {"oneOf":[{"type": "null"}, {"type":"string"}] },
571 "rebuild":{"type": ["object","null"]},
573 "type": ["object","null"],
575 # "type":{"type":"string", "enum":["SOFT"] }
577 # "minProperties": 1,
578 # "maxProperties": 1,
579 # "additionalProperties": False
584 "additionalProperties": False
587 network_new_schema
= {
588 "title":"network creation information schema",
589 "$schema": "http://json-schema.org/draft-04/schema#",
597 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
598 "shared":{"type":"boolean"},
599 "tenant_id":id_schema
,
600 "admin_state_up":{"type":"boolean"},
601 "provider:vlan":vlan_schema
,
602 "provider:physical":net_bind_schema
,
604 "enable_dhcp": {"type":"boolean"},
605 "dhcp_first_ip": ip_schema
,
606 "dhcp_last_ip": ip_schema
,
607 "bind_net":name_schema
, #can be name, or uuid
608 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
613 "required": ["network"],
614 "additionalProperties": False
616 network_update_schema
= {
617 "title":"network update information schema",
618 "$schema": "http://json-schema.org/draft-04/schema#",
625 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
626 "shared":{"type":"boolean"},
627 "tenant_id":id_schema
,
628 "admin_state_up":{"type":"boolean"},
629 "provider:vlan":vlan_schema
,
630 "provider:physical":net_bind_schema
,
632 "enable_dhcp": {"type":"boolean"},
633 # "dhcp_first_ip": ip_schema,
634 # "dhcp_last_ip": ip_schema,
635 "bind_net":name_schema
, #can be name, or uuid
636 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
639 "additionalProperties": False
642 "required": ["network"],
643 "additionalProperties": False
648 "title":"port creation information schema",
649 "$schema": "http://json-schema.org/draft-04/schema#",
656 "name":nameshort_schema
,
657 "network_id":{"oneOf":[{"type": "null"}, id_schema
]},
658 "tenant_id":id_schema
,
659 "mac_address": {"oneOf":[{"type": "null"}, mac_schema
] },
660 "admin_state_up":{"type":"boolean"},
661 "bandwidth":bandwidth_schema
,
662 "binding:switch_port":nameshort_schema
,
663 "binding:vlan": {"oneOf":[{"type": "null"}, vlan_schema
]}
668 "required": ["port"],
669 "additionalProperties": False
672 port_update_schema
= {
673 "title":"port update information schema",
674 "$schema": "http://json-schema.org/draft-04/schema#",
680 "name":nameshort_schema
,
681 "network_id":{"anyOf":[{"type":"null"}, id_schema
] }
684 "additionalProperties": False
687 "required": ["port"],
688 "additionalProperties": False
692 "title":"localinfo information schema",
693 "$schema": "http://json-schema.org/draft-04/schema#",
696 "files":{ "type": "object"},
697 "inc_files":{ "type": "object"},
698 "server_files":{ "type": "object"}
700 "required": ["files"]
704 "title":"host information schema",
705 "$schema": "http://json-schema.org/draft-04/schema#",
710 "patternProperties":{
711 ".":{ "type": "string"}
716 "required": ["iface_names"]