bug 636 validation vim_account-create config. Deny null values
[osm/NBI.git] / osm_nbi / validation.py
1 # -*- coding: utf-8 -*-
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from jsonschema import validate as js_v, exceptions as js_e
17 from http import HTTPStatus
18 from copy import deepcopy
19
20 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
21 __version__ = "0.1"
22 version_date = "Mar 2018"
23
24 """
25 Validator of input data using JSON schemas for those items that not contains an OSM yang information model
26 """
27
28 # Basis schemas
29 patern_name = "^[ -~]+$"
30 shortname_schema = {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()\\.\\$'\"]+$"}
31 passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
32 name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
33 string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
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}
37 bool_schema = {"type": "boolean"}
38 null_schema = {"type": "null"}
39 # "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}$"
40 id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
41 time_schema = {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"}
42 pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"}
43 # allows [] for wildcards. For that reason huge length limit is set
44 pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
45 http_schema = {"type": "string", "pattern": "^https?://[^'\"=]+$"}
46 bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
47 memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
48 integer0_schema = {"type": "integer", "minimum": 0}
49 integer1_schema = {"type": "integer", "minimum": 1}
50 path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
51 vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
52 vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
53 mac_schema = {"type": "string",
54 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0
55 dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
56 # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
57 ip_schema = {"type": "string",
58 "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]?)$"}
59 ip_prefix_schema = {"type": "string",
60 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
61 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
62 port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
63 object_schema = {"type": "object"}
64 schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
65 # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
66 log_level_schema = {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
67 checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
68 size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
69 array_edition_schema = {
70 "type": "object",
71 "patternProperties": {
72 "^\\$": {}
73 },
74 "additionalProperties": False,
75 "minProperties": 1,
76 }
77 nameshort_list_schema = {
78 "type": "array",
79 "minItems": 1,
80 "items": shortname_schema,
81 }
82
83
84 ns_instantiate_vdu = {
85 "title": "ns action instantiate input schema for vdu",
86 "$schema": "http://json-schema.org/draft-04/schema#",
87 "type": "object",
88 "properties": {
89 "id": name_schema,
90 "volume": {
91 "type": "array",
92 "minItems": 1,
93 "items": {
94 "type": "object",
95 "properties": {
96 "name": name_schema,
97 "vim-volume-id": name_schema,
98 },
99 "required": ["name", "vim-volume-id"],
100 "additionalProperties": False
101 }
102 },
103 "interface": {
104 "type": "array",
105 "minItems": 1,
106 "items": {
107 "type": "object",
108 "properties": {
109 "name": name_schema,
110 "ip-address": ip_schema,
111 "mac-address": mac_schema,
112 "floating-ip-required": bool_schema,
113 },
114 "required": ["name"],
115 "additionalProperties": False
116 }
117 }
118 },
119 "required": ["id"],
120 "additionalProperties": False
121 }
122
123 ip_profile_dns_schema = {
124 "type": "array",
125 "minItems": 1,
126 "items": {
127 "type": "object",
128 "properties": {
129 "address": ip_schema,
130 },
131 "required": ["address"],
132 "additionalProperties": False
133 }
134 }
135
136 ip_profile_dhcp_schema = {
137 "type": "object",
138 "properties": {
139 "enabled": {"type": "boolean"},
140 "count": integer1_schema,
141 "start-address": ip_schema
142 },
143 "additionalProperties": False,
144 }
145
146 ip_profile_schema = {
147 "title": "ip profile validation schame",
148 "$schema": "http://json-schema.org/draft-04/schema#",
149 "type": "object",
150 "properties": {
151 "ip-version": {"enum": ["ipv4", "ipv6"]},
152 "subnet-address": ip_prefix_schema,
153 "gateway-address": ip_schema,
154 "dns-server": ip_profile_dns_schema,
155 "dhcp-params": ip_profile_dhcp_schema,
156 }
157 }
158
159 ip_profile_update_schema = {
160 "title": "ip profile validation schame",
161 "$schema": "http://json-schema.org/draft-04/schema#",
162 "type": "object",
163 "properties": {
164 "ip-version": {"enum": ["ipv4", "ipv6"]},
165 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
166 "gateway-address": {"oneOf": [null_schema, ip_schema]},
167 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
168
169 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
170 },
171 "additionalProperties": False
172 }
173
174 ns_instantiate_internal_vld = {
175 "title": "ns action instantiate input schema for vdu",
176 "$schema": "http://json-schema.org/draft-04/schema#",
177 "type": "object",
178 "properties": {
179 "name": name_schema,
180 "vim-network-name": name_schema,
181 "vim-network-id": name_schema,
182 "ip-profile": ip_profile_update_schema,
183 "internal-connection-point": {
184 "type": "array",
185 "minItems": 1,
186 "items": {
187 "type": "object",
188 "properties": {
189 "id-ref": name_schema,
190 "ip-address": ip_schema,
191 # "mac-address": mac_schema,
192 },
193 "required": ["id-ref"],
194 "minProperties": 2,
195 "additionalProperties": False
196 },
197 }
198 },
199 "required": ["name"],
200 "minProperties": 2,
201 "additionalProperties": False
202 }
203
204 additional_params_for_vnf = {
205 "type": "array",
206 "items": {
207 "type": "object",
208 "properties": {
209 "member-vnf-index": name_schema,
210 "additionalParams": object_schema,
211 },
212 "required": ["member-vnf-index", "additionalParams"],
213 "additionalProperties": False
214 }
215
216 }
217
218 ns_instantiate = {
219 "title": "ns action instantiate input schema",
220 "$schema": "http://json-schema.org/draft-04/schema#",
221 "type": "object",
222 "properties": {
223 "lcmOperationType": string_schema,
224 "nsInstanceId": id_schema,
225 "netsliceInstanceId": id_schema,
226 "nsName": name_schema,
227 "nsDescription": {"oneOf": [description_schema, {"type": "null"}]},
228 "nsdId": id_schema,
229 "vimAccountId": id_schema,
230 "additionalParamsForNs": object_schema,
231 "additionalParamsForVnf": additional_params_for_vnf,
232 "ssh_keys": {"type": "array", "items": {"type": "string"}},
233 "nsr_id": id_schema,
234 "vduImage": name_schema,
235 "vnf": {
236 "type": "array",
237 "minItems": 1,
238 "items": {
239 "type": "object",
240 "properties": {
241 "member-vnf-index": name_schema,
242 "vimAccountId": id_schema,
243 "vdu": {
244 "type": "array",
245 "minItems": 1,
246 "items": ns_instantiate_vdu,
247 },
248 "internal-vld": {
249 "type": "array",
250 "minItems": 1,
251 "items": ns_instantiate_internal_vld
252 }
253 },
254 "required": ["member-vnf-index"],
255 "minProperties": 2,
256 "additionalProperties": False
257 }
258 },
259 "vld": {
260 "type": "array",
261 "minItems": 1,
262 "items": {
263 "type": "object",
264 "properties": {
265 "name": string_schema,
266 "vim-network-name": {"OneOf": [string_schema, object_schema]},
267 "vim-network-id": {"OneOf": [string_schema, object_schema]},
268 "ip-profile": object_schema,
269 "vnfd-connection-point-ref": {
270 "type": "array",
271 "minItems": 1,
272 "items": {
273 "type": "object",
274 "properties": {
275 "member-vnf-index-ref": name_schema,
276 "vnfd-connection-point-ref": name_schema,
277 "ip-address": ip_schema,
278 # "mac-address": mac_schema,
279 },
280 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
281 "minProperties": 3,
282 "additionalProperties": False
283 },
284 }
285 },
286 "required": ["name"],
287 "additionalProperties": False
288 }
289 },
290 },
291 "required": ["nsName", "nsdId", "vimAccountId"],
292 "additionalProperties": False
293 }
294
295 ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
296 "title": "ns action input schema",
297 "$schema": "http://json-schema.org/draft-04/schema#",
298 "type": "object",
299 "properties": {
300 "lcmOperationType": string_schema,
301 "nsInstanceId": id_schema,
302 "member_vnf_index": name_schema,
303 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
304 "vdu_id": name_schema,
305 "vdu_count_index": integer0_schema,
306 "primitive": name_schema,
307 "primitive_params": {"type": "object"},
308 },
309 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
310 "additionalProperties": False
311 }
312 ns_scale = { # TODO for the moment it is only VDU-scaling
313 "title": "ns scale input schema",
314 "$schema": "http://json-schema.org/draft-04/schema#",
315 "type": "object",
316 "properties": {
317 "lcmOperationType": string_schema,
318 "nsInstanceId": id_schema,
319 "scaleType": {"enum": ["SCALE_VNF"]},
320 "scaleVnfData": {
321 "type": "object",
322 "properties": {
323 "vnfInstanceId": name_schema,
324 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
325 "scaleByStepData": {
326 "type": "object",
327 "properties": {
328 "scaling-group-descriptor": name_schema,
329 "member-vnf-index": name_schema,
330 "scaling-policy": name_schema,
331 },
332 "required": ["scaling-group-descriptor", "member-vnf-index"],
333 "additionalProperties": False
334 },
335 },
336 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
337 "additionalProperties": False
338 },
339 "scaleTime": time_schema,
340 },
341 "required": ["scaleType", "scaleVnfData"],
342 "additionalProperties": False
343 }
344
345
346 schema_version = {"type": "string", "enum": ["1.0"]}
347 schema_type = {"type": "string"}
348 vim_account_edit_schema = {
349 "title": "vim_account edit input schema",
350 "$schema": "http://json-schema.org/draft-04/schema#",
351 "type": "object",
352 "properties": {
353 "name": name_schema,
354 "description": description_schema,
355 "type": shortname_schema,
356 "vim": name_schema,
357 "datacenter": name_schema,
358 "vim_url": description_schema,
359 "vim_url_admin": description_schema,
360 "vim_tenant": name_schema,
361 "vim_tenant_name": name_schema,
362 "vim_username": shortname_schema,
363 "vim_password": passwd_schema,
364 "config": {"type": "object"}
365 },
366 "additionalProperties": False
367 }
368
369 vim_account_new_schema = {
370 "title": "vim_account creation input schema",
371 "$schema": "http://json-schema.org/draft-04/schema#",
372 "type": "object",
373 "properties": {
374 "schema_version": schema_version,
375 "schema_type": schema_type,
376 "name": name_schema,
377 "description": description_schema,
378 "vim": name_schema,
379 "datacenter": name_schema,
380 "vim_type": {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws"]},
381 "vim_url": description_schema,
382 # "vim_url_admin": description_schema,
383 # "vim_tenant": name_schema,
384 "vim_tenant_name": name_schema,
385 "vim_user": shortname_schema,
386 "vim_password": passwd_schema,
387 "config": {"type": "object"}
388 },
389 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
390 "additionalProperties": False
391 }
392
393 wim_account_edit_schema = {
394 "title": "wim_account edit input schema",
395 "$schema": "http://json-schema.org/draft-04/schema#",
396 "type": "object",
397 "properties": {
398 "name": name_schema,
399 "description": description_schema,
400 "type": shortname_schema,
401 "wim": name_schema,
402 "wim_url": description_schema,
403 "user": shortname_schema,
404 "password": passwd_schema,
405 "config": {"type": "object"}
406 },
407 "additionalProperties": False
408 }
409
410 wim_account_new_schema = {
411 "title": "wim_account creation input schema",
412 "$schema": "http://json-schema.org/draft-04/schema#",
413 "type": "object",
414 "properties": {
415 "schema_version": schema_version,
416 "schema_type": schema_type,
417 "name": name_schema,
418 "description": description_schema,
419 "wim": name_schema,
420 "wim_type": {"enum": ["tapi", "onos", "odl", "dynpac"]},
421 "wim_url": description_schema,
422 "user": shortname_schema,
423 "password": passwd_schema,
424 "config": {
425 "type": "object",
426 "patternProperties": {
427 ".": {"not": {"type": "null"}}
428 }
429 }
430 },
431 "required": ["name", "wim_url", "wim_type"],
432 "additionalProperties": False
433 }
434
435 sdn_properties = {
436 "name": name_schema,
437 "description": description_schema,
438 "dpid": dpid_Schema,
439 "ip": ip_schema,
440 "port": port_schema,
441 "type": {"type": "string", "enum": ["opendaylight", "floodlight", "onos"]},
442 "version": {"type": "string", "minLength": 1, "maxLength": 12},
443 "user": shortname_schema,
444 "password": passwd_schema
445 }
446 sdn_new_schema = {
447 "title": "sdn controller information schema",
448 "$schema": "http://json-schema.org/draft-04/schema#",
449 "type": "object",
450 "properties": sdn_properties,
451 "required": ["name", "port", 'ip', 'dpid', 'type'],
452 "additionalProperties": False
453 }
454 sdn_edit_schema = {
455 "title": "sdn controller update information schema",
456 "$schema": "http://json-schema.org/draft-04/schema#",
457 "type": "object",
458 "properties": sdn_properties,
459 # "required": ["name", "port", 'ip', 'dpid', 'type'],
460 "additionalProperties": False
461 }
462 sdn_port_mapping_schema = {
463 "$schema": "http://json-schema.org/draft-04/schema#",
464 "title": "sdn port mapping information schema",
465 "type": "array",
466 "items": {
467 "type": "object",
468 "properties": {
469 "compute_node": shortname_schema,
470 "ports": {
471 "type": "array",
472 "items": {
473 "type": "object",
474 "properties": {
475 "pci": pci_extended_schema,
476 "switch_port": shortname_schema,
477 "switch_mac": mac_schema
478 },
479 "required": ["pci"]
480 }
481 }
482 },
483 "required": ["compute_node", "ports"]
484 }
485 }
486 sdn_external_port_schema = {
487 "$schema": "http://json-schema.org/draft-04/schema#",
488 "title": "External port information",
489 "type": "object",
490 "properties": {
491 "port": {"type": "string", "minLength": 1, "maxLength": 60},
492 "vlan": vlan_schema,
493 "mac": mac_schema
494 },
495 "required": ["port"]
496 }
497
498 # PDUs
499 pdu_interface = {
500 "type": "object",
501 "properties": {
502 "name": shortname_schema,
503 "mgmt": bool_schema,
504 "type": {"enum": ["overlay", 'underlay']},
505 "ip-address": ip_schema,
506 # TODO, add user, password, ssh-key
507 "mac-address": mac_schema,
508 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
509 "vim-network-id": shortname_schema,
510 # # provide this in case SDN assist must deal with this interface
511 # "switch-dpid": dpid_Schema,
512 # "switch-port": shortname_schema,
513 # "switch-mac": shortname_schema,
514 # "switch-vlan": vlan_schema,
515 },
516 "required": ["name", "mgmt", "ip-address"],
517 "additionalProperties": False
518 }
519 pdu_new_schema = {
520 "title": "pdu creation input schema",
521 "$schema": "http://json-schema.org/draft-04/schema#",
522 "type": "object",
523 "properties": {
524 "name": shortname_schema,
525 "type": shortname_schema,
526 "description": description_schema,
527 "shared": bool_schema,
528 "vims": nameshort_list_schema,
529 "vim_accounts": nameshort_list_schema,
530 "interfaces": {
531 "type": "array",
532 "items": pdu_interface,
533 "minItems": 1
534 }
535 },
536 "required": ["name", "type", "interfaces"],
537 "additionalProperties": False
538 }
539
540 pdu_edit_schema = {
541 "title": "pdu edit input schema",
542 "$schema": "http://json-schema.org/draft-04/schema#",
543 "type": "object",
544 "properties": {
545 "name": shortname_schema,
546 "type": shortname_schema,
547 "description": description_schema,
548 "shared": bool_schema,
549 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
550 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
551 "interfaces": {"oneOf": [
552 array_edition_schema,
553 {
554 "type": "array",
555 "items": pdu_interface,
556 "minItems": 1
557 }
558 ]}
559 },
560 "additionalProperties": False,
561 "minProperties": 1
562 }
563
564 # USERS
565 user_new_schema = {
566 "$schema": "http://json-schema.org/draft-04/schema#",
567 "title": "New user schema",
568 "type": "object",
569 "properties": {
570 "username": shortname_schema,
571 "password": passwd_schema,
572 "projects": nameshort_list_schema,
573 },
574 "required": ["username", "password", "projects"],
575 "additionalProperties": False
576 }
577 user_edit_schema = {
578 "$schema": "http://json-schema.org/draft-04/schema#",
579 "title": "User edit schema for administrators",
580 "type": "object",
581 "properties": {
582 "password": passwd_schema,
583 "projects": {
584 "oneOf": [
585 nameshort_list_schema,
586 array_edition_schema
587 ]
588 },
589 },
590 "minProperties": 1,
591 "additionalProperties": False
592 }
593
594 # PROJECTS
595 project_new_schema = {
596 "$schema": "http://json-schema.org/draft-04/schema#",
597 "title": "New project schema for administrators",
598 "type": "object",
599 "properties": {
600 "name": shortname_schema,
601 "admin": bool_schema,
602 },
603 "required": ["name"],
604 "additionalProperties": False
605 }
606 project_edit_schema = {
607 "$schema": "http://json-schema.org/draft-04/schema#",
608 "title": "Project edit schema for administrators",
609 "type": "object",
610 "properties": {
611 "admin": bool_schema,
612 },
613 "additionalProperties": False,
614 "minProperties": 1
615 }
616
617 # GLOBAL SCHEMAS
618
619 nbi_new_input_schemas = {
620 "users": user_new_schema,
621 "projects": project_new_schema,
622 "vim_accounts": vim_account_new_schema,
623 "sdns": sdn_new_schema,
624 "ns_instantiate": ns_instantiate,
625 "ns_action": ns_action,
626 "ns_scale": ns_scale,
627 "pdus": pdu_new_schema,
628 }
629
630 nbi_edit_input_schemas = {
631 "users": user_edit_schema,
632 "projects": project_edit_schema,
633 "vim_accounts": vim_account_edit_schema,
634 "sdns": sdn_edit_schema,
635 "pdus": pdu_edit_schema,
636 }
637
638 # NETSLICE SCHEMAS
639 nsi_slice_instantiate = deepcopy(ns_instantiate)
640 nsi_slice_instantiate["title"] = "netslice subnet instantiation params input schema"
641 nsi_slice_instantiate["properties"]["id"] = name_schema
642 nsi_slice_instantiate["properties"]["additionalParamsForNsi"] = object_schema
643 nsi_slice_instantiate["properties"]["additionalParamsForSubnet"] = {
644 "type": "array",
645 "items": {
646 "type": "object",
647 "properties": {
648 "id": name_schema,
649 "additionalParamsForNs": object_schema,
650 "additionalParamsForVnf": additional_params_for_vnf
651 },
652 "required": ["id"],
653 "additionalProperties": False
654 }
655 }
656 del nsi_slice_instantiate["required"]
657 del nsi_slice_instantiate["properties"]["additionalParamsForNs"]
658 del nsi_slice_instantiate["properties"]["additionalParamsForVnf"]
659
660 nsi_vld_instantiate = {
661 "title": "netslice vld instantiation params input schema",
662 "$schema": "http://json-schema.org/draft-04/schema#",
663 "type": "object",
664 "properties": {
665 "name": string_schema,
666 "vim-network-name": {"OneOf": [string_schema, object_schema]},
667 "vim-network-id": {"OneOf": [string_schema, object_schema]},
668 "ip-profile": object_schema,
669 },
670 "required": ["name"],
671 "additionalProperties": False
672 }
673
674 nsi_instantiate = {
675 "title": "netslice action instantiate input schema",
676 "$schema": "http://json-schema.org/draft-04/schema#",
677 "type": "object",
678 "properties": {
679 "lcmOperationType": string_schema,
680 "nsiInstanceId": id_schema,
681 "nsiName": name_schema,
682 "nsiDescription": {"oneOf": [description_schema, {"type": "null"}]},
683 "nstId": string_schema,
684 "vimAccountId": id_schema,
685 "ssh_keys": {"type": "string"},
686 "nsi_id": id_schema,
687 "netslice-subnet": {
688 "type": "array",
689 "minItems": 1,
690 "items": nsi_slice_instantiate
691 },
692 "netslice-vld": {
693 "type": "array",
694 "minItems": 1,
695 "items": nsi_vld_instantiate
696 },
697 },
698 "required": ["nsiName", "nstId", "vimAccountId"],
699 "additionalProperties": False
700 }
701
702 nsi_action = {
703
704 }
705
706 nsi_terminate = {
707
708 }
709
710
711 class ValidationError(Exception):
712 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
713 self.http_code = http_code
714 Exception.__init__(self, message)
715
716
717 def validate_input(indata, schema_to_use):
718 """
719 Validates input data against json schema
720 :param indata: user input data. Should be a dictionary
721 :param schema_to_use: jsonschema to test
722 :return: None if ok, raises ValidationError exception on error
723 """
724 try:
725 if schema_to_use:
726 js_v(indata, schema_to_use)
727 return None
728 except js_e.ValidationError as e:
729 if e.path:
730 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
731 else:
732 error_pos = ""
733 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
734 except js_e.SchemaError:
735 raise ValidationError("Bad json schema {}".format(schema_to_use), http_code=HTTPStatus.INTERNAL_SERVER_ERROR)