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