blob: 2eb703448d17f27db5fe63cc7194a78e2d0f6e84 [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 = "^[ -~]+$"
tiernocd54a4a2018-09-12 16:40:35 +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}"}
tierno0f98af52018-03-19 10:28:22 +010027pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\.[0-9a-fA-F]$"}
28http_schema = {"type": "string", "pattern": "^https?://[^'\"=]+$"}
29bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
30memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
31integer0_schema = {"type": "integer", "minimum": 0}
32integer1_schema = {"type": "integer", "minimum": 1}
33path_schema = {"type": "string", "pattern": "^(\.){0,2}(/[^/\"':{}\(\)]+)+$"}
34vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
35vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
36mac_schema = {"type": "string",
37 "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 +020038dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
tierno0f98af52018-03-19 10:28:22 +010039# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
40ip_schema = {"type": "string",
41 "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]?)$"}
42ip_prefix_schema = {"type": "string",
tierno2236d202018-05-16 19:05:16 +020043 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}"
44 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
tierno0f98af52018-03-19 10:28:22 +010045port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
46object_schema = {"type": "object"}
47schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
48# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
49log_level_schema = {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
50checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
51size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +020052array_edition_schema = {
53 "type": "object",
54 "patternProperties": {
55 "^\$": "Any"
56 },
57 "additionalProperties": False,
58 "minProperties": 1,
59}
tiernocb83c942018-09-24 17:28:13 +020060nameshort_list_schema = {
61 "type": "array",
62 "minItems": 1,
63 "items": nameshort_schema,
64}
tiernocd54a4a2018-09-12 16:40:35 +020065
tierno0f98af52018-03-19 10:28:22 +010066
tierno441dbbf2018-07-10 12:52:48 +020067ns_instantiate_vdu = {
68 "title": "ns action instantiate input schema for vdu",
69 "$schema": "http://json-schema.org/draft-04/schema#",
70 "type": "object",
71 "properties": {
72 "id": name_schema,
73 "volume": {
74 "type": "array",
75 "minItems": 1,
76 "items": {
77 "type": "object",
78 "properties": {
79 "name": name_schema,
80 "vim-volume-id": name_schema,
81 },
82 "required": ["name", "vim-volume-id"],
83 "additionalProperties": False
84 }
85 },
86 "interface": {
87 "type": "array",
88 "minItems": 1,
89 "items": {
90 "type": "object",
91 "properties": {
92 "name": name_schema,
93 "ip-address": ip_schema,
94 "mac-address": mac_schema,
95 "floating-ip-required": bool_schema,
96 },
97 "required": ["name"],
98 "additionalProperties": False
99 }
100 }
101 },
102 "required": ["id"],
103 "additionalProperties": False
104}
105
106ip_profile_dns_schema = {
107 "type": "array",
108 "minItems": 1,
109 "items": {
110 "type": "object",
111 "properties": {
112 "address": ip_schema,
113 },
114 "required": ["address"],
115 "additionalProperties": False
116 }
117}
118
119ip_profile_dhcp_schema = {
120 "type": "object",
121 "properties": {
122 "enabled": {"type": "boolean"},
123 "count": integer1_schema,
124 "start-address": ip_schema
125 },
126 "additionalProperties": False,
127}
128
129ip_profile_schema = {
130 "title": "ip profile validation schame",
131 "$schema": "http://json-schema.org/draft-04/schema#",
132 "type": "object",
133 "properties": {
134 "ip-version": {"enum": ["ipv4", "ipv6"]},
135 "subnet-address": ip_prefix_schema,
136 "gateway-address": ip_schema,
137 "dns-server": ip_profile_dns_schema,
138 "dhcp-params": ip_profile_dhcp_schema,
139 }
140}
141
142ip_profile_update_schema = {
143 "title": "ip profile validation schame",
144 "$schema": "http://json-schema.org/draft-04/schema#",
145 "type": "object",
146 "properties": {
147 "ip-version": {"enum": ["ipv4", "ipv6"]},
148 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
149 "gateway-address": {"oneOf": [null_schema, ip_schema]},
150 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
151
152 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
153 },
154 "additionalProperties": False
155}
156
157ns_instantiate_internal_vld = {
158 "title": "ns action instantiate input schema for vdu",
159 "$schema": "http://json-schema.org/draft-04/schema#",
160 "type": "object",
161 "properties": {
162 "name": name_schema,
163 "vim-network-name": name_schema,
164 "ip-profile": ip_profile_update_schema,
165 "internal-connection-point": {
166 "type": "array",
167 "minItems": 1,
168 "items": {
169 "type": "object",
170 "properties": {
171 "id-ref": name_schema,
172 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200173 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200174 },
tiernob7c6f2a2018-09-03 14:32:10 +0200175 "required": ["id-ref"],
176 "minProperties": 2,
tierno441dbbf2018-07-10 12:52:48 +0200177 "additionalProperties": False
178 },
179 }
180 },
181 "required": ["name"],
182 "minProperties": 2,
183 "additionalProperties": False
184}
tierno65acb4d2018-04-06 16:42:40 +0200185
186ns_instantiate = {
187 "title": "ns action instantiate input schema",
188 "$schema": "http://json-schema.org/draft-04/schema#",
189 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200190 "properties": {
191 "nsName": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200192 "nsDescription": {"oneOf": [description_schema, {"type": "null"}]},
tierno0da52252018-06-27 15:47:22 +0200193 "nsdId": id_schema,
194 "vimAccountId": id_schema,
195 "ssh_keys": {"type": "string"},
tierno441dbbf2018-07-10 12:52:48 +0200196 "nsr_id": id_schema,
tierno0da52252018-06-27 15:47:22 +0200197 "vnf": {
198 "type": "array",
199 "minItems": 1,
200 "items": {
201 "type": "object",
202 "properties": {
203 "member-vnf-index": name_schema,
204 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200205 "vdu": {
206 "type": "array",
207 "minItems": 1,
208 "items": ns_instantiate_vdu,
209 },
210 "internal-vld": {
211 "type": "array",
212 "minItems": 1,
213 "items": ns_instantiate_internal_vld
214 }
tierno0da52252018-06-27 15:47:22 +0200215 },
tierno441dbbf2018-07-10 12:52:48 +0200216 "required": ["member-vnf-index"],
217 "minProperties": 2,
218 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200219 }
220 },
221 "vld": {
222 "type": "array",
223 "minItems": 1,
224 "items": {
225 "type": "object",
226 "properties": {
227 "name": string_schema,
228 "vim-network-name": {"OneOf": [string_schema, object_schema]},
229 "ip-profile": object_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200230 "vnfd-connection-point-ref": {
231 "type": "array",
232 "minItems": 1,
233 "items": {
234 "type": "object",
235 "properties": {
236 "member-vnf-index-ref": name_schema,
237 "vnfd-connection-point-ref": name_schema,
238 "ip-address": ip_schema,
239 # "mac-address": mac_schema,
240 },
241 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
242 "minProperties": 3,
243 "additionalProperties": False
244 },
245 }
tierno0da52252018-06-27 15:47:22 +0200246 },
tierno441dbbf2018-07-10 12:52:48 +0200247 "required": ["name"],
248 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200249 }
250 },
251 },
tierno441dbbf2018-07-10 12:52:48 +0200252 "required": ["nsName", "nsdId", "vimAccountId"],
253 "additionalProperties": False
tierno65acb4d2018-04-06 16:42:40 +0200254}
tierno0da52252018-06-27 15:47:22 +0200255
tierno65acb4d2018-04-06 16:42:40 +0200256ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200257 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200258 "$schema": "http://json-schema.org/draft-04/schema#",
259 "type": "object",
260 "properties": {
tiernof5298be2018-05-16 14:43:57 +0200261 "member_vnf_index": name_schema,
262 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200263 "vdu_id": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200264 "primitive": name_schema,
265 "primitive_params": {"type": "object"},
266 },
tiernof5298be2018-05-16 14:43:57 +0200267 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
tierno65acb4d2018-04-06 16:42:40 +0200268 "additionalProperties": False
269}
tiernof759d822018-06-11 18:54:54 +0200270ns_scale = { # TODO for the moment it is only VDU-scaling
271 "title": "ns scale input schema",
272 "$schema": "http://json-schema.org/draft-04/schema#",
273 "type": "object",
274 "properties": {
275 "scaleType": {"enum": ["SCALE_VNF"]},
276 "scaleVnfData": {
277 "type": "object",
278 "properties": {
279 "vnfInstanceId": name_schema,
280 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
281 "scaleByStepData": {
282 "type": "object",
283 "properties": {
284 "scaling-group-descriptor": name_schema,
285 "member-vnf-index": name_schema,
286 "scaling-policy": name_schema,
287 },
288 "required": ["scaling-group-descriptor", "member-vnf-index"],
289 "additionalProperties": False
290 },
291 },
292 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
293 "additionalProperties": False
294 },
295 "scaleTime": time_schema,
296 },
297 "required": ["scaleType", "scaleVnfData"],
298 "additionalProperties": False
299}
tierno65acb4d2018-04-06 16:42:40 +0200300
301
tierno0f98af52018-03-19 10:28:22 +0100302schema_version = {"type": "string", "enum": ["1.0"]}
tierno09c073e2018-04-26 13:36:48 +0200303vim_account_edit_schema = {
304 "title": "vim_account edit input schema",
305 "$schema": "http://json-schema.org/draft-04/schema#",
306 "type": "object",
307 "properties": {
308 "name": name_schema,
309 "description": description_schema,
310 "type": nameshort_schema, # currently "openvim" or "openstack", can be enlarged with plugins
311 "vim": name_schema,
312 "datacenter": name_schema,
313 "vim_url": description_schema,
314 "vim_url_admin": description_schema,
315 "vim_tenant": name_schema,
316 "vim_tenant_name": name_schema,
317 "vim_username": nameshort_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200318 "vim_password": passwd_schema,
tierno09c073e2018-04-26 13:36:48 +0200319 "config": {"type": "object"}
320 },
321 "additionalProperties": False
322}
tierno0f98af52018-03-19 10:28:22 +0100323schema_type = {"type": "string"}
324
tierno09c073e2018-04-26 13:36:48 +0200325vim_account_new_schema = {
326 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100327 "$schema": "http://json-schema.org/draft-04/schema#",
328 "type": "object",
329 "properties": {
330 "schema_version": schema_version,
331 "schema_type": schema_type,
332 "name": name_schema,
333 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200334 "vim": name_schema,
335 "datacenter": name_schema,
tierno0f98af52018-03-19 10:28:22 +0100336 "vim_type": {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws"]},
337 "vim_url": description_schema,
338 # "vim_url_admin": description_schema,
339 # "vim_tenant": name_schema,
340 "vim_tenant_name": name_schema,
341 "vim_user": nameshort_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200342 "vim_password": passwd_schema,
tierno0f98af52018-03-19 10:28:22 +0100343 "config": {"type": "object"}
344 },
345 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
346 "additionalProperties": False
347}
tierno0f98af52018-03-19 10:28:22 +0100348
349
350sdn_properties = {
351 "name": name_schema,
tiernocfb07c62018-05-10 18:30:51 +0200352 "description": description_schema,
tiernocb83c942018-09-24 17:28:13 +0200353 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100354 "ip": ip_schema,
355 "port": port_schema,
356 "type": {"type": "string", "enum": ["opendaylight", "floodlight", "onos"]},
357 "version": {"type": "string", "minLength": 1, "maxLength": 12},
358 "user": nameshort_schema,
359 "password": passwd_schema
360}
361sdn_new_schema = {
362 "title": "sdn controller information schema",
363 "$schema": "http://json-schema.org/draft-04/schema#",
364 "type": "object",
365 "properties": sdn_properties,
366 "required": ["name", "port", 'ip', 'dpid', 'type'],
367 "additionalProperties": False
368}
369sdn_edit_schema = {
370 "title": "sdn controller update information schema",
371 "$schema": "http://json-schema.org/draft-04/schema#",
372 "type": "object",
373 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200374 # "required": ["name", "port", 'ip', 'dpid', 'type'],
tierno0f98af52018-03-19 10:28:22 +0100375 "additionalProperties": False
376}
377sdn_port_mapping_schema = {
378 "$schema": "http://json-schema.org/draft-04/schema#",
379 "title": "sdn port mapping information schema",
380 "type": "array",
381 "items": {
382 "type": "object",
383 "properties": {
384 "compute_node": nameshort_schema,
385 "ports": {
386 "type": "array",
387 "items": {
388 "type": "object",
389 "properties": {
390 "pci": pci_schema,
391 "switch_port": nameshort_schema,
392 "switch_mac": mac_schema
393 },
394 "required": ["pci"]
395 }
396 }
397 },
398 "required": ["compute_node", "ports"]
399 }
400}
401sdn_external_port_schema = {
402 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200403 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100404 "type": "object",
405 "properties": {
406 "port": {"type": "string", "minLength": 1, "maxLength": 60},
407 "vlan": vlan_schema,
408 "mac": mac_schema
409 },
410 "required": ["port"]
411}
412
tiernocb83c942018-09-24 17:28:13 +0200413# PDUs
414pdu_interface = {
415 "type": "object",
416 "properties": {
417 "name": nameshort_schema,
418 "mgmt": bool_schema,
419 "type": {"enum": ["overlay", 'underlay']},
420 "ip_address": ip_schema,
421 # TODO, add user, password, ssh-key
422 "mac_address": mac_schema,
423 "vim_network_name": nameshort_schema, # interface is connected to one vim network, or switch port
424 "vim_network_id": nameshort_schema,
425 # provide this in case SDN assist must deal with this interface
426 "switch_dpid": dpid_Schema,
427 "switch_port": nameshort_schema,
428 "switch_mac": nameshort_schema,
429 "switch_vlan": vlan_schema,
430 },
431 "required": ["name", "mgmt", "ip_address"],
432 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200433}
tiernocb83c942018-09-24 17:28:13 +0200434pdu_new_schema = {
435 "title": "pdu creation input schema",
436 "$schema": "http://json-schema.org/draft-04/schema#",
437 "type": "object",
438 "properties": {
439 "name": nameshort_schema,
440 "type": nameshort_schema,
441 "description": description_schema,
442 "shared": bool_schema,
443 "vims": nameshort_list_schema,
444 "vim_accounts": nameshort_list_schema,
445 "interfaces": {
446 "type": "array",
447 "items": {"type": pdu_interface},
448 "minItems": 1
449 }
450 },
451 "required": ["name", "type", "interfaces"],
452 "additionalProperties": False
453}
454
455pdu_edit_schema = {
456 "title": "pdu edit input schema",
457 "$schema": "http://json-schema.org/draft-04/schema#",
458 "type": "object",
459 "properties": {
460 "name": nameshort_schema,
461 "type": nameshort_schema,
462 "description": description_schema,
463 "shared": bool_schema,
464 "vims": {"oneOff": [array_edition_schema, nameshort_list_schema]},
465 "vim_accounts": {"oneOff": [array_edition_schema, nameshort_list_schema]},
466 "interfaces": {"oneOff": [
467 array_edition_schema,
468 {
469 "type": "array",
470 "items": {"type": pdu_interface},
471 "minItems": 1
472 }
473 ]}
474 },
475 "additionalProperties": False,
476 "minProperties": 1
477}
478
479# USERS
tiernocd54a4a2018-09-12 16:40:35 +0200480user_new_schema = {
481 "$schema": "http://json-schema.org/draft-04/schema#",
482 "title": "New user schema",
483 "type": "object",
484 "properties": {
485 "username": nameshort_schema,
486 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200487 "projects": nameshort_list_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200488 },
489 "required": ["username", "password", "projects"],
490 "additionalProperties": False
491}
492user_edit_schema = {
493 "$schema": "http://json-schema.org/draft-04/schema#",
494 "title": "User edit schema for administrators",
495 "type": "object",
496 "properties": {
497 "password": passwd_schema,
498 "projects": {
499 "oneOff": [
tiernocb83c942018-09-24 17:28:13 +0200500 nameshort_list_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200501 array_edition_schema
502 ]
503 },
tiernocb83c942018-09-24 17:28:13 +0200504 },
505 "minProperties": 1,
506 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200507}
508
509# PROJECTS
510project_new_schema = {
511 "$schema": "http://json-schema.org/draft-04/schema#",
512 "title": "New project schema for administrators",
513 "type": "object",
514 "properties": {
515 "name": nameshort_schema,
516 "admin": bool_schema,
517 },
518 "required": ["name"],
519 "additionalProperties": False
520}
521project_edit_schema = {
522 "$schema": "http://json-schema.org/draft-04/schema#",
523 "title": "Project edit schema for administrators",
524 "type": "object",
525 "properties": {
526 "admin": bool_schema,
527 },
528 "additionalProperties": False,
529 "minProperties": 1
530}
531
532# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +0100533
534nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200535 "users": user_new_schema,
536 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +0200537 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +0200538 "sdns": sdn_new_schema,
539 "ns_instantiate": ns_instantiate,
540 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +0200541 "ns_scale": ns_scale,
542 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +0100543}
544
545nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200546 "users": user_edit_schema,
547 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +0200548 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +0200549 "sdns": sdn_edit_schema,
550 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +0100551}
552
553
554class ValidationError(Exception):
555 pass
556
557
558def validate_input(indata, item, new=True):
559 """
tiernocd54a4a2018-09-12 16:40:35 +0200560 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +0100561 :param indata: user input data. Should be a dictionary
tierno65acb4d2018-04-06 16:42:40 +0200562 :param item: can be users, projects, vims, sdns, ns_xxxxx
tierno0f98af52018-03-19 10:28:22 +0100563 :param new: True if the validation is for creating or False if it is for editing
564 :return: None if ok, raises ValidationError exception otherwise
565 """
566 try:
567 if new:
568 schema_to_use = nbi_new_input_schemas.get(item)
569 else:
570 schema_to_use = nbi_edit_input_schemas.get(item)
571 if schema_to_use:
572 js_v(indata, schema_to_use)
573 return None
574 except js_e.ValidationError as e:
575 if e.path:
tierno0da52252018-06-27 15:47:22 +0200576 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +0100577 else:
578 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +0200579 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))