Refactor to support OVS insted of prepopulate tagged interfaces and linux briges
[osm/openvim.git] / vim_schema.py
1 # -*- coding: utf-8 -*-
2
3 ##
4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
6 # All Rights Reserved.
7 #
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
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
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
18 # under the License.
19 #
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
22 ##
23
24 ''' Definition of dictionaries schemas used by validating input
25 These dictionaries are validated using jsonschema library
26 '''
27 __author__="Alfonso Tierno"
28 __date__ ="$10-jul-2014 12:07:15$"
29
30 #
31 # SCHEMAS to validate input data
32 #
33
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"]}
56
57 config_schema = {
58 "title":"main configuration information schema",
59 "$schema": "http://json-schema.org/draft-04/schema#",
60 "type":"object",
61 "properties":{
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,
85 "bridge_ifaces": {
86 "type": "object",
87 "patternProperties": {
88 "." : {
89 "type": "array",
90 "items": integer0_schema,
91 "minItems":2,
92 "maxItems":2,
93 },
94 },
95 "minProperties": 2
96 },
97 "dhcp_server": {
98 "type": "object",
99 "properties": {
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"},
106 "bridge_ifaces" :{
107 "type": "array",
108 "items": nameshort_schema,
109 },
110 "nets" :{
111 "type": "array",
112 "items": name_schema,
113 },
114 },
115 "required": ['host', 'provider', 'user']
116 },
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 },
122 "patternProperties": {
123 "of_*" : {"type": ["string", "integer", "boolean"]}
124 },
125 "required": ['db_host', 'db_user', 'db_passwd', 'db_name',
126 'of_controller_ip', 'of_controller_port', 'of_controller_dpid', 'of_controller'],
127 "additionalProperties": False
128 }
129
130
131
132 metadata_schema={
133 "type":"object",
134 "properties":{
135 "architecture": {"type":"string"},
136 "use_incremental": yes_no_schema,
137 "vpci": pci_schema,
138 "os_distro": {"type":"string"},
139 "os_type": {"type":"string"},
140 "os_version": {"type":"string"},
141 "bus": {"type":"string"},
142 "topology": {"type":"string", "enum": ["oneSocket"]}
143 }
144 }
145
146
147
148 tenant_new_schema = {
149 "title":"tenant creation information schema",
150 "$schema": "http://json-schema.org/draft-04/schema#",
151 "type":"object",
152 "properties":{
153 "tenant":{
154 "type":"object",
155 "properties":{
156 "id":id_schema,
157 "name": nameshort_schema,
158 "description":description_schema,
159 "enabled":{"type" : "boolean"}
160 },
161 "required": ["name"]
162 }
163 },
164 "required": ["tenant"],
165 "additionalProperties": False
166 }
167 tenant_edit_schema = {
168 "title":"tenant edition information schema",
169 "$schema": "http://json-schema.org/draft-04/schema#",
170 "type":"object",
171 "properties":{
172 "tenant":{
173 "type":"object",
174 "minProperties":1,
175 "properties":{
176 "name":nameshort_schema,
177 "description":description_schema,
178 "enabled":{"type" : "boolean"}
179 },
180 "additionalProperties": False,
181 }
182 },
183 "required": ["tenant"],
184 "additionalProperties": False
185 }
186 interfaces_schema={
187 "type":"array",
188 "minItems":0,
189 "items":{
190 "type":"object",
191 "properties":{
192 "name":name_schema,
193 "dedicated":{"type":"string","enum":["yes","no","yes:sriov"]},
194 "bandwidth":bandwidth_schema,
195 "vpci":pci_schema,
196 "uuid":id_schema,
197 "mac_address":mac_schema
198 },
199 "additionalProperties": False,
200 "required": ["dedicated", "bandwidth"]
201 }
202 }
203
204 extended_schema={
205 "type":"object",
206 "properties":{
207 "processor_ranking":integer0_schema,
208 "devices":{
209 "type": "array",
210 "items":{
211 "type": "object",
212 "properties":{
213 "type":{"type":"string", "enum":["usb","disk","cdrom","xml"]},
214 "vpci":pci_schema,
215 "imageRef":id_schema,
216 "xml":xml_text_schema,
217 "dev":nameshort_schema
218 },
219 "additionalProperties": False,
220 "required": ["type"]
221 }
222 },
223 "numas":{
224 "type": "array",
225 "items":{
226 "type": "object",
227 "properties":{
228 "memory":integer1_schema,
229 "cores":integer1_schema,
230 "paired-threads":integer1_schema,
231 "threads":integer1_schema,
232 "cores-id":{"type":"array","items":integer0_schema},
233 "paired-threads-id":{"type":"array","items":{"type":"array","minItems":2,"maxItems":2,"items":integer0_schema}},
234 "threads-id":{"type":"array","items":integer0_schema},
235 "interfaces":interfaces_schema
236 },
237 "additionalProperties": False,
238 "minProperties": 1,
239 #"required": ["memory"]
240 }
241 }
242 },
243 #"additionalProperties": False,
244 #"required": ["processor_ranking"]
245 }
246
247 host_data_schema={
248 "title":"hosts manual insertion information schema",
249 "type":"object",
250 "properties":{
251 "ip_name":nameshort_schema,
252 "name": name_schema,
253 "description":description_schema,
254 "user":nameshort_schema,
255 "password":nameshort_schema,
256 "features":description_schema,
257 "ranking":integer0_schema,
258 "devices":{
259 "type": "array",
260 "items":{
261 "type": "object",
262 "properties":{
263 "type":{"type":"string", "enum":["usb","disk"]},
264 "vpci":pci_schema
265 },
266 "additionalProperties": False,
267 "required": ["type"]
268 }
269 },
270 "numas":{
271 "type": "array",
272 "minItems":1,
273 "items":{
274 "type": "object",
275 "properties":{
276 "admin_state_up":{"type":"boolean"},
277 "hugepages":integer0_schema,
278 "cores":{
279 "type": "array",
280 "minItems":2,
281 "items":{
282 "type": "object",
283 "properties":{
284 "core_id":integer0_schema,
285 "thread_id":integer0_schema,
286 "status": {"type":"string", "enum":["noteligible"]}
287 },
288 "additionalProperties": False,
289 "required": ["core_id","thread_id"]
290 }
291 },
292 "interfaces":{
293 "type": "array",
294 "minItems":1,
295 "items":{
296 "type": "object",
297 "properties":{
298 "source_name":nameshort_schema,
299 "mac":mac_schema,
300 "Mbps":integer0_schema,
301 "pci":pci_schema,
302 "sriovs":{
303 "type": "array",
304 "minItems":1,
305 "items":{
306 "type": "object",
307 "properties":{
308 "source_name":{"oneOf":[integer0_schema, nameshort_schema]},
309 "mac":mac_schema,
310 "vlan":integer0_schema,
311 "pci":pci_schema,
312 },
313 "additionalProperties": False,
314 "required": ["source_name","mac","pci"]
315 }
316 },
317 "switch_port": nameshort_schema,
318 "switch_dpid": nameshort_schema,
319 },
320 "additionalProperties": False,
321 "required": ["source_name","mac","Mbps","pci"]
322 }
323 },
324 "numa_socket":integer0_schema,
325 "memory":integer1_schema
326 },
327 "additionalProperties": False,
328 "required": ["cores","numa_socket"]
329 }
330 }
331 },
332 "additionalProperties": False,
333 "required": ["ranking", "numas","ip_name","user"]
334 }
335
336 host_edit_schema={
337 "title":"hosts creation information schema",
338 "$schema": "http://json-schema.org/draft-04/schema#",
339 "type":"object",
340 "properties":{
341 "host":{
342 "type":"object",
343 "properties":{
344 "ip_name":nameshort_schema,
345 "name": name_schema,
346 "description":description_schema,
347 "user":nameshort_schema,
348 "password":nameshort_schema,
349 "admin_state_up":{"type":"boolean"},
350 "numas":{
351 "type":"array",
352 "items":{
353 "type": "object",
354 "properties":{
355 "numa_socket": integer0_schema,
356 "admin_state_up":{"type":"boolean"},
357 "interfaces":{
358 "type":"array",
359 "items":{
360 "type": "object",
361 "properties":{
362 "source_name": nameshort_schema,
363 "switch_dpid": nameshort_schema,
364 "switch_port": nameshort_schema,
365 },
366 "required": ["source_name"],
367 }
368 }
369 },
370 "required": ["numa_socket"],
371 "additionalProperties": False,
372 }
373 }
374 },
375 "minProperties": 1,
376 "additionalProperties": False
377 },
378 },
379 "required": ["host"],
380 "minProperties": 1,
381 "additionalProperties": False
382 }
383
384 host_new_schema = {
385 "title":"hosts creation information schema",
386 "$schema": "http://json-schema.org/draft-04/schema#",
387 "type":"object",
388 "properties":{
389 "host":{
390 "type":"object",
391 "properties":{
392 "id":id_schema,
393 "ip_name":nameshort_schema,
394 "name": name_schema,
395 "description":description_schema,
396 "user":nameshort_schema,
397 "password":nameshort_schema,
398 "admin_state_up":{"type":"boolean"},
399 },
400 "required": ["name","ip_name","user"]
401 },
402 "host-data":host_data_schema
403 },
404 "required": ["host"],
405 "minProperties": 1,
406 "maxProperties": 2,
407 "additionalProperties": False
408 }
409
410
411 flavor_new_schema = {
412 "title":"flavor creation information schema",
413 "$schema": "http://json-schema.org/draft-04/schema#",
414 "type":"object",
415 "properties":{
416 "flavor":{
417 "type":"object",
418 "properties":{
419 "id":id_schema,
420 "name":name_schema,
421 "description":description_schema,
422 "ram":integer0_schema,
423 "vcpus":integer0_schema,
424 "extended": extended_schema,
425 "public": yes_no_schema
426 },
427 "required": ["name"]
428 }
429 },
430 "required": ["flavor"],
431 "additionalProperties": False
432 }
433 flavor_update_schema = {
434 "title":"flavor update information schema",
435 "$schema": "http://json-schema.org/draft-04/schema#",
436 "type":"object",
437 "properties":{
438 "flavor":{
439 "type":"object",
440 "properties":{
441 "name":name_schema,
442 "description":description_schema,
443 "ram":integer0_schema,
444 "vcpus":integer0_schema,
445 "extended": extended_schema,
446 "public": yes_no_schema
447 },
448 "minProperties": 1,
449 "additionalProperties": False
450 }
451 },
452 "required": ["flavor"],
453 "additionalProperties": False
454 }
455
456 image_new_schema = {
457 "title":"image creation information schema",
458 "$schema": "http://json-schema.org/draft-04/schema#",
459 "type":"object",
460 "properties":{
461 "image":{
462 "type":"object",
463 "properties":{
464 "id":id_schema,
465 "path": {"oneOf": [path_schema, http_schema]},
466 "description":description_schema,
467 "name":name_schema,
468 "metadata":metadata_schema,
469 "public": yes_no_schema
470 },
471 "required": ["name","path"]
472 }
473 },
474 "required": ["image"],
475 "additionalProperties": False
476 }
477
478 image_update_schema = {
479 "title":"image update information schema",
480 "$schema": "http://json-schema.org/draft-04/schema#",
481 "type":"object",
482 "properties":{
483 "image":{
484 "type":"object",
485 "properties":{
486 "path":{"oneOf": [path_schema, http_schema]},
487 "description":description_schema,
488 "name":name_schema,
489 "metadata":metadata_schema,
490 "public": yes_no_schema
491 },
492 "minProperties": 1,
493 "additionalProperties": False
494 }
495 },
496 "required": ["image"],
497 "additionalProperties": False
498 }
499
500 networks_schema={
501 "type":"array",
502 "items":{
503 "type":"object",
504 "properties":{
505 "name":name_schema,
506 "bandwidth":bandwidth_schema,
507 "vpci":pci_schema,
508 "uuid":id_schema,
509 "mac_address": mac_schema,
510 "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]},
511 "type": {"type":"string", "enum":["virtual","PF","VF","VFnotShared"]}
512 },
513 "additionalProperties": False,
514 "required": ["uuid"]
515 }
516 }
517
518 server_new_schema = {
519 "title":"server creation information schema",
520 "$schema": "http://json-schema.org/draft-04/schema#",
521 "type":"object",
522 "properties":{
523 "server":{
524 "type":"object",
525 "properties":{
526 "id":id_schema,
527 "name":name_schema,
528 "description":description_schema,
529 "start":{"type":"string", "enum":["yes","no","paused"]},
530 "hostId":id_schema,
531 "flavorRef":id_schema,
532 "imageRef":id_schema,
533 "extended": extended_schema,
534 "networks":networks_schema
535 },
536 "required": ["name","flavorRef","imageRef"]
537 }
538 },
539 "required": ["server"],
540 "additionalProperties": False
541 }
542
543 server_action_schema = {
544 "title":"server action information schema",
545 "$schema": "http://json-schema.org/draft-04/schema#",
546 "type":"object",
547 "properties":{
548 "start":{"oneOf":[{"type": "null"}, {"type":"string", "enum":["rebuild","null"] }]},
549 "pause":{"type": "null"},
550 "resume":{"type": "null"},
551 "shutoff":{"type": "null"},
552 "shutdown":{"type": "null"},
553 "forceOff":{"type": "null"},
554 "terminate":{"type": "null"},
555 "createImage":{
556 "type":"object",
557 "properties":{
558 "path":path_schema,
559 "description":description_schema,
560 "name":name_schema,
561 "metadata":metadata_schema,
562 "imageRef": id_schema,
563 "disk": {"oneOf":[{"type": "null"}, {"type":"string"}] },
564 },
565 "required": ["name"]
566 },
567 "rebuild":{"type": ["object","null"]},
568 "reboot":{
569 "type": ["object","null"],
570 # "properties": {
571 # "type":{"type":"string", "enum":["SOFT"] }
572 # },
573 # "minProperties": 1,
574 # "maxProperties": 1,
575 # "additionalProperties": False
576 }
577 },
578 "minProperties": 1,
579 "maxProperties": 1,
580 "additionalProperties": False
581 }
582
583 network_new_schema = {
584 "title":"network creation information schema",
585 "$schema": "http://json-schema.org/draft-04/schema#",
586 "type":"object",
587 "properties":{
588 "network":{
589 "type":"object",
590 "properties":{
591 "id":id_schema,
592 "name":name_schema,
593 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
594 "shared":{"type":"boolean"},
595 "tenant_id":id_schema,
596 "admin_state_up":{"type":"boolean"},
597 "provider:vlan":vlan_schema,
598 "provider:physical":net_bind_schema,
599 "cidr":cidr_schema,
600 "enable_dhcp": {"type":"boolean"},
601 "dhcp_first_ip": ip_schema,
602 "dhcp_last_ip": ip_schema,
603 "bind_net":name_schema, #can be name, or uuid
604 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
605 },
606 "required": ["name"]
607 }
608 },
609 "required": ["network"],
610 "additionalProperties": False
611 }
612 network_update_schema = {
613 "title":"network update information schema",
614 "$schema": "http://json-schema.org/draft-04/schema#",
615 "type":"object",
616 "properties":{
617 "network":{
618 "type":"object",
619 "properties":{
620 "name":name_schema,
621 "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
622 "shared":{"type":"boolean"},
623 "tenant_id":id_schema,
624 "admin_state_up":{"type":"boolean"},
625 "provider:vlan":vlan_schema,
626 "provider:physical":net_bind_schema,
627 "cidr":cidr_schema,
628 "enable_dhcp": {"type":"boolean"},
629 "dhcp_first_ip": ip_schema,
630 "dhcp_last_ip": ip_schema,
631 "bind_net":name_schema, #can be name, or uuid
632 "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
633 },
634 "minProperties": 1,
635 "additionalProperties": False
636 }
637 },
638 "required": ["network"],
639 "additionalProperties": False
640 }
641
642
643 port_new_schema = {
644 "title":"port creation information schema",
645 "$schema": "http://json-schema.org/draft-04/schema#",
646 "type":"object",
647 "properties":{
648 "port":{
649 "type":"object",
650 "properties":{
651 "id":id_schema,
652 "name":nameshort_schema,
653 "network_id":{"oneOf":[{"type": "null"}, id_schema ]},
654 "tenant_id":id_schema,
655 "mac_address": {"oneOf":[{"type": "null"}, mac_schema] },
656 "admin_state_up":{"type":"boolean"},
657 "bandwidth":bandwidth_schema,
658 "binding:switch_port":nameshort_schema,
659 "binding:vlan": {"oneOf":[{"type": "null"}, vlan_schema ]}
660 },
661 "required": ["name"]
662 }
663 },
664 "required": ["port"],
665 "additionalProperties": False
666 }
667
668 port_update_schema = {
669 "title":"port update information schema",
670 "$schema": "http://json-schema.org/draft-04/schema#",
671 "type":"object",
672 "properties":{
673 "port":{
674 "type":"object",
675 "properties":{
676 "name":nameshort_schema,
677 "network_id":{"anyOf":[{"type":"null"}, id_schema ] }
678 },
679 "minProperties": 1,
680 "additionalProperties": False
681 }
682 },
683 "required": ["port"],
684 "additionalProperties": False
685 }
686
687 localinfo_schema = {
688 "title":"localinfo information schema",
689 "$schema": "http://json-schema.org/draft-04/schema#",
690 "type":"object",
691 "properties":{
692 "files":{ "type": "object"},
693 "inc_files":{ "type": "object"},
694 "server_files":{ "type": "object"}
695 },
696 "required": ["files"]
697 }
698
699 hostinfo_schema = {
700 "title":"host information schema",
701 "$schema": "http://json-schema.org/draft-04/schema#",
702 "type":"object",
703 "properties":{
704 "iface_names":{
705 "type":"object",
706 "patternProperties":{
707 ".":{ "type": "string"}
708 },
709 "minProperties": 1
710 }
711 },
712 "required": ["iface_names"]
713 }