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