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
,
121 "patternProperties": {
122 "of_*" : {"type": ["string", "integer", "boolean"]}
124 "required": ['db_host', 'db_user', 'db_passwd', 'db_name',
125 'of_controller_ip', 'of_controller_port', 'of_controller_dpid', 'bridge_ifaces', 'of_controller'],
126 "additionalProperties": False
134 "architecture": {"type":"string"},
135 "use_incremental": yes_no_schema
,
137 "os_distro": {"type":"string"},
138 "os_type": {"type":"string"},
139 "os_version": {"type":"string"},
140 "bus": {"type":"string"},
141 "topology": {"type":"string", "enum": ["oneSocket"]}
147 tenant_new_schema
= {
148 "title":"tenant creation information schema",
149 "$schema": "http://json-schema.org/draft-04/schema#",
156 "name": nameshort_schema
,
157 "description":description_schema
,
158 "enabled":{"type" : "boolean"}
163 "required": ["tenant"],
164 "additionalProperties": False
166 tenant_edit_schema
= {
167 "title":"tenant edition information schema",
168 "$schema": "http://json-schema.org/draft-04/schema#",
175 "name":nameshort_schema
,
176 "description":description_schema
,
177 "enabled":{"type" : "boolean"}
179 "additionalProperties": False,
182 "required": ["tenant"],
183 "additionalProperties": False
192 "dedicated":{"type":"string","enum":["yes","no","yes:sriov"]},
193 "bandwidth":bandwidth_schema
,
196 "mac_address":mac_schema
198 "additionalProperties": False,
199 "required": ["dedicated", "bandwidth"]
206 "processor_ranking":integer0_schema
,
212 "type":{"type":"string", "enum":["usb","disk","cdrom","xml"]},
214 "imageRef":id_schema
,
215 "xml":xml_text_schema
,
216 "dev":nameshort_schema
218 "additionalProperties": False,
227 "memory":integer1_schema
,
228 "cores":integer1_schema
,
229 "paired-threads":integer1_schema
,
230 "threads":integer1_schema
,
231 "cores-id":{"type":"array","items":integer0_schema
},
232 "paired-threads-id":{"type":"array","items":{"type":"array","minItems":2,"maxItems":2,"items":integer0_schema
}},
233 "threads-id":{"type":"array","items":integer0_schema
},
234 "interfaces":interfaces_schema
236 "additionalProperties": False,
238 #"required": ["memory"]
242 #"additionalProperties": False,
243 #"required": ["processor_ranking"]
247 "title":"hosts manual insertion information schema",
250 "ip_name":nameshort_schema
,
252 "description":description_schema
,
253 "user":nameshort_schema
,
254 "password":nameshort_schema
,
255 "features":description_schema
,
256 "ranking":integer0_schema
,
262 "type":{"type":"string", "enum":["usb","disk"]},
265 "additionalProperties": False,
275 "admin_state_up":{"type":"boolean"},
276 "hugepages":integer0_schema
,
283 "core_id":integer0_schema
,
284 "thread_id":integer0_schema
,
285 "status": {"type":"string", "enum":["noteligible"]}
287 "additionalProperties": False,
288 "required": ["core_id","thread_id"]
297 "source_name":nameshort_schema
,
299 "Mbps":integer0_schema
,
307 "source_name":{"oneOf":[integer0_schema
, nameshort_schema
]},
309 "vlan":integer0_schema
,
312 "additionalProperties": False,
313 "required": ["source_name","mac","pci"]
316 "switch_port": nameshort_schema
,
317 "switch_dpid": nameshort_schema
,
319 "additionalProperties": False,
320 "required": ["source_name","mac","Mbps","pci"]
323 "numa_socket":integer0_schema
,
324 "memory":integer1_schema
326 "additionalProperties": False,
327 "required": ["cores","numa_socket"]
331 "additionalProperties": False,
332 "required": ["ranking", "numas","ip_name","user"]
336 "title":"hosts creation information schema",
337 "$schema": "http://json-schema.org/draft-04/schema#",
343 "ip_name":nameshort_schema
,
345 "description":description_schema
,
346 "user":nameshort_schema
,
347 "password":nameshort_schema
,
348 "admin_state_up":{"type":"boolean"},
354 "numa_socket": integer0_schema
,
355 "admin_state_up":{"type":"boolean"},
361 "source_name": nameshort_schema
,
362 "switch_dpid": nameshort_schema
,
363 "switch_port": nameshort_schema
,
365 "required": ["source_name"],
369 "required": ["numa_socket"],
370 "additionalProperties": False,
375 "additionalProperties": False
378 "required": ["host"],
380 "additionalProperties": False
384 "title":"hosts creation information schema",
385 "$schema": "http://json-schema.org/draft-04/schema#",
392 "ip_name":nameshort_schema
,
394 "description":description_schema
,
395 "user":nameshort_schema
,
396 "password":nameshort_schema
,
397 "admin_state_up":{"type":"boolean"},
399 "required": ["name","ip_name","user"]
401 "host-data":host_data_schema
403 "required": ["host"],
406 "additionalProperties": False
410 flavor_new_schema
= {
411 "title":"flavor creation information schema",
412 "$schema": "http://json-schema.org/draft-04/schema#",
420 "description":description_schema
,
421 "ram":integer0_schema
,
422 "vcpus":integer0_schema
,
423 "extended": extended_schema
,
424 "public": yes_no_schema
429 "required": ["flavor"],
430 "additionalProperties": False
432 flavor_update_schema
= {
433 "title":"flavor update information schema",
434 "$schema": "http://json-schema.org/draft-04/schema#",
441 "description":description_schema
,
442 "ram":integer0_schema
,
443 "vcpus":integer0_schema
,
444 "extended": extended_schema
,
445 "public": yes_no_schema
448 "additionalProperties": False
451 "required": ["flavor"],
452 "additionalProperties": False
456 "title":"image creation information schema",
457 "$schema": "http://json-schema.org/draft-04/schema#",
464 "path": {"oneOf": [path_schema
, http_schema
]},
465 "description":description_schema
,
467 "metadata":metadata_schema
,
468 "public": yes_no_schema
470 "required": ["name","path"]
473 "required": ["image"],
474 "additionalProperties": False
477 image_update_schema
= {
478 "title":"image update information schema",
479 "$schema": "http://json-schema.org/draft-04/schema#",
485 "path":{"oneOf": [path_schema
, http_schema
]},
486 "description":description_schema
,
488 "metadata":metadata_schema
,
489 "public": yes_no_schema
492 "additionalProperties": False
495 "required": ["image"],
496 "additionalProperties": False
505 "bandwidth":bandwidth_schema
,
508 "mac_address": mac_schema
,
509 "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]},
510 "type": {"type":"string", "enum":["virtual","PF","VF","VFnotShared"]}
512 "additionalProperties": False,
517 server_new_schema
= {
518 "title":"server creation information schema",
519 "$schema": "http://json-schema.org/draft-04/schema#",
527 "description":description_schema
,
528 "start":{"type":"string", "enum":["yes","no","paused"]},
530 "flavorRef":id_schema
,
531 "imageRef":id_schema
,
532 "extended": extended_schema
,
533 "networks":networks_schema
535 "required": ["name","flavorRef","imageRef"]
538 "required": ["server"],
539 "additionalProperties": False
542 server_action_schema
= {
543 "title":"server action information schema",
544 "$schema": "http://json-schema.org/draft-04/schema#",
547 "start":{"oneOf":[{"type": "null"}, {"type":"string", "enum":["rebuild","null"] }]},
548 "pause":{"type": "null"},
549 "resume":{"type": "null"},
550 "shutoff":{"type": "null"},
551 "shutdown":{"type": "null"},
552 "forceOff":{"type": "null"},
553 "terminate":{"type": "null"},
558 "description":description_schema
,
560 "metadata":metadata_schema
,
561 "imageRef": id_schema
,
562 "disk": {"oneOf":[{"type": "null"}, {"type":"string"}] },
566 "rebuild":{"type": ["object","null"]},
568 "type": ["object","null"],
570 # "type":{"type":"string", "enum":["SOFT"] }
572 # "minProperties": 1,
573 # "maxProperties": 1,
574 # "additionalProperties": False
579 "additionalProperties": False
582 network_new_schema
= {
583 "title":"network creation information schema",
584 "$schema": "http://json-schema.org/draft-04/schema#",
592 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
593 "shared":{"type":"boolean"},
594 "tenant_id":id_schema
,
595 "admin_state_up":{"type":"boolean"},
596 "provider:vlan":vlan_schema
,
597 "provider:physical":net_bind_schema
,
599 "enable_dhcp": {"type":"boolean"},
600 "dhcp_first_ip": ip_schema
,
601 "dhcp_last_ip": ip_schema
,
602 "bind_net":name_schema
, #can be name, or uuid
603 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
608 "required": ["network"],
609 "additionalProperties": False
611 network_update_schema
= {
612 "title":"network update information schema",
613 "$schema": "http://json-schema.org/draft-04/schema#",
620 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
621 "shared":{"type":"boolean"},
622 "tenant_id":id_schema
,
623 "admin_state_up":{"type":"boolean"},
624 "provider:vlan":vlan_schema
,
625 "provider:physical":net_bind_schema
,
627 "enable_dhcp": {"type":"boolean"},
628 "dhcp_first_ip": ip_schema
,
629 "dhcp_last_ip": ip_schema
,
630 "bind_net":name_schema
, #can be name, or uuid
631 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
634 "additionalProperties": False
637 "required": ["network"],
638 "additionalProperties": False
643 "title":"port creation information schema",
644 "$schema": "http://json-schema.org/draft-04/schema#",
651 "name":nameshort_schema
,
652 "network_id":{"oneOf":[{"type": "null"}, id_schema
]},
653 "tenant_id":id_schema
,
654 "mac_address": {"oneOf":[{"type": "null"}, mac_schema
] },
655 "admin_state_up":{"type":"boolean"},
656 "bandwidth":bandwidth_schema
,
657 "binding:switch_port":nameshort_schema
,
658 "binding:vlan": {"oneOf":[{"type": "null"}, vlan_schema
]}
663 "required": ["port"],
664 "additionalProperties": False
667 port_update_schema
= {
668 "title":"port update information schema",
669 "$schema": "http://json-schema.org/draft-04/schema#",
675 "name":nameshort_schema
,
676 "network_id":{"anyOf":[{"type":"null"}, id_schema
] }
679 "additionalProperties": False
682 "required": ["port"],
683 "additionalProperties": False
687 "title":"localinfo information schema",
688 "$schema": "http://json-schema.org/draft-04/schema#",
691 "files":{ "type": "object"},
692 "inc_files":{ "type": "object"},
693 "server_files":{ "type": "object"}
695 "required": ["files"]
699 "title":"host information schema",
700 "$schema": "http://json-schema.org/draft-04/schema#",
705 "patternProperties":{
706 ".":{ "type": "string"}
711 "required": ["iface_names"]