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