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