v0.4.41 logging added. Split database into a base class db_base with general methods...
[osm/RO.git] / openmano_schemas.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 openmano
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 '''
25 JSON schemas used by openmano httpserver.py module to parse the different files and messages sent through the API
26 '''
27 __author__="Alfonso Tierno, Gerardo Garcia"
28 __date__ ="$09-oct-2014 09:09:48$"
29
30 #Basis schemas
31 patern_name="^[ -~]+$"
32 passwd_schema={"type" : "string", "minLength":1, "maxLength":60}
33 nameshort_schema={"type" : "string", "minLength":1, "maxLength":60, "pattern" : "^[^,;()'\"]+$"}
34 name_schema={"type" : "string", "minLength":1, "maxLength":255, "pattern" : "^[^,;()'\"]+$"}
35 xml_text_schema={"type" : "string", "minLength":1, "maxLength":1000, "pattern" : "^[^']+$"}
36 description_schema={"type" : ["string","null"], "maxLength":255, "pattern" : "^[^'\"]+$"}
37 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}$"
38 id_schema = {"type" : "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
39 pci_schema={"type":"string", "pattern":"^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\.[0-9a-fA-F]$"}
40 http_schema={"type":"string", "pattern":"^https?://[^'\"=]+$"}
41 bandwidth_schema={"type":"string", "pattern" : "^[0-9]+ *([MG]bps)?$"}
42 memory_schema={"type":"string", "pattern" : "^[0-9]+ *([MG]i?[Bb])?$"}
43 integer0_schema={"type":"integer","minimum":0}
44 integer1_schema={"type":"integer","minimum":1}
45 path_schema={"type":"string", "pattern":"^(\.){0,2}(/[^/\"':{}\(\)]+)+$"}
46 vlan_schema={"type":"integer","minimum":1,"maximum":4095}
47 vlan1000_schema={"type":"integer","minimum":1000,"maximum":4095}
48 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
49 #mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
50 ip_schema={"type":"string","pattern":"^([0-9]{1,3}.){3}[0-9]{1,3}$"}
51 port_schema={"type":"integer","minimum":1,"maximum":65534}
52 object_schema={"type":"object"}
53 schema_version_2={"type":"integer","minimum":2,"maximum":2}
54 log_level_schema={"type":"string", "enum":["DEBUG", "INFO", "WARNING","ERROR","CRITICAL"]}
55
56 metadata_schema={
57 "type":"object",
58 "properties":{
59 "architecture": {"type":"string"},
60 "use_incremental": {"type":"string","enum":["yes","no"]},
61 "vpci": pci_schema,
62 "os_distro": {"type":"string"},
63 "os_type": {"type":"string"},
64 "os_version": {"type":"string"},
65 "bus": {"type":"string"},
66 "topology": {"type":"string", "enum": ["oneSocket"]}
67 }
68 }
69
70 #Schema for the configuration file
71 config_schema = {
72 "title":"configuration response information schema",
73 "$schema": "http://json-schema.org/draft-04/schema#",
74 "type":"object",
75 "properties":{
76 "http_port": port_schema,
77 "http_admin_port": port_schema,
78 "http_host": nameshort_schema,
79 "vnf_repository": path_schema,
80 "db_host": nameshort_schema,
81 "db_user": nameshort_schema,
82 "db_passwd": {"type":"string"},
83 "db_name": nameshort_schema,
84 # Next fields will disappear once the MANO API includes appropriate primitives
85 "vim_url": http_schema,
86 "vim_url_admin": http_schema,
87 "vim_name": nameshort_schema,
88 "vim_tenant_name": nameshort_schema,
89 "mano_tenant_name": nameshort_schema,
90 "mano_tenant_id": id_schema,
91 "http_console_ports": {
92 "type": "array",
93 "items": {"OneOf" : [
94 port_schema,
95 {"type":"object", "properties":{"from": port_schema, "to": port_schema}, "required": ["from","to"]}
96 ]}
97 },
98 "log_level": log_level_schema,
99 "log_level_db": log_level_schema,
100 "log_level_vimconn": log_level_schema,
101 "log_level_nfvo": log_level_schema,
102 "log_host": nameshort_schema,
103 "log_port": port_schema,
104 "log_file": path_schema,
105 },
106 "required": ['db_host', 'db_user', 'db_passwd', 'db_name'],
107 "additionalProperties": False
108 }
109
110 tenant_schema = {
111 "title":"tenant information schema",
112 "$schema": "http://json-schema.org/draft-04/schema#",
113 "type":"object",
114 "properties":{
115 "tenant":{
116 "type":"object",
117 "properties":{
118 "name": nameshort_schema,
119 "description": description_schema,
120 },
121 "required": ["name"],
122 "additionalProperties": True
123 }
124 },
125 "required": ["tenant"],
126 "additionalProperties": False
127 }
128 tenant_edit_schema = {
129 "title":"tenant edit information schema",
130 "$schema": "http://json-schema.org/draft-04/schema#",
131 "type":"object",
132 "properties":{
133 "tenant":{
134 "type":"object",
135 "properties":{
136 "name": name_schema,
137 "description": description_schema,
138 },
139 "additionalProperties": False
140 }
141 },
142 "required": ["tenant"],
143 "additionalProperties": False
144 }
145
146 datacenter_schema_properties={
147 "name": name_schema,
148 "description": description_schema,
149 "type": nameshort_schema, #currently "openvim" or "openstack", can be enlarge with plugins
150 "vim_url": description_schema,
151 "vim_url_admin": description_schema,
152 "config": { "type":"object" }
153 }
154
155 datacenter_schema = {
156 "title":"datacenter information schema",
157 "$schema": "http://json-schema.org/draft-04/schema#",
158 "type":"object",
159 "properties":{
160 "datacenter":{
161 "type":"object",
162 "properties":datacenter_schema_properties,
163 "required": ["name", "vim_url"],
164 "additionalProperties": True
165 }
166 },
167 "required": ["datacenter"],
168 "additionalProperties": False
169 }
170
171
172 datacenter_edit_schema = {
173 "title":"datacenter edit nformation schema",
174 "$schema": "http://json-schema.org/draft-04/schema#",
175 "type":"object",
176 "properties":{
177 "datacenter":{
178 "type":"object",
179 "properties":datacenter_schema_properties,
180 "additionalProperties": False
181 }
182 },
183 "required": ["datacenter"],
184 "additionalProperties": False
185 }
186
187
188 netmap_new_schema = {
189 "title":"netmap new information schema",
190 "$schema": "http://json-schema.org/draft-04/schema#",
191 "type":"object",
192 "properties":{
193 "netmap":{ #delete from datacenter
194 "type":"object",
195 "properties":{
196 "name": name_schema, #name or uuid of net to change
197 "vim_id": id_schema,
198 "vim_name": name_schema
199 },
200 "minProperties": 1,
201 "additionalProperties": False
202 },
203 },
204 "required": ["netmap"],
205 "additionalProperties": False
206 }
207
208 netmap_edit_schema = {
209 "title":"netmap edit information schema",
210 "$schema": "http://json-schema.org/draft-04/schema#",
211 "type":"object",
212 "properties":{
213 "netmap":{ #delete from datacenter
214 "type":"object",
215 "properties":{
216 "name": name_schema, #name or uuid of net to change
217 },
218 "minProperties": 1,
219 "additionalProperties": False
220 },
221 },
222 "required": ["netmap"],
223 "additionalProperties": False
224 }
225
226 datacenter_action_schema = {
227 "title":"datacenter action information schema",
228 "$schema": "http://json-schema.org/draft-04/schema#",
229 "type":"object",
230 "properties":{
231 "net-update":{"type":"null",},
232 "net-edit":{
233 "type":"object",
234 "properties":{
235 "net": name_schema, #name or uuid of net to change
236 "name": name_schema,
237 "description": description_schema,
238 "shared": {"type": "boolean"}
239 },
240 "minProperties": 1,
241 "additionalProperties": False
242 },
243 "net-delete":{
244 "type":"object",
245 "properties":{
246 "net": name_schema, #name or uuid of net to change
247 },
248 "required": ["net"],
249 "additionalProperties": False
250 },
251 },
252 "minProperties": 1,
253 "maxProperties": 1,
254 "additionalProperties": False
255 }
256
257
258 datacenter_associate_schema={
259 "title":"datacenter associate information schema",
260 "$schema": "http://json-schema.org/draft-04/schema#",
261 "type":"object",
262 "properties":{
263 "datacenter":{
264 "type":"object",
265 "properties":{
266 "vim_tenant": id_schema,
267 "vim_tenant_name": nameshort_schema,
268 "vim_username": nameshort_schema,
269 "vim_password": nameshort_schema,
270 },
271 # "required": ["vim_tenant"],
272 "additionalProperties": True
273 }
274 },
275 "required": ["datacenter"],
276 "additionalProperties": False
277 }
278
279 internal_connection_element_schema = {
280 "type":"object",
281 "properties":{
282 "VNFC": name_schema,
283 "local_iface_name": name_schema
284 }
285 }
286
287 internal_connection_schema = {
288 "type":"object",
289 "properties":{
290 "name": name_schema,
291 "description":description_schema,
292 "type":{"type":"string", "enum":["bridge","data","ptp"]},
293 "elements": {"type" : "array", "items": internal_connection_element_schema, "minItems":2}
294 },
295 "required": ["name", "type", "elements"],
296 "additionalProperties": False
297 }
298
299 external_connection_schema = {
300 "type":"object",
301 "properties":{
302 "name": name_schema,
303 "type":{"type":"string", "enum":["mgmt","bridge","data"]},
304 "VNFC": name_schema,
305 "local_iface_name": name_schema ,
306 "description":description_schema
307 },
308 "required": ["name", "type", "VNFC", "local_iface_name"],
309 "additionalProperties": False
310 }
311
312 interfaces_schema={
313 "type":"array",
314 "items":{
315 "type":"object",
316 "properties":{
317 "name":name_schema,
318 "dedicated":{"type":"string","enum":["yes","no","yes:sriov"]},
319 "bandwidth":bandwidth_schema,
320 "vpci":pci_schema,
321 "mac_address": mac_schema
322 },
323 "additionalProperties": False,
324 "required": ["name","dedicated", "bandwidth"]
325 }
326 }
327
328 bridge_interfaces_schema={
329 "type":"array",
330 "items":{
331 "type":"object",
332 "properties":{
333 "name": name_schema,
334 "bandwidth":bandwidth_schema,
335 "vpci":pci_schema,
336 "mac_address": mac_schema,
337 "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]}
338 },
339 "additionalProperties": False,
340 "required": ["name"]
341 }
342 }
343
344 devices_schema={
345 "type":"array",
346 "items":{
347 "type":"object",
348 "properties":{
349 "type":{"type":"string", "enum":["disk","cdrom","xml"] },
350 "image": path_schema,
351 "image metadata": metadata_schema,
352 "vpci":pci_schema,
353 "xml":xml_text_schema,
354 },
355 "additionalProperties": False,
356 "required": ["type"]
357 }
358 }
359
360
361 numa_schema = {
362 "type": "object",
363 "properties": {
364 "memory":integer1_schema,
365 "cores":integer1_schema,
366 "paired-threads":integer1_schema,
367 "threads":integer1_schema,
368 "cores-id":{"type":"array","items":integer0_schema},
369 "paired-threads-id":{"type":"array","items":{"type":"array","minItems":2,"maxItems":2,"items":integer0_schema}},
370 "threads-id":{"type":"array","items":integer0_schema},
371 "interfaces":interfaces_schema
372 },
373 "additionalProperties": False,
374 #"required": ["memory"]
375 }
376
377 vnfc_schema = {
378 "type":"object",
379 "properties":{
380 "name": name_schema,
381 "description": description_schema,
382 "VNFC image": {"oneOf": [path_schema, http_schema]},
383 "image metadata": metadata_schema,
384 "processor": {
385 "type":"object",
386 "properties":{
387 "model":description_schema,
388 "features":{"type":"array","items":nameshort_schema}
389 },
390 "required": ["model"],
391 "additionalProperties": False
392 },
393 "hypervisor": {
394 "type":"object",
395 "properties":{
396 "type":nameshort_schema,
397 "version":description_schema
398 },
399 },
400 "ram":integer0_schema,
401 "vcpus":integer0_schema,
402 "disk": integer1_schema,
403 "numas": {
404 "type": "array",
405 "items":numa_schema
406 },
407 "bridge-ifaces": bridge_interfaces_schema,
408 "devices": devices_schema
409 },
410 "required": ["name", "VNFC image"],
411 "additionalProperties": False
412 }
413
414 vnfd_schema_v01 = {
415 "title":"vnfd information schema v0.1",
416 "$schema": "http://json-schema.org/draft-04/schema#",
417 "type":"object",
418 "properties":{
419 "vnf":{
420 "type":"object",
421 "properties":{
422 "name": name_schema,
423 "description": description_schema,
424 "class": nameshort_schema,
425 "public": {"type" : "boolean"},
426 "physical": {"type" : "boolean"},
427 "tenant_id": id_schema, #only valid for admin
428 "external-connections": {"type" : "array", "items": external_connection_schema, "minItems":1},
429 "internal-connections": {"type" : "array", "items": internal_connection_schema, "minItems":1},
430 "VNFC":{"type" : "array", "items": vnfc_schema, "minItems":1}
431 },
432 "required": ["name","external-connections"],
433 "additionalProperties": True
434 }
435 },
436 "required": ["vnf"],
437 "additionalProperties": False
438 }
439
440 #Future VNFD schema to be defined
441 vnfd_schema_v02 = {
442 "title":"vnfd information schema v0.2",
443 "$schema": "http://json-schema.org/draft-04/schema#",
444 "type":"object",
445 "properties":{
446 "schema_version": schema_version_2,
447 "vnf":{
448 "type":"object",
449 "properties":{
450 "name": name_schema,
451 },
452 "required": ["name"],
453 "additionalProperties": True
454 }
455 },
456 "required": ["vnf", "schema_version"],
457 "additionalProperties": False
458 }
459
460 #vnfd_schema = vnfd_schema_v01
461 #{
462 # "title":"vnfd information schema v0.2",
463 # "$schema": "http://json-schema.org/draft-04/schema#",
464 # "oneOf": [vnfd_schema_v01, vnfd_schema_v02]
465 #}
466
467 graph_schema = {
468 "title":"graphical scenario descriptor information schema",
469 "$schema": "http://json-schema.org/draft-04/schema#",
470 "type":"object",
471 "properties":{
472 "x": integer0_schema,
473 "y": integer0_schema,
474 "ifaces": {
475 "type":"object",
476 "properties":{
477 "left": {"type":"array"},
478 "right": {"type":"array"},
479 "bottom": {"type":"array"},
480 }
481 }
482 },
483 "required": ["x","y"]
484 }
485
486 nsd_schema_v01 = {
487 "title":"network scenario descriptor information schema v0.1",
488 "$schema": "http://json-schema.org/draft-04/schema#",
489 "type":"object",
490 "properties":{
491 "name":name_schema,
492 "description": description_schema,
493 "tenant_id": id_schema, #only valid for admin
494 "public": {"type": "boolean"},
495 "topology":{
496 "type":"object",
497 "properties":{
498 "nodes": {
499 "type":"object",
500 "patternProperties":{
501 ".": {
502 "type": "object",
503 "properties":{
504 "type":{"type":"string", "enum":["VNF", "other_network", "network", "external_network"]},
505 "vnf_id": id_schema,
506 "graph": graph_schema,
507 },
508 "patternProperties":{
509 "^(VNF )?model$": {"type": "string"}
510 },
511 "required": ["type"]
512 }
513 }
514 },
515 "connections": {
516 "type":"object",
517 "patternProperties":{
518 ".": {
519 "type": "object",
520 "properties":{
521 "nodes":{"oneOf":[{"type":"object", "minProperties":2}, {"type":"array", "minLength":1}]},
522 "type": {"type": "string", "enum":["link", "external_network", "dataplane_net", "bridge_net"]},
523 "graph": graph_schema
524 },
525 "required": ["nodes"]
526 },
527 }
528 }
529 },
530 "required": ["nodes"],
531 "additionalProperties": False
532 }
533 },
534 "required": ["name","topology"],
535 "additionalProperties": False
536 }
537
538 #Future NSD schema to be defined
539 nsd_schema_v02 = {
540 "title":"network scenario descriptor information schema v0.2",
541 "$schema": "http://json-schema.org/draft-04/schema#",
542 "type":"object",
543 "properties":{
544 "schema_version": schema_version_2,
545 "scenario":{
546 "type":"object",
547 "properties":{
548 "name":name_schema,
549 "description": description_schema,
550 "tenant_id": id_schema, #only valid for admin
551 "public": {"type": "boolean"},
552 "vnfs": {
553 "type":"object",
554 "patternProperties":{
555 ".": {
556 "type": "object",
557 "properties":{
558 "vnf_id": id_schema,
559 "graph": graph_schema,
560 "vnf_name": name_schema,
561 },
562 }
563 },
564 "minProperties": 1
565 },
566 "networks": {
567 "type":"object",
568 "patternProperties":{
569 ".": {
570 "type": "object",
571 "properties":{
572 "interfaces":{"type":"array", "minLength":1},
573 "type": {"type": "string", "enum":["dataplane", "bridge"]},
574 "external" : {"type": "boolean"},
575 "graph": graph_schema
576 },
577 "required": ["interfaces"]
578 },
579 }
580 },
581
582 },
583 "required": ["vnfs", "networks","name"],
584 "additionalProperties": False
585 }
586 },
587 "required": ["scenario","schema_version"],
588 "additionalProperties": False
589 }
590
591 #scenario_new_schema = {
592 # "title":"new scenario information schema",
593 # "$schema": "http://json-schema.org/draft-04/schema#",
594 # #"oneOf": [nsd_schema_v01, nsd_schema_v02]
595 # "oneOf": [nsd_schema_v01]
596 #}
597
598 scenario_edit_schema = {
599 "title":"edit scenario information schema",
600 "$schema": "http://json-schema.org/draft-04/schema#",
601 "type":"object",
602 "properties":{
603 "name":name_schema,
604 "description": description_schema,
605 "topology":{
606 "type":"object",
607 "properties":{
608 "nodes": {
609 "type":"object",
610 "patternProperties":{
611 "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$": {
612 "type":"object",
613 "properties":{
614 "graph":{
615 "type": "object",
616 "properties":{
617 "x": integer0_schema,
618 "y": integer0_schema,
619 "ifaces":{ "type": "object"}
620 }
621 },
622 "description": description_schema,
623 "name": name_schema
624 }
625 }
626 }
627 }
628 },
629 "required": ["nodes"],
630 "additionalProperties": False
631 }
632 },
633 "additionalProperties": False
634 }
635
636 scenario_action_schema = {
637 "title":"scenario action information schema",
638 "$schema": "http://json-schema.org/draft-04/schema#",
639 "type":"object",
640 "properties":{
641 "start":{
642 "type": "object",
643 "properties": {
644 "instance_name":name_schema,
645 "description":description_schema,
646 "datacenter": {"type": "string"}
647 },
648 "required": ["instance_name"]
649 },
650 "deploy":{
651 "type": "object",
652 "properties": {
653 "instance_name":name_schema,
654 "description":description_schema,
655 "datacenter": {"type": "string"}
656 },
657 "required": ["instance_name"]
658 },
659 "reserve":{
660 "type": "object",
661 "properties": {
662 "instance_name":name_schema,
663 "description":description_schema,
664 "datacenter": {"type": "string"}
665 },
666 "required": ["instance_name"]
667 },
668 "verify":{
669 "type": "object",
670 "properties": {
671 "instance_name":name_schema,
672 "description":description_schema,
673 "datacenter": {"type": "string"}
674 },
675 "required": ["instance_name"]
676 }
677 },
678 "minProperties": 1,
679 "maxProperties": 1,
680 "additionalProperties": False
681 }
682
683 instance_scenario_create_schema = {
684 "title":"instance scenario create information schema v0.1",
685 "$schema": "http://json-schema.org/draft-04/schema#",
686 "type":"object",
687 "properties":{
688 "schema_version": {"type": "string", "enum": ["0.1"]},
689 "instance":{
690 "type":"object",
691 "properties":{
692 "name":name_schema,
693 "description":description_schema,
694 "datacenter": name_schema,
695 "scenario" : name_schema, #can be an UUID or name
696 "action":{"enum": ["deploy","reserve","verify" ]},
697 "connect_mgmt_interfaces": {"oneOff": [{"type":"boolean"}, {"type":"object"}]},# can be true or a dict with datacenter: net_name
698 "vnfs":{ #mapping from scenario to datacenter
699 "type": "object",
700 "patternProperties":{
701 ".": {
702 "type": "object",
703 "properties":{
704 "name": name_schema,#override vnf name
705 "datacenter": name_schema,
706 "metadata": {"type": "object"},
707 "user_data": {"type": "string"}
708 }
709 }
710 },
711 },
712 "networks":{ #mapping from scenario to datacenter
713 "type": "object",
714 "patternProperties":{
715 ".": {
716 "type": "object",
717 "properties":{
718 "netmap-create": {"oneOf":[name_schema,{"type": "null"}]}, #datacenter network to use. Null if must be created as an internal net
719 "netmap-use": name_schema,
720 "name": name_schema,#override network name
721 "datacenter": name_schema,
722 }
723 }
724 },
725 },
726 },
727 "additionalProperties": False,
728 "required": ["scenario", "name"]
729 },
730 },
731 "required": ["instance"],
732 "additionalProperties": False
733
734 }
735
736 instance_scenario_action_schema = {
737 "title":"instance scenario action information schema",
738 "$schema": "http://json-schema.org/draft-04/schema#",
739 "type":"object",
740 "properties":{
741 "start":{"type": "null"},
742 "pause":{"type": "null"},
743 "resume":{"type": "null"},
744 "shutoff":{"type": "null"},
745 "shutdown":{"type": "null"},
746 "forceOff":{"type": "null"},
747 "rebuild":{"type": "null"},
748 "reboot":{
749 "type": ["object","null"],
750 },
751 "console": {"type": ["string", "null"], "enum": ["novnc", "xvpvnc", "rdp-html5", "spice-html5", None]},
752 "vnfs":{"type": "array", "items":{"type":"string"}},
753 "vms":{"type": "array", "items":{"type":"string"}}
754 },
755 "minProperties": 1,
756 #"maxProperties": 1,
757 "additionalProperties": False
758 }