blob: da3dd04a361a0de06ea8b89d174ee4b438821abb [file] [log] [blame]
tierno0f98af52018-03-19 10:28:22 +01001# -*- coding: utf-8 -*-
2
3from jsonschema import validate as js_v, exceptions as js_e
4
5__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
6__version__ = "0.1"
7version_date = "Mar 2018"
8
9"""
10Validator of input data using JSON schemas for those items that not contains an OSM yang information model
11"""
12
13# Basis schemas
14patern_name = "^[ -~]+$"
tierno87006042018-10-24 12:50:20 +020015nameshort_schema = {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()\\.\\$'\"]+$"}
tierno0f98af52018-03-19 10:28:22 +010016passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
tierno0f98af52018-03-19 10:28:22 +010017name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
tierno0da52252018-06-27 15:47:22 +020018string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
tierno0f98af52018-03-19 10:28:22 +010019xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
20description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
tierno441dbbf2018-07-10 12:52:48 +020021id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
22bool_schema = {"type": "boolean"}
23null_schema = {"type": "null"}
tierno2236d202018-05-16 19:05:16 +020024# "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}$"
tierno0f98af52018-03-19 10:28:22 +010025id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
tiernof759d822018-06-11 18:54:54 +020026time_schema = {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"}
tierno87006042018-10-24 12:50:20 +020027pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"}
tierno42fce592018-11-02 09:23:43 +010028# allows [] for wildcards. For that reason huge length limit is set
29pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
tierno0f98af52018-03-19 10:28:22 +010030http_schema = {"type": "string", "pattern": "^https?://[^'\"=]+$"}
31bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
32memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
33integer0_schema = {"type": "integer", "minimum": 0}
34integer1_schema = {"type": "integer", "minimum": 1}
tierno87006042018-10-24 12:50:20 +020035path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
tierno0f98af52018-03-19 10:28:22 +010036vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
37vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
38mac_schema = {"type": "string",
39 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0
tiernocb83c942018-09-24 17:28:13 +020040dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
tierno0f98af52018-03-19 10:28:22 +010041# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
42ip_schema = {"type": "string",
tierno87006042018-10-24 12:50:20 +020043 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"}
tierno0f98af52018-03-19 10:28:22 +010044ip_prefix_schema = {"type": "string",
tierno87006042018-10-24 12:50:20 +020045 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
tierno2236d202018-05-16 19:05:16 +020046 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
tierno0f98af52018-03-19 10:28:22 +010047port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
48object_schema = {"type": "object"}
49schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
50# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
51log_level_schema = {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
52checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
53size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +020054array_edition_schema = {
55 "type": "object",
56 "patternProperties": {
tierno87006042018-10-24 12:50:20 +020057 "^\\$": "Any"
tiernocd54a4a2018-09-12 16:40:35 +020058 },
59 "additionalProperties": False,
60 "minProperties": 1,
61}
tiernocb83c942018-09-24 17:28:13 +020062nameshort_list_schema = {
63 "type": "array",
64 "minItems": 1,
65 "items": nameshort_schema,
66}
tiernocd54a4a2018-09-12 16:40:35 +020067
tierno0f98af52018-03-19 10:28:22 +010068
tierno441dbbf2018-07-10 12:52:48 +020069ns_instantiate_vdu = {
70 "title": "ns action instantiate input schema for vdu",
71 "$schema": "http://json-schema.org/draft-04/schema#",
72 "type": "object",
73 "properties": {
74 "id": name_schema,
75 "volume": {
76 "type": "array",
77 "minItems": 1,
78 "items": {
79 "type": "object",
80 "properties": {
81 "name": name_schema,
82 "vim-volume-id": name_schema,
83 },
84 "required": ["name", "vim-volume-id"],
85 "additionalProperties": False
86 }
87 },
88 "interface": {
89 "type": "array",
90 "minItems": 1,
91 "items": {
92 "type": "object",
93 "properties": {
94 "name": name_schema,
95 "ip-address": ip_schema,
96 "mac-address": mac_schema,
97 "floating-ip-required": bool_schema,
98 },
99 "required": ["name"],
100 "additionalProperties": False
101 }
102 }
103 },
104 "required": ["id"],
105 "additionalProperties": False
106}
107
108ip_profile_dns_schema = {
109 "type": "array",
110 "minItems": 1,
111 "items": {
112 "type": "object",
113 "properties": {
114 "address": ip_schema,
115 },
116 "required": ["address"],
117 "additionalProperties": False
118 }
119}
120
121ip_profile_dhcp_schema = {
122 "type": "object",
123 "properties": {
124 "enabled": {"type": "boolean"},
125 "count": integer1_schema,
126 "start-address": ip_schema
127 },
128 "additionalProperties": False,
129}
130
131ip_profile_schema = {
132 "title": "ip profile validation schame",
133 "$schema": "http://json-schema.org/draft-04/schema#",
134 "type": "object",
135 "properties": {
136 "ip-version": {"enum": ["ipv4", "ipv6"]},
137 "subnet-address": ip_prefix_schema,
138 "gateway-address": ip_schema,
139 "dns-server": ip_profile_dns_schema,
140 "dhcp-params": ip_profile_dhcp_schema,
141 }
142}
143
144ip_profile_update_schema = {
145 "title": "ip profile validation schame",
146 "$schema": "http://json-schema.org/draft-04/schema#",
147 "type": "object",
148 "properties": {
149 "ip-version": {"enum": ["ipv4", "ipv6"]},
150 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
151 "gateway-address": {"oneOf": [null_schema, ip_schema]},
152 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
153
154 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
155 },
156 "additionalProperties": False
157}
158
159ns_instantiate_internal_vld = {
160 "title": "ns action instantiate input schema for vdu",
161 "$schema": "http://json-schema.org/draft-04/schema#",
162 "type": "object",
163 "properties": {
164 "name": name_schema,
165 "vim-network-name": name_schema,
166 "ip-profile": ip_profile_update_schema,
167 "internal-connection-point": {
168 "type": "array",
169 "minItems": 1,
170 "items": {
171 "type": "object",
172 "properties": {
173 "id-ref": name_schema,
174 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200175 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200176 },
tiernob7c6f2a2018-09-03 14:32:10 +0200177 "required": ["id-ref"],
178 "minProperties": 2,
tierno441dbbf2018-07-10 12:52:48 +0200179 "additionalProperties": False
180 },
181 }
182 },
183 "required": ["name"],
184 "minProperties": 2,
185 "additionalProperties": False
186}
tierno65acb4d2018-04-06 16:42:40 +0200187
188ns_instantiate = {
189 "title": "ns action instantiate input schema",
190 "$schema": "http://json-schema.org/draft-04/schema#",
191 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200192 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200193 "lcmOperationType": string_schema,
194 "nsInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200195 "nsName": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200196 "nsDescription": {"oneOf": [description_schema, {"type": "null"}]},
tierno0da52252018-06-27 15:47:22 +0200197 "nsdId": id_schema,
198 "vimAccountId": id_schema,
tiernofc5089c2018-10-31 09:28:11 +0100199 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tierno441dbbf2018-07-10 12:52:48 +0200200 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200201 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200202 "vnf": {
203 "type": "array",
204 "minItems": 1,
205 "items": {
206 "type": "object",
207 "properties": {
208 "member-vnf-index": name_schema,
209 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200210 "vdu": {
211 "type": "array",
212 "minItems": 1,
213 "items": ns_instantiate_vdu,
214 },
215 "internal-vld": {
216 "type": "array",
217 "minItems": 1,
218 "items": ns_instantiate_internal_vld
219 }
tierno0da52252018-06-27 15:47:22 +0200220 },
tierno441dbbf2018-07-10 12:52:48 +0200221 "required": ["member-vnf-index"],
222 "minProperties": 2,
223 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200224 }
225 },
226 "vld": {
227 "type": "array",
228 "minItems": 1,
229 "items": {
230 "type": "object",
231 "properties": {
232 "name": string_schema,
233 "vim-network-name": {"OneOf": [string_schema, object_schema]},
234 "ip-profile": object_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200235 "vnfd-connection-point-ref": {
236 "type": "array",
237 "minItems": 1,
238 "items": {
239 "type": "object",
240 "properties": {
241 "member-vnf-index-ref": name_schema,
242 "vnfd-connection-point-ref": name_schema,
243 "ip-address": ip_schema,
244 # "mac-address": mac_schema,
245 },
246 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
247 "minProperties": 3,
248 "additionalProperties": False
249 },
250 }
tierno0da52252018-06-27 15:47:22 +0200251 },
tierno441dbbf2018-07-10 12:52:48 +0200252 "required": ["name"],
253 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200254 }
255 },
256 },
tierno441dbbf2018-07-10 12:52:48 +0200257 "required": ["nsName", "nsdId", "vimAccountId"],
258 "additionalProperties": False
tierno65acb4d2018-04-06 16:42:40 +0200259}
tierno0da52252018-06-27 15:47:22 +0200260
tierno65acb4d2018-04-06 16:42:40 +0200261ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200262 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200263 "$schema": "http://json-schema.org/draft-04/schema#",
264 "type": "object",
265 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200266 "lcmOperationType": string_schema,
267 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200268 "member_vnf_index": name_schema,
269 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200270 "vdu_id": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200271 "primitive": name_schema,
272 "primitive_params": {"type": "object"},
273 },
tiernof5298be2018-05-16 14:43:57 +0200274 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
tierno65acb4d2018-04-06 16:42:40 +0200275 "additionalProperties": False
276}
tiernof759d822018-06-11 18:54:54 +0200277ns_scale = { # TODO for the moment it is only VDU-scaling
278 "title": "ns scale input schema",
279 "$schema": "http://json-schema.org/draft-04/schema#",
280 "type": "object",
281 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200282 "lcmOperationType": string_schema,
283 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200284 "scaleType": {"enum": ["SCALE_VNF"]},
285 "scaleVnfData": {
286 "type": "object",
287 "properties": {
288 "vnfInstanceId": name_schema,
289 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
290 "scaleByStepData": {
291 "type": "object",
292 "properties": {
293 "scaling-group-descriptor": name_schema,
294 "member-vnf-index": name_schema,
295 "scaling-policy": name_schema,
296 },
297 "required": ["scaling-group-descriptor", "member-vnf-index"],
298 "additionalProperties": False
299 },
300 },
301 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
302 "additionalProperties": False
303 },
304 "scaleTime": time_schema,
305 },
306 "required": ["scaleType", "scaleVnfData"],
307 "additionalProperties": False
308}
tierno65acb4d2018-04-06 16:42:40 +0200309
310
tierno0f98af52018-03-19 10:28:22 +0100311schema_version = {"type": "string", "enum": ["1.0"]}
tierno09c073e2018-04-26 13:36:48 +0200312vim_account_edit_schema = {
313 "title": "vim_account edit input schema",
314 "$schema": "http://json-schema.org/draft-04/schema#",
315 "type": "object",
316 "properties": {
317 "name": name_schema,
318 "description": description_schema,
319 "type": nameshort_schema, # currently "openvim" or "openstack", can be enlarged with plugins
320 "vim": name_schema,
321 "datacenter": name_schema,
322 "vim_url": description_schema,
323 "vim_url_admin": description_schema,
324 "vim_tenant": name_schema,
325 "vim_tenant_name": name_schema,
326 "vim_username": nameshort_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200327 "vim_password": passwd_schema,
tierno09c073e2018-04-26 13:36:48 +0200328 "config": {"type": "object"}
329 },
330 "additionalProperties": False
331}
tierno0f98af52018-03-19 10:28:22 +0100332schema_type = {"type": "string"}
333
tierno09c073e2018-04-26 13:36:48 +0200334vim_account_new_schema = {
335 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100336 "$schema": "http://json-schema.org/draft-04/schema#",
337 "type": "object",
338 "properties": {
339 "schema_version": schema_version,
340 "schema_type": schema_type,
341 "name": name_schema,
342 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200343 "vim": name_schema,
344 "datacenter": name_schema,
tierno0f98af52018-03-19 10:28:22 +0100345 "vim_type": {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws"]},
346 "vim_url": description_schema,
347 # "vim_url_admin": description_schema,
348 # "vim_tenant": name_schema,
349 "vim_tenant_name": name_schema,
350 "vim_user": nameshort_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200351 "vim_password": passwd_schema,
tierno0f98af52018-03-19 10:28:22 +0100352 "config": {"type": "object"}
353 },
354 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
355 "additionalProperties": False
356}
tierno0f98af52018-03-19 10:28:22 +0100357
358
359sdn_properties = {
360 "name": name_schema,
tiernocfb07c62018-05-10 18:30:51 +0200361 "description": description_schema,
tiernocb83c942018-09-24 17:28:13 +0200362 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100363 "ip": ip_schema,
364 "port": port_schema,
365 "type": {"type": "string", "enum": ["opendaylight", "floodlight", "onos"]},
366 "version": {"type": "string", "minLength": 1, "maxLength": 12},
367 "user": nameshort_schema,
368 "password": passwd_schema
369}
370sdn_new_schema = {
371 "title": "sdn controller information schema",
372 "$schema": "http://json-schema.org/draft-04/schema#",
373 "type": "object",
374 "properties": sdn_properties,
375 "required": ["name", "port", 'ip', 'dpid', 'type'],
376 "additionalProperties": False
377}
378sdn_edit_schema = {
379 "title": "sdn controller update information schema",
380 "$schema": "http://json-schema.org/draft-04/schema#",
381 "type": "object",
382 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200383 # "required": ["name", "port", 'ip', 'dpid', 'type'],
tierno0f98af52018-03-19 10:28:22 +0100384 "additionalProperties": False
385}
386sdn_port_mapping_schema = {
387 "$schema": "http://json-schema.org/draft-04/schema#",
388 "title": "sdn port mapping information schema",
389 "type": "array",
390 "items": {
391 "type": "object",
392 "properties": {
393 "compute_node": nameshort_schema,
394 "ports": {
395 "type": "array",
396 "items": {
397 "type": "object",
398 "properties": {
tierno42fce592018-11-02 09:23:43 +0100399 "pci": pci_extended_schema,
tierno0f98af52018-03-19 10:28:22 +0100400 "switch_port": nameshort_schema,
401 "switch_mac": mac_schema
402 },
403 "required": ["pci"]
404 }
405 }
406 },
407 "required": ["compute_node", "ports"]
408 }
409}
410sdn_external_port_schema = {
411 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200412 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100413 "type": "object",
414 "properties": {
415 "port": {"type": "string", "minLength": 1, "maxLength": 60},
416 "vlan": vlan_schema,
417 "mac": mac_schema
418 },
419 "required": ["port"]
420}
421
tiernocb83c942018-09-24 17:28:13 +0200422# PDUs
423pdu_interface = {
424 "type": "object",
425 "properties": {
426 "name": nameshort_schema,
427 "mgmt": bool_schema,
428 "type": {"enum": ["overlay", 'underlay']},
429 "ip_address": ip_schema,
430 # TODO, add user, password, ssh-key
431 "mac_address": mac_schema,
432 "vim_network_name": nameshort_schema, # interface is connected to one vim network, or switch port
433 "vim_network_id": nameshort_schema,
434 # provide this in case SDN assist must deal with this interface
435 "switch_dpid": dpid_Schema,
436 "switch_port": nameshort_schema,
437 "switch_mac": nameshort_schema,
438 "switch_vlan": vlan_schema,
439 },
440 "required": ["name", "mgmt", "ip_address"],
441 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200442}
tiernocb83c942018-09-24 17:28:13 +0200443pdu_new_schema = {
444 "title": "pdu creation input schema",
445 "$schema": "http://json-schema.org/draft-04/schema#",
446 "type": "object",
447 "properties": {
448 "name": nameshort_schema,
449 "type": nameshort_schema,
450 "description": description_schema,
451 "shared": bool_schema,
452 "vims": nameshort_list_schema,
453 "vim_accounts": nameshort_list_schema,
454 "interfaces": {
455 "type": "array",
456 "items": {"type": pdu_interface},
457 "minItems": 1
458 }
459 },
460 "required": ["name", "type", "interfaces"],
461 "additionalProperties": False
462}
463
464pdu_edit_schema = {
465 "title": "pdu edit input schema",
466 "$schema": "http://json-schema.org/draft-04/schema#",
467 "type": "object",
468 "properties": {
469 "name": nameshort_schema,
470 "type": nameshort_schema,
471 "description": description_schema,
472 "shared": bool_schema,
473 "vims": {"oneOff": [array_edition_schema, nameshort_list_schema]},
474 "vim_accounts": {"oneOff": [array_edition_schema, nameshort_list_schema]},
475 "interfaces": {"oneOff": [
476 array_edition_schema,
477 {
478 "type": "array",
479 "items": {"type": pdu_interface},
480 "minItems": 1
481 }
482 ]}
483 },
484 "additionalProperties": False,
485 "minProperties": 1
486}
487
488# USERS
tiernocd54a4a2018-09-12 16:40:35 +0200489user_new_schema = {
490 "$schema": "http://json-schema.org/draft-04/schema#",
491 "title": "New user schema",
492 "type": "object",
493 "properties": {
494 "username": nameshort_schema,
495 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200496 "projects": nameshort_list_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200497 },
498 "required": ["username", "password", "projects"],
499 "additionalProperties": False
500}
501user_edit_schema = {
502 "$schema": "http://json-schema.org/draft-04/schema#",
503 "title": "User edit schema for administrators",
504 "type": "object",
505 "properties": {
506 "password": passwd_schema,
507 "projects": {
508 "oneOff": [
tiernocb83c942018-09-24 17:28:13 +0200509 nameshort_list_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200510 array_edition_schema
511 ]
512 },
tiernocb83c942018-09-24 17:28:13 +0200513 },
514 "minProperties": 1,
515 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200516}
517
518# PROJECTS
519project_new_schema = {
520 "$schema": "http://json-schema.org/draft-04/schema#",
521 "title": "New project schema for administrators",
522 "type": "object",
523 "properties": {
524 "name": nameshort_schema,
525 "admin": bool_schema,
526 },
527 "required": ["name"],
528 "additionalProperties": False
529}
530project_edit_schema = {
531 "$schema": "http://json-schema.org/draft-04/schema#",
532 "title": "Project edit schema for administrators",
533 "type": "object",
534 "properties": {
535 "admin": bool_schema,
536 },
537 "additionalProperties": False,
538 "minProperties": 1
539}
540
541# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +0100542
543nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200544 "users": user_new_schema,
545 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +0200546 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +0200547 "sdns": sdn_new_schema,
548 "ns_instantiate": ns_instantiate,
549 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +0200550 "ns_scale": ns_scale,
551 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +0100552}
553
554nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200555 "users": user_edit_schema,
556 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +0200557 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +0200558 "sdns": sdn_edit_schema,
559 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +0100560}
561
562
563class ValidationError(Exception):
564 pass
565
566
tiernob24258a2018-10-04 18:39:49 +0200567def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +0100568 """
tiernocd54a4a2018-09-12 16:40:35 +0200569 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +0100570 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +0200571 :param schema_to_use: jsonschema to test
572 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +0100573 """
574 try:
tierno0f98af52018-03-19 10:28:22 +0100575 if schema_to_use:
576 js_v(indata, schema_to_use)
577 return None
578 except js_e.ValidationError as e:
579 if e.path:
tierno0da52252018-06-27 15:47:22 +0200580 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +0100581 else:
582 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +0200583 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))