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