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