minor changes at host thread tasks scheduler
[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 "ovs_controller_file_path": path_schema,
122 "ovs_controller_user": nameshort_schema,
123
124 "ovs_controller_ip": nameshort_schema
125 },
126 "patternProperties": {
127 "of_*" : {"type": ["string", "integer", "boolean"]}
128 },
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
132 }
133
134
135
136 metadata_schema={
137 "type":"object",
138 "properties":{
139 "architecture": {"type":"string"},
140 "use_incremental": yes_no_schema,
141 "vpci": pci_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"]}
147 }
148 }
149
150
151
152 tenant_new_schema = {
153 "title":"tenant creation information schema",
154 "$schema": "http://json-schema.org/draft-04/schema#",
155 "type":"object",
156 "properties":{
157 "tenant":{
158 "type":"object",
159 "properties":{
160 "id":id_schema,
161 "name": nameshort_schema,
162 "description":description_schema,
163 "enabled":{"type" : "boolean"}
164 },
165 "required": ["name"]
166 }
167 },
168 "required": ["tenant"],
169 "additionalProperties": False
170 }
171 tenant_edit_schema = {
172 "title":"tenant edition information schema",
173 "$schema": "http://json-schema.org/draft-04/schema#",
174 "type":"object",
175 "properties":{
176 "tenant":{
177 "type":"object",
178 "minProperties":1,
179 "properties":{
180 "name":nameshort_schema,
181 "description":description_schema,
182 "enabled":{"type" : "boolean"}
183 },
184 "additionalProperties": False,
185 }
186 },
187 "required": ["tenant"],
188 "additionalProperties": False
189 }
190 interfaces_schema={
191 "type":"array",
192 "minItems":0,
193 "items":{
194 "type":"object",
195 "properties":{
196 "name":name_schema,
197 "dedicated":{"type":"string","enum":["yes","no","yes:sriov"]},
198 "bandwidth":bandwidth_schema,
199 "vpci":pci_schema,
200 "uuid":id_schema,
201 "mac_address":mac_schema
202 },
203 "additionalProperties": False,
204 "required": ["dedicated", "bandwidth"]
205 }
206 }
207
208 extended_schema={
209 "type":"object",
210 "properties":{
211 "processor_ranking":integer0_schema,
212 "devices":{
213 "type": "array",
214 "items":{
215 "type": "object",
216 "properties":{
217 "type":{"type":"string", "enum":["usb","disk","cdrom","xml"]},
218 "vpci":pci_schema,
219 "imageRef":id_schema,
220 "xml":xml_text_schema,
221 "dev":nameshort_schema
222 },
223 "additionalProperties": False,
224 "required": ["type"]
225 }
226 },
227 "numas":{
228 "type": "array",
229 "items":{
230 "type": "object",
231 "properties":{
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
240 },
241 "additionalProperties": False,
242 "minProperties": 1,
243 #"required": ["memory"]
244 }
245 }
246 },
247 #"additionalProperties": False,
248 #"required": ["processor_ranking"]
249 }
250
251 host_data_schema={
252 "title":"hosts manual insertion information schema",
253 "type":"object",
254 "properties":{
255 "ip_name":nameshort_schema,
256 "name": name_schema,
257 "description":description_schema,
258 "user":nameshort_schema,
259 "password":nameshort_schema,
260 "features":description_schema,
261 "ranking":integer0_schema,
262 "devices":{
263 "type": "array",
264 "items":{
265 "type": "object",
266 "properties":{
267 "type":{"type":"string", "enum":["usb","disk"]},
268 "vpci":pci_schema
269 },
270 "additionalProperties": False,
271 "required": ["type"]
272 }
273 },
274 "numas":{
275 "type": "array",
276 "minItems":1,
277 "items":{
278 "type": "object",
279 "properties":{
280 "admin_state_up":{"type":"boolean"},
281 "hugepages":integer0_schema,
282 "cores":{
283 "type": "array",
284 "minItems":2,
285 "items":{
286 "type": "object",
287 "properties":{
288 "core_id":integer0_schema,
289 "thread_id":integer0_schema,
290 "status": {"type":"string", "enum":["noteligible"]}
291 },
292 "additionalProperties": False,
293 "required": ["core_id","thread_id"]
294 }
295 },
296 "interfaces":{
297 "type": "array",
298 "minItems":1,
299 "items":{
300 "type": "object",
301 "properties":{
302 "source_name":nameshort_schema,
303 "mac":mac_schema,
304 "Mbps":integer0_schema,
305 "pci":pci_schema,
306 "sriovs":{
307 "type": "array",
308 "minItems":1,
309 "items":{
310 "type": "object",
311 "properties":{
312 "source_name":{"oneOf":[integer0_schema, nameshort_schema]},
313 "mac":mac_schema,
314 "vlan":integer0_schema,
315 "pci":pci_schema,
316 },
317 "additionalProperties": False,
318 "required": ["source_name","mac","pci"]
319 }
320 },
321 "switch_port": nameshort_schema,
322 "switch_dpid": nameshort_schema,
323 },
324 "additionalProperties": False,
325 "required": ["source_name","mac","Mbps","pci"]
326 }
327 },
328 "numa_socket":integer0_schema,
329 "memory":integer1_schema
330 },
331 "additionalProperties": False,
332 "required": ["cores","numa_socket"]
333 }
334 }
335 },
336 "additionalProperties": False,
337 "required": ["ranking", "numas","ip_name","user"]
338 }
339
340 host_edit_schema={
341 "title":"hosts creation information schema",
342 "$schema": "http://json-schema.org/draft-04/schema#",
343 "type":"object",
344 "properties":{
345 "host":{
346 "type":"object",
347 "properties":{
348 "ip_name":nameshort_schema,
349 "name": name_schema,
350 "description":description_schema,
351 "user":nameshort_schema,
352 "password":nameshort_schema,
353 "admin_state_up":{"type":"boolean"},
354 "numas":{
355 "type":"array",
356 "items":{
357 "type": "object",
358 "properties":{
359 "numa_socket": integer0_schema,
360 "admin_state_up":{"type":"boolean"},
361 "interfaces":{
362 "type":"array",
363 "items":{
364 "type": "object",
365 "properties":{
366 "source_name": nameshort_schema,
367 "switch_dpid": nameshort_schema,
368 "switch_port": nameshort_schema,
369 },
370 "required": ["source_name"],
371 }
372 }
373 },
374 "required": ["numa_socket"],
375 "additionalProperties": False,
376 }
377 }
378 },
379 "minProperties": 1,
380 "additionalProperties": False
381 },
382 },
383 "required": ["host"],
384 "minProperties": 1,
385 "additionalProperties": False
386 }
387
388 host_new_schema = {
389 "title":"hosts creation information schema",
390 "$schema": "http://json-schema.org/draft-04/schema#",
391 "type":"object",
392 "properties":{
393 "host":{
394 "type":"object",
395 "properties":{
396 "id":id_schema,
397 "ip_name":nameshort_schema,
398 "name": name_schema,
399 "description":description_schema,
400 "user":nameshort_schema,
401 "password":nameshort_schema,
402 "admin_state_up":{"type":"boolean"},
403 },
404 "required": ["name","ip_name","user"]
405 },
406 "host-data":host_data_schema
407 },
408 "required": ["host"],
409 "minProperties": 1,
410 "maxProperties": 2,
411 "additionalProperties": False
412 }
413
414
415 flavor_new_schema = {
416 "title":"flavor creation information schema",
417 "$schema": "http://json-schema.org/draft-04/schema#",
418 "type":"object",
419 "properties":{
420 "flavor":{
421 "type":"object",
422 "properties":{
423 "id":id_schema,
424 "name":name_schema,
425 "description":description_schema,
426 "ram":integer0_schema,
427 "vcpus":integer0_schema,
428 "extended": extended_schema,
429 "public": yes_no_schema
430 },
431 "required": ["name"]
432 }
433 },
434 "required": ["flavor"],
435 "additionalProperties": False
436 }
437 flavor_update_schema = {
438 "title":"flavor update information schema",
439 "$schema": "http://json-schema.org/draft-04/schema#",
440 "type":"object",
441 "properties":{
442 "flavor":{
443 "type":"object",
444 "properties":{
445 "name":name_schema,
446 "description":description_schema,
447 "ram":integer0_schema,
448 "vcpus":integer0_schema,
449 "extended": extended_schema,
450 "public": yes_no_schema
451 },
452 "minProperties": 1,
453 "additionalProperties": False
454 }
455 },
456 "required": ["flavor"],
457 "additionalProperties": False
458 }
459
460 image_new_schema = {
461 "title":"image creation information schema",
462 "$schema": "http://json-schema.org/draft-04/schema#",
463 "type":"object",
464 "properties":{
465 "image":{
466 "type":"object",
467 "properties":{
468 "id":id_schema,
469 "path": {"oneOf": [path_schema, http_schema]},
470 "description":description_schema,
471 "name":name_schema,
472 "metadata":metadata_schema,
473 "public": yes_no_schema
474 },
475 "required": ["name","path"]
476 }
477 },
478 "required": ["image"],
479 "additionalProperties": False
480 }
481
482 image_update_schema = {
483 "title":"image update information schema",
484 "$schema": "http://json-schema.org/draft-04/schema#",
485 "type":"object",
486 "properties":{
487 "image":{
488 "type":"object",
489 "properties":{
490 "path":{"oneOf": [path_schema, http_schema]},
491 "description":description_schema,
492 "name":name_schema,
493 "metadata":metadata_schema,
494 "public": yes_no_schema
495 },
496 "minProperties": 1,
497 "additionalProperties": False
498 }
499 },
500 "required": ["image"],
501 "additionalProperties": False
502 }
503
504 networks_schema={
505 "type":"array",
506 "items":{
507 "type":"object",
508 "properties":{
509 "name":name_schema,
510 "bandwidth":bandwidth_schema,
511 "vpci":pci_schema,
512 "uuid":id_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"]}
516 },
517 "additionalProperties": False,
518 "required": ["uuid"]
519 }
520 }
521
522 server_new_schema = {
523 "title":"server creation information schema",
524 "$schema": "http://json-schema.org/draft-04/schema#",
525 "type":"object",
526 "properties":{
527 "server":{
528 "type":"object",
529 "properties":{
530 "id":id_schema,
531 "name":name_schema,
532 "description":description_schema,
533 "start":{"type":"string", "enum":["yes","no","paused"]},
534 "hostId":id_schema,
535 "flavorRef":id_schema,
536 "imageRef":id_schema,
537 "extended": extended_schema,
538 "networks":networks_schema
539 },
540 "required": ["name","flavorRef","imageRef"]
541 }
542 },
543 "required": ["server"],
544 "additionalProperties": False
545 }
546
547 server_action_schema = {
548 "title":"server action information schema",
549 "$schema": "http://json-schema.org/draft-04/schema#",
550 "type":"object",
551 "properties":{
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"},
559 "createImage":{
560 "type":"object",
561 "properties":{
562 "path":path_schema,
563 "description":description_schema,
564 "name":name_schema,
565 "metadata":metadata_schema,
566 "imageRef": id_schema,
567 "disk": {"oneOf":[{"type": "null"}, {"type":"string"}] },
568 },
569 "required": ["name"]
570 },
571 "rebuild":{"type": ["object","null"]},
572 "reboot":{
573 "type": ["object","null"],
574 # "properties": {
575 # "type":{"type":"string", "enum":["SOFT"] }
576 # },
577 # "minProperties": 1,
578 # "maxProperties": 1,
579 # "additionalProperties": False
580 }
581 },
582 "minProperties": 1,
583 "maxProperties": 1,
584 "additionalProperties": False
585 }
586
587 network_new_schema = {
588 "title":"network creation information schema",
589 "$schema": "http://json-schema.org/draft-04/schema#",
590 "type":"object",
591 "properties":{
592 "network":{
593 "type":"object",
594 "properties":{
595 "id":id_schema,
596 "name":name_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,
603 "cidr":cidr_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}$"}]}
609 },
610 "required": ["name"]
611 }
612 },
613 "required": ["network"],
614 "additionalProperties": False
615 }
616 network_update_schema = {
617 "title":"network update information schema",
618 "$schema": "http://json-schema.org/draft-04/schema#",
619 "type":"object",
620 "properties":{
621 "network":{
622 "type":"object",
623 "properties":{
624 "name":name_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,
631 "cidr":cidr_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}$"}]}
637 },
638 "minProperties": 1,
639 "additionalProperties": False
640 }
641 },
642 "required": ["network"],
643 "additionalProperties": False
644 }
645
646
647 port_new_schema = {
648 "title":"port creation information schema",
649 "$schema": "http://json-schema.org/draft-04/schema#",
650 "type":"object",
651 "properties":{
652 "port":{
653 "type":"object",
654 "properties":{
655 "id":id_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 ]}
664 },
665 "required": ["name"]
666 }
667 },
668 "required": ["port"],
669 "additionalProperties": False
670 }
671
672 port_update_schema = {
673 "title":"port update information schema",
674 "$schema": "http://json-schema.org/draft-04/schema#",
675 "type":"object",
676 "properties":{
677 "port":{
678 "type":"object",
679 "properties":{
680 "name":nameshort_schema,
681 "network_id":{"anyOf":[{"type":"null"}, id_schema ] }
682 },
683 "minProperties": 1,
684 "additionalProperties": False
685 }
686 },
687 "required": ["port"],
688 "additionalProperties": False
689 }
690
691 localinfo_schema = {
692 "title":"localinfo information schema",
693 "$schema": "http://json-schema.org/draft-04/schema#",
694 "type":"object",
695 "properties":{
696 "files":{ "type": "object"},
697 "inc_files":{ "type": "object"},
698 "server_files":{ "type": "object"}
699 },
700 "required": ["files"]
701 }
702
703 hostinfo_schema = {
704 "title":"host information schema",
705 "$schema": "http://json-schema.org/draft-04/schema#",
706 "type":"object",
707 "properties":{
708 "iface_names":{
709 "type":"object",
710 "patternProperties":{
711 ".":{ "type": "string"}
712 },
713 "minProperties": 1
714 }
715 },
716 "required": ["iface_names"]
717 }