1 # -*- coding: utf-8 -*-
4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openmano
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
25 JSON schemas used by openmano httpserver.py module to parse the different files and messages sent through the API
27 __author__
="Alfonso Tierno, Gerardo Garcia"
28 __date__
="$09-oct-2014 09:09:48$"
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"]}
59 "architecture": {"type":"string"},
60 "use_incremental": {"type":"string","enum":["yes","no"]},
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"]}
70 #Schema for the configuration file
72 "title":"configuration response information schema",
73 "$schema": "http://json-schema.org/draft-04/schema#",
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": {
95 {"type":"object", "properties":{"from": port_schema
, "to": port_schema
}, "required": ["from","to"]}
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
,
107 "required": ['db_host', 'db_user', 'db_passwd', 'db_name'],
108 "additionalProperties": False
112 "title":"tenant information schema",
113 "$schema": "http://json-schema.org/draft-04/schema#",
119 "name": nameshort_schema
,
120 "description": description_schema
,
122 "required": ["name"],
123 "additionalProperties": True
126 "required": ["tenant"],
127 "additionalProperties": False
129 tenant_edit_schema
= {
130 "title":"tenant edit information schema",
131 "$schema": "http://json-schema.org/draft-04/schema#",
138 "description": description_schema
,
140 "additionalProperties": False
143 "required": ["tenant"],
144 "additionalProperties": False
147 datacenter_schema_properties
={
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" }
156 datacenter_schema
= {
157 "title":"datacenter information schema",
158 "$schema": "http://json-schema.org/draft-04/schema#",
163 "properties":datacenter_schema_properties
,
164 "required": ["name", "vim_url"],
165 "additionalProperties": True
168 "required": ["datacenter"],
169 "additionalProperties": False
173 datacenter_edit_schema
= {
174 "title":"datacenter edit nformation schema",
175 "$schema": "http://json-schema.org/draft-04/schema#",
180 "properties":datacenter_schema_properties
,
181 "additionalProperties": False
184 "required": ["datacenter"],
185 "additionalProperties": False
189 netmap_new_schema
= {
190 "title":"netmap new information schema",
191 "$schema": "http://json-schema.org/draft-04/schema#",
194 "netmap":{ #delete from datacenter
197 "name": name_schema
, #name or uuid of net to change
199 "vim_name": name_schema
202 "additionalProperties": False
205 "required": ["netmap"],
206 "additionalProperties": False
209 netmap_edit_schema
= {
210 "title":"netmap edit information schema",
211 "$schema": "http://json-schema.org/draft-04/schema#",
214 "netmap":{ #delete from datacenter
217 "name": name_schema
, #name or uuid of net to change
220 "additionalProperties": False
223 "required": ["netmap"],
224 "additionalProperties": False
227 datacenter_action_schema
= {
228 "title":"datacenter action information schema",
229 "$schema": "http://json-schema.org/draft-04/schema#",
232 "net-update":{"type":"null",},
236 "net": name_schema
, #name or uuid of net to change
238 "description": description_schema
,
239 "shared": {"type": "boolean"}
242 "additionalProperties": False
247 "net": name_schema
, #name or uuid of net to change
250 "additionalProperties": False
255 "additionalProperties": False
259 datacenter_associate_schema
={
260 "title":"datacenter associate information schema",
261 "$schema": "http://json-schema.org/draft-04/schema#",
267 "vim_tenant": id_schema
,
268 "vim_tenant_name": nameshort_schema
,
269 "vim_username": nameshort_schema
,
270 "vim_password": nameshort_schema
,
272 # "required": ["vim_tenant"],
273 "additionalProperties": True
276 "required": ["datacenter"],
277 "additionalProperties": False
280 internal_connection_element_schema
= {
284 "local_iface_name": name_schema
288 internal_connection_schema
= {
292 "description":description_schema
,
293 "type":{"type":"string", "enum":["bridge","data","ptp"]},
294 "elements": {"type" : "array", "items": internal_connection_element_schema
, "minItems":2}
296 "required": ["name", "type", "elements"],
297 "additionalProperties": False
300 external_connection_schema
= {
304 "type":{"type":"string", "enum":["mgmt","bridge","data"]},
306 "local_iface_name": name_schema
,
307 "description":description_schema
309 "required": ["name", "type", "VNFC", "local_iface_name"],
310 "additionalProperties": False
319 "dedicated":{"type":"string","enum":["yes","no","yes:sriov"]},
320 "bandwidth":bandwidth_schema
,
322 "mac_address": mac_schema
324 "additionalProperties": False,
325 "required": ["name","dedicated", "bandwidth"]
329 bridge_interfaces_schema
={
335 "bandwidth":bandwidth_schema
,
337 "mac_address": mac_schema
,
338 "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]}
340 "additionalProperties": False,
350 "type":{"type":"string", "enum":["disk","cdrom","xml"] },
351 "image": path_schema
,
352 "image metadata": metadata_schema
,
354 "xml":xml_text_schema
,
356 "additionalProperties": False,
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
374 "additionalProperties": False,
375 #"required": ["memory"]
382 "description": description_schema
,
383 "VNFC image": {"oneOf": [path_schema
, http_schema
]},
384 "image metadata": metadata_schema
,
388 "model":description_schema
,
389 "features":{"type":"array","items":nameshort_schema
}
391 "required": ["model"],
392 "additionalProperties": False
397 "type":nameshort_schema
,
398 "version":description_schema
401 "ram":integer0_schema
,
402 "vcpus":integer0_schema
,
403 "disk": integer1_schema
,
408 "bridge-ifaces": bridge_interfaces_schema
,
409 "devices": devices_schema
411 "required": ["name", "VNFC image"],
412 "additionalProperties": False
416 "title":"vnfd information schema v0.1",
417 "$schema": "http://json-schema.org/draft-04/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}
433 "required": ["name","external-connections"],
434 "additionalProperties": True
438 "additionalProperties": False
441 #Future VNFD schema to be defined
443 "title":"vnfd information schema v0.2",
444 "$schema": "http://json-schema.org/draft-04/schema#",
447 "schema_version": schema_version_2
,
453 "required": ["name"],
454 "additionalProperties": True
457 "required": ["vnf", "schema_version"],
458 "additionalProperties": False
461 #vnfd_schema = vnfd_schema_v01
463 # "title":"vnfd information schema v0.2",
464 # "$schema": "http://json-schema.org/draft-04/schema#",
465 # "oneOf": [vnfd_schema_v01, vnfd_schema_v02]
469 "title":"graphical scenario descriptor information schema",
470 "$schema": "http://json-schema.org/draft-04/schema#",
473 "x": integer0_schema
,
474 "y": integer0_schema
,
478 "left": {"type":"array"},
479 "right": {"type":"array"},
480 "bottom": {"type":"array"},
484 "required": ["x","y"]
488 "title":"network scenario descriptor information schema v0.1",
489 "$schema": "http://json-schema.org/draft-04/schema#",
493 "description": description_schema
,
494 "tenant_id": id_schema
, #only valid for admin
495 "public": {"type": "boolean"},
501 "patternProperties":{
505 "type":{"type":"string", "enum":["VNF", "other_network", "network", "external_network"]},
507 "graph": graph_schema
,
509 "patternProperties":{
510 "^(VNF )?model$": {"type": "string"}
518 "patternProperties":{
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
526 "required": ["nodes"]
531 "required": ["nodes"],
532 "additionalProperties": False
535 "required": ["name","topology"],
536 "additionalProperties": False
539 #Future NSD schema to be defined
541 "title":"network scenario descriptor information schema v0.2",
542 "$schema": "http://json-schema.org/draft-04/schema#",
545 "schema_version": schema_version_2
,
550 "description": description_schema
,
551 "tenant_id": id_schema
, #only valid for admin
552 "public": {"type": "boolean"},
555 "patternProperties":{
560 "graph": graph_schema
,
561 "vnf_name": name_schema
,
569 "patternProperties":{
573 "interfaces":{"type":"array", "minLength":1},
574 "type": {"type": "string", "enum":["dataplane", "bridge"]},
575 "external" : {"type": "boolean"},
576 "graph": graph_schema
578 "required": ["interfaces"]
584 "required": ["vnfs", "networks","name"],
585 "additionalProperties": False
588 "required": ["scenario","schema_version"],
589 "additionalProperties": False
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]
599 scenario_edit_schema
= {
600 "title":"edit scenario information schema",
601 "$schema": "http://json-schema.org/draft-04/schema#",
605 "description": description_schema
,
611 "patternProperties":{
612 "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$": {
618 "x": integer0_schema
,
619 "y": integer0_schema
,
620 "ifaces":{ "type": "object"}
623 "description": description_schema
,
630 "required": ["nodes"],
631 "additionalProperties": False
634 "additionalProperties": False
637 scenario_action_schema
= {
638 "title":"scenario action information schema",
639 "$schema": "http://json-schema.org/draft-04/schema#",
645 "instance_name":name_schema
,
646 "description":description_schema
,
647 "datacenter": {"type": "string"}
649 "required": ["instance_name"]
654 "instance_name":name_schema
,
655 "description":description_schema
,
656 "datacenter": {"type": "string"}
658 "required": ["instance_name"]
663 "instance_name":name_schema
,
664 "description":description_schema
,
665 "datacenter": {"type": "string"}
667 "required": ["instance_name"]
672 "instance_name":name_schema
,
673 "description":description_schema
,
674 "datacenter": {"type": "string"}
676 "required": ["instance_name"]
681 "additionalProperties": False
684 instance_scenario_create_schema
= {
685 "title":"instance scenario create information schema v0.1",
686 "$schema": "http://json-schema.org/draft-04/schema#",
689 "schema_version": {"type": "string", "enum": ["0.1"]},
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
701 "patternProperties":{
705 "name": name_schema
,#override vnf name
706 "datacenter": name_schema
,
707 "metadata": {"type": "object"},
708 "user_data": {"type": "string"}
713 "networks":{ #mapping from scenario to datacenter
715 "patternProperties":{
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
,
728 "additionalProperties": False,
729 "required": ["scenario", "name"]
732 "required": ["instance"],
733 "additionalProperties": False
737 instance_scenario_action_schema
= {
738 "title":"instance scenario action information schema",
739 "$schema": "http://json-schema.org/draft-04/schema#",
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"},
750 "type": ["object","null"],
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"}}
758 "additionalProperties": False