blob: 6a6eeee093f1d19662c43b2fe451080e7da23722 [file] [log] [blame]
tierno0f98af52018-03-19 10:28:22 +01001# -*- coding: utf-8 -*-
2
tiernod125caf2018-11-22 16:05:54 +00003# 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
tierno0f98af52018-03-19 10:28:22 +010016from jsonschema import validate as js_v, exceptions as js_e
tierno36ec8602018-11-02 17:27:11 +010017from http import HTTPStatus
garciadeblasdaf8cc52018-11-30 14:17:20 +010018from copy import deepcopy
garciadeblas4568a372021-03-24 09:19:48 +010019from uuid import UUID # To test for valid UUID
tierno0f98af52018-03-19 10:28:22 +010020
21__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
22__version__ = "0.1"
23version_date = "Mar 2018"
24
25"""
26Validator of input data using JSON schemas for those items that not contains an OSM yang information model
27"""
28
29# Basis schemas
30patern_name = "^[ -~]+$"
garciadeblas4568a372021-03-24 09:19:48 +010031shortname_schema = {
32 "type": "string",
33 "minLength": 1,
34 "maxLength": 60,
35 "pattern": "^[^,;()\\.\\$'\"]+$",
36}
tierno0f98af52018-03-19 10:28:22 +010037passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
garciadeblas4568a372021-03-24 09:19:48 +010038name_schema = {
39 "type": "string",
40 "minLength": 1,
41 "maxLength": 255,
42 "pattern": "^[^,;()'\"]+$",
43}
tierno0da52252018-06-27 15:47:22 +020044string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
garciadeblas4568a372021-03-24 09:19:48 +010045xml_text_schema = {
46 "type": "string",
47 "minLength": 1,
48 "maxLength": 1000,
49 "pattern": "^[^']+$",
50}
51description_schema = {
52 "type": ["string", "null"],
53 "maxLength": 255,
54 "pattern": "^[^'\"]+$",
55}
56long_description_schema = {
57 "type": ["string", "null"],
58 "maxLength": 3000,
59 "pattern": "^[^'\"]+$",
60}
tierno441dbbf2018-07-10 12:52:48 +020061id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
62bool_schema = {"type": "boolean"}
63null_schema = {"type": "null"}
tierno2236d202018-05-16 19:05:16 +020064# "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}$"
garciadeblas4568a372021-03-24 09:19:48 +010065id_schema = {
66 "type": "string",
67 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
68}
69time_schema = {
70 "type": "string",
71 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}",
72}
73pci_schema = {
74 "type": "string",
75 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$",
76}
tierno42fce592018-11-02 09:23:43 +010077# allows [] for wildcards. For that reason huge length limit is set
78pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
K Sai Kiran990ac462020-05-20 12:25:12 +053079http_schema = {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
tierno0f98af52018-03-19 10:28:22 +010080bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
81memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
82integer0_schema = {"type": "integer", "minimum": 0}
83integer1_schema = {"type": "integer", "minimum": 1}
tierno87006042018-10-24 12:50:20 +020084path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
tierno0f98af52018-03-19 10:28:22 +010085vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
86vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
garciadeblas4568a372021-03-24 09:19:48 +010087mac_schema = {
88 "type": "string",
89 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$",
90} # must be unicast: LSB bit of MSB byte ==0
tiernocb83c942018-09-24 17:28:13 +020091dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
tierno0f98af52018-03-19 10:28:22 +010092# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
garciadeblas4568a372021-03-24 09:19:48 +010093ip_schema = {
94 "type": "string",
95 "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]?)$",
96}
97ip_prefix_schema = {
98 "type": "string",
99 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
100 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
101}
tierno0f98af52018-03-19 10:28:22 +0100102port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
103object_schema = {"type": "object"}
104schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
105# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
garciadeblas4568a372021-03-24 09:19:48 +0100106log_level_schema = {
107 "type": "string",
108 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
109}
tierno0f98af52018-03-19 10:28:22 +0100110checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
111size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +0200112array_edition_schema = {
113 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100114 "patternProperties": {"^\\$": {}},
tiernocd54a4a2018-09-12 16:40:35 +0200115 "additionalProperties": False,
116 "minProperties": 1,
117}
tiernocb83c942018-09-24 17:28:13 +0200118nameshort_list_schema = {
119 "type": "array",
120 "minItems": 1,
tiernofd160572019-01-21 10:41:37 +0000121 "items": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200122}
tiernocd54a4a2018-09-12 16:40:35 +0200123
David Garciaecb41322021-03-31 19:10:46 +0200124description_list_schema = {
125 "type": "array",
126 "minItems": 1,
127 "items": description_schema,
128}
tierno0f98af52018-03-19 10:28:22 +0100129
tierno441dbbf2018-07-10 12:52:48 +0200130ns_instantiate_vdu = {
131 "title": "ns action instantiate input schema for vdu",
132 "$schema": "http://json-schema.org/draft-04/schema#",
133 "type": "object",
134 "properties": {
135 "id": name_schema,
136 "volume": {
137 "type": "array",
138 "minItems": 1,
139 "items": {
140 "type": "object",
141 "properties": {
142 "name": name_schema,
143 "vim-volume-id": name_schema,
144 },
145 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100146 "additionalProperties": False,
147 },
tierno441dbbf2018-07-10 12:52:48 +0200148 },
149 "interface": {
150 "type": "array",
151 "minItems": 1,
152 "items": {
153 "type": "object",
154 "properties": {
155 "name": name_schema,
156 "ip-address": ip_schema,
157 "mac-address": mac_schema,
158 "floating-ip-required": bool_schema,
159 },
160 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100161 "additionalProperties": False,
162 },
163 },
tierno441dbbf2018-07-10 12:52:48 +0200164 },
165 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100166 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200167}
168
169ip_profile_dns_schema = {
170 "type": "array",
171 "minItems": 1,
172 "items": {
173 "type": "object",
174 "properties": {
175 "address": ip_schema,
176 },
177 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100178 "additionalProperties": False,
179 },
tierno441dbbf2018-07-10 12:52:48 +0200180}
181
182ip_profile_dhcp_schema = {
183 "type": "object",
184 "properties": {
185 "enabled": {"type": "boolean"},
186 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100187 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200188 },
189 "additionalProperties": False,
190}
191
192ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000193 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200194 "$schema": "http://json-schema.org/draft-04/schema#",
195 "type": "object",
196 "properties": {
197 "ip-version": {"enum": ["ipv4", "ipv6"]},
198 "subnet-address": ip_prefix_schema,
199 "gateway-address": ip_schema,
200 "dns-server": ip_profile_dns_schema,
201 "dhcp-params": ip_profile_dhcp_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100202 },
tierno441dbbf2018-07-10 12:52:48 +0200203}
204
205ip_profile_update_schema = {
tierno2a929042020-03-10 16:34:25 +0000206 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200207 "$schema": "http://json-schema.org/draft-04/schema#",
208 "type": "object",
209 "properties": {
210 "ip-version": {"enum": ["ipv4", "ipv6"]},
211 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
212 "gateway-address": {"oneOf": [null_schema, ip_schema]},
213 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200214 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
215 },
garciadeblas4568a372021-03-24 09:19:48 +0100216 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200217}
218
kbsub21f03f52019-10-17 16:26:56 +0000219provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000220 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000221 "$schema": "http://json-schema.org/draft-04/schema#",
222 "type": "object",
223 "properties": {
224 "physical-network": name_schema,
225 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000226 "sdn-ports": { # external ports to append to the SDN-assist network
227 "type": "array",
228 "items": {
229 "type": "object",
230 "properties": {
231 "switch_id": shortname_schema,
232 "switch_port": shortname_schema,
233 "mac_address": mac_schema,
234 "vlan": vlan_schema,
235 },
garciadeblas4568a372021-03-24 09:19:48 +0100236 "additionalProperties": True,
237 },
tierno2a929042020-03-10 16:34:25 +0000238 },
239 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000240 },
garciadeblas4568a372021-03-24 09:19:48 +0100241 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000242}
243
tierno441dbbf2018-07-10 12:52:48 +0200244ns_instantiate_internal_vld = {
245 "title": "ns action instantiate input schema for vdu",
246 "$schema": "http://json-schema.org/draft-04/schema#",
247 "type": "object",
248 "properties": {
249 "name": name_schema,
250 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100251 "vim-network-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200252 "ip-profile": ip_profile_update_schema,
kbsub21f03f52019-10-17 16:26:56 +0000253 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200254 "internal-connection-point": {
255 "type": "array",
256 "minItems": 1,
257 "items": {
258 "type": "object",
259 "properties": {
260 "id-ref": name_schema,
261 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200262 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200263 },
tiernob7c6f2a2018-09-03 14:32:10 +0200264 "required": ["id-ref"],
265 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100266 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200267 },
garciadeblas4568a372021-03-24 09:19:48 +0100268 },
tierno441dbbf2018-07-10 12:52:48 +0200269 },
270 "required": ["name"],
271 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100272 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200273}
tierno65acb4d2018-04-06 16:42:40 +0200274
tiernofd160572019-01-21 10:41:37 +0000275additional_params_for_vnf = {
276 "type": "array",
277 "items": {
278 "type": "object",
279 "properties": {
280 "member-vnf-index": name_schema,
281 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000282 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000283 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000284 "additionalParamsForVdu": {
285 "type": "array",
286 "items": {
287 "type": "object",
288 "properties": {
289 "vdu_id": name_schema,
290 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100291 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000292 },
tiernof62ac6a2020-04-29 13:46:13 +0000293 "required": ["vdu_id"],
294 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000295 "additionalProperties": False,
296 },
297 },
298 "additionalParamsForKdu": {
299 "type": "array",
300 "items": {
301 "type": "object",
302 "properties": {
303 "kdu_name": name_schema,
304 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000305 "kdu_model": name_schema,
306 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100307 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200308 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000309 },
tierno54db2e42020-04-06 15:29:42 +0000310 "required": ["kdu_name"],
311 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000312 "additionalProperties": False,
313 },
314 },
tiernofd160572019-01-21 10:41:37 +0000315 },
tierno714954e2019-11-29 13:43:26 +0000316 "required": ["member-vnf-index"],
317 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100318 "additionalProperties": False,
319 },
tiernofd160572019-01-21 10:41:37 +0000320}
321
tierno65acb4d2018-04-06 16:42:40 +0200322ns_instantiate = {
323 "title": "ns action instantiate input schema",
324 "$schema": "http://json-schema.org/draft-04/schema#",
325 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200326 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200327 "lcmOperationType": string_schema,
328 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100329 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200330 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000331 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200332 "nsdId": id_schema,
333 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000334 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100335 "placement-engine": string_schema,
336 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000337 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000338 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100339 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000340 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100341 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000342 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200343 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200344 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200345 "vnf": {
346 "type": "array",
347 "minItems": 1,
348 "items": {
349 "type": "object",
350 "properties": {
351 "member-vnf-index": name_schema,
352 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200353 "vdu": {
354 "type": "array",
355 "minItems": 1,
356 "items": ns_instantiate_vdu,
357 },
358 "internal-vld": {
359 "type": "array",
360 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100361 "items": ns_instantiate_internal_vld,
362 },
tierno0da52252018-06-27 15:47:22 +0200363 },
tierno441dbbf2018-07-10 12:52:48 +0200364 "required": ["member-vnf-index"],
365 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100366 "additionalProperties": False,
367 },
tierno0da52252018-06-27 15:47:22 +0200368 },
369 "vld": {
370 "type": "array",
371 "minItems": 1,
372 "items": {
373 "type": "object",
374 "properties": {
375 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000376 "vim-network-name": {"oneOf": [string_schema, object_schema]},
377 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100378 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000379 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200380 "ip-profile": object_schema,
kbsub21f03f52019-10-17 16:26:56 +0000381 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200382 "vnfd-connection-point-ref": {
383 "type": "array",
384 "minItems": 1,
385 "items": {
386 "type": "object",
387 "properties": {
388 "member-vnf-index-ref": name_schema,
389 "vnfd-connection-point-ref": name_schema,
390 "ip-address": ip_schema,
391 # "mac-address": mac_schema,
392 },
garciadeblas4568a372021-03-24 09:19:48 +0100393 "required": [
394 "member-vnf-index-ref",
395 "vnfd-connection-point-ref",
396 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200397 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100398 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200399 },
garciadeblas4568a372021-03-24 09:19:48 +0100400 },
tierno0da52252018-06-27 15:47:22 +0200401 },
tierno441dbbf2018-07-10 12:52:48 +0200402 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100403 "additionalProperties": False,
404 },
tierno0da52252018-06-27 15:47:22 +0200405 },
406 },
tierno441dbbf2018-07-10 12:52:48 +0200407 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100408 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200409}
tierno0da52252018-06-27 15:47:22 +0200410
tierno1c38f2f2020-03-24 11:51:39 +0000411ns_terminate = {
412 "title": "ns terminate input schema",
413 "$schema": "http://json-schema.org/draft-04/schema#",
414 "type": "object",
415 "properties": {
416 "lcmOperationType": string_schema,
417 "nsInstanceId": id_schema,
418 "autoremove": bool_schema,
419 "timeout_ns_terminate": integer1_schema,
420 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000421 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000422 },
garciadeblas4568a372021-03-24 09:19:48 +0100423 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000424}
425
garciadeblas4568a372021-03-24 09:19:48 +0100426ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200427 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200428 "$schema": "http://json-schema.org/draft-04/schema#",
429 "type": "object",
430 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200431 "lcmOperationType": string_schema,
432 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200433 "member_vnf_index": name_schema,
434 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200435 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000436 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000437 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200438 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000439 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200440 "primitive_params": {"type": "object"},
441 },
garciadeblas4568a372021-03-24 09:19:48 +0100442 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
443 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200444}
garciadeblas4568a372021-03-24 09:19:48 +0100445ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200446 "title": "ns scale input schema",
447 "$schema": "http://json-schema.org/draft-04/schema#",
448 "type": "object",
449 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200450 "lcmOperationType": string_schema,
451 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200452 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000453 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200454 "scaleVnfData": {
455 "type": "object",
456 "properties": {
457 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100458 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200459 "scaleByStepData": {
460 "type": "object",
461 "properties": {
462 "scaling-group-descriptor": name_schema,
463 "member-vnf-index": name_schema,
464 "scaling-policy": name_schema,
465 },
466 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100467 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200468 },
469 },
470 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100471 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200472 },
473 "scaleTime": time_schema,
474 },
475 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100476 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200477}
tierno65acb4d2018-04-06 16:42:40 +0200478
479
tierno0f98af52018-03-19 10:28:22 +0100480schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000481schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000482vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200483
tierno09c073e2018-04-26 13:36:48 +0200484vim_account_edit_schema = {
485 "title": "vim_account edit input schema",
486 "$schema": "http://json-schema.org/draft-04/schema#",
487 "type": "object",
488 "properties": {
489 "name": name_schema,
490 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200491 "vim": name_schema,
492 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200493 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200494 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200495 # "vim_url_admin": description_schema,
496 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200497 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200498 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200499 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200500 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100501 "config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200502 },
garciadeblas4568a372021-03-24 09:19:48 +0100503 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200504}
tierno0f98af52018-03-19 10:28:22 +0100505
tierno09c073e2018-04-26 13:36:48 +0200506vim_account_new_schema = {
507 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100508 "$schema": "http://json-schema.org/draft-04/schema#",
509 "type": "object",
510 "properties": {
511 "schema_version": schema_version,
512 "schema_type": schema_type,
513 "name": name_schema,
514 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200515 "vim": name_schema,
516 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200517 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100518 "vim_url": description_schema,
519 # "vim_url_admin": description_schema,
520 # "vim_tenant": name_schema,
521 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200522 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200523 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200524 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100525 "config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100526 },
garciadeblas4568a372021-03-24 09:19:48 +0100527 "required": [
528 "name",
529 "vim_url",
530 "vim_type",
531 "vim_user",
532 "vim_password",
533 "vim_tenant_name",
534 ],
535 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100536}
tierno0f98af52018-03-19 10:28:22 +0100537
tierno85807722019-12-20 14:11:35 +0000538wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200539
tierno55ba2e62018-12-11 17:22:22 +0000540wim_account_edit_schema = {
541 "title": "wim_account edit input schema",
542 "$schema": "http://json-schema.org/draft-04/schema#",
543 "type": "object",
544 "properties": {
545 "name": name_schema,
546 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000547 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200548 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000549 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100550 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000551 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100552 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000553 },
garciadeblas4568a372021-03-24 09:19:48 +0100554 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000555}
556
557wim_account_new_schema = {
558 "title": "wim_account creation input schema",
559 "$schema": "http://json-schema.org/draft-04/schema#",
560 "type": "object",
561 "properties": {
562 "schema_version": schema_version,
563 "schema_type": schema_type,
564 "name": name_schema,
565 "description": description_schema,
566 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200567 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000568 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100569 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000570 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000571 "config": {
572 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100573 "patternProperties": {".": {"not": {"type": "null"}}},
574 },
tierno55ba2e62018-12-11 17:22:22 +0000575 },
576 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100577 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000578}
tierno0f98af52018-03-19 10:28:22 +0100579
580sdn_properties = {
581 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000582 "type": {"type": "string"},
583 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100584 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000585 "password": passwd_schema,
586 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200587 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000588 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200589 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100590 "ip": ip_schema,
591 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100592 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100593}
594sdn_new_schema = {
595 "title": "sdn controller information schema",
596 "$schema": "http://json-schema.org/draft-04/schema#",
597 "type": "object",
598 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100599 "required": ["name", "type"],
600 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100601}
602sdn_edit_schema = {
603 "title": "sdn controller update information schema",
604 "$schema": "http://json-schema.org/draft-04/schema#",
605 "type": "object",
606 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200607 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100608 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100609}
610sdn_port_mapping_schema = {
611 "$schema": "http://json-schema.org/draft-04/schema#",
612 "title": "sdn port mapping information schema",
613 "type": "array",
614 "items": {
615 "type": "object",
616 "properties": {
tiernofd160572019-01-21 10:41:37 +0000617 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100618 "ports": {
619 "type": "array",
620 "items": {
621 "type": "object",
622 "properties": {
tierno42fce592018-11-02 09:23:43 +0100623 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000624 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100625 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100626 },
garciadeblas4568a372021-03-24 09:19:48 +0100627 "required": ["pci"],
628 },
629 },
tierno0f98af52018-03-19 10:28:22 +0100630 },
garciadeblas4568a372021-03-24 09:19:48 +0100631 "required": ["compute_node", "ports"],
632 },
tierno0f98af52018-03-19 10:28:22 +0100633}
634sdn_external_port_schema = {
635 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200636 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100637 "type": "object",
638 "properties": {
639 "port": {"type": "string", "minLength": 1, "maxLength": 60},
640 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100641 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100642 },
garciadeblas4568a372021-03-24 09:19:48 +0100643 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100644}
645
delacruzramofe598fe2019-10-23 18:25:11 +0200646# K8s Clusters
647k8scluster_nets_schema = {
648 "title": "k8scluster nets input schema",
649 "$schema": "http://json-schema.org/draft-04/schema#",
650 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000651 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200652 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100653 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200654}
655k8scluster_new_schema = {
656 "title": "k8scluster creation input schema",
657 "$schema": "http://json-schema.org/draft-04/schema#",
658 "type": "object",
659 "properties": {
660 "schema_version": schema_version,
661 "schema_type": schema_type,
662 "name": name_schema,
663 "description": description_schema,
664 "credentials": object_schema,
665 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200666 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200667 "k8s_version": string_schema,
668 "nets": k8scluster_nets_schema,
669 "namespace": name_schema,
670 "cni": nameshort_list_schema,
671 },
672 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100673 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200674}
675k8scluster_edit_schema = {
676 "title": "vim_account edit input schema",
677 "$schema": "http://json-schema.org/draft-04/schema#",
678 "type": "object",
679 "properties": {
680 "name": name_schema,
681 "description": description_schema,
682 "credentials": object_schema,
683 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200684 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200685 "k8s_version": string_schema,
686 "nets": k8scluster_nets_schema,
687 "namespace": name_schema,
688 "cni": nameshort_list_schema,
689 },
garciadeblas4568a372021-03-24 09:19:48 +0100690 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200691}
692
David Garciaecb41322021-03-31 19:10:46 +0200693# VCA
694vca_new_schema = {
695 "title": "vca creation input schema",
696 "$schema": "http://json-schema.org/draft-04/schema#",
697 "type": "object",
698 "properties": {
699 "schema_version": schema_version,
700 "schema_type": schema_type,
701 "name": name_schema,
702 "description": description_schema,
703 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100704 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200705 "secret": passwd_schema,
706 "cacert": long_description_schema,
707 "lxd-cloud": shortname_schema,
708 "lxd-credentials": shortname_schema,
709 "k8s-cloud": shortname_schema,
710 "k8s-credentials": shortname_schema,
711 "model-config": object_schema,
712 },
713 "required": [
714 "name",
715 "endpoints",
716 "user",
717 "secret",
718 "cacert",
719 "lxd-cloud",
720 "lxd-credentials",
721 "k8s-cloud",
722 "k8s-credentials",
723 ],
724 "additionalProperties": False,
725}
726vca_edit_schema = {
727 "title": "vca creation input schema",
728 "$schema": "http://json-schema.org/draft-04/schema#",
729 "type": "object",
730 "properties": {
731 "name": name_schema,
732 "description": description_schema,
733 "endpoints": description_list_schema,
734 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100735 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200736 "secret": passwd_schema,
737 "cacert": long_description_schema,
738 "lxd-cloud": shortname_schema,
739 "lxd-credentials": shortname_schema,
740 "k8s-cloud": shortname_schema,
741 "k8s-credentials": shortname_schema,
742 "model-config": object_schema,
743 },
744 "additionalProperties": False,
745}
746
delacruzramofe598fe2019-10-23 18:25:11 +0200747# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000748k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200749k8srepo_properties = {
750 "name": name_schema,
751 "description": description_schema,
752 "type": k8srepo_types,
753 "url": description_schema,
754}
755k8srepo_new_schema = {
756 "title": "k8scluster creation input schema",
757 "$schema": "http://json-schema.org/draft-04/schema#",
758 "type": "object",
759 "properties": k8srepo_properties,
760 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100761 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200762}
763k8srepo_edit_schema = {
764 "title": "vim_account edit input schema",
765 "$schema": "http://json-schema.org/draft-04/schema#",
766 "type": "object",
767 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100768 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200769}
770
Felipe Vicensb66b0412020-05-06 10:11:00 +0200771# OSM Repos
772osmrepo_types = {"enum": ["osm"]}
773osmrepo_properties = {
774 "name": name_schema,
775 "description": description_schema,
776 "type": osmrepo_types,
777 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100778 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200779 # "password": passwd_schema
780}
781osmrepo_new_schema = {
782 "title": "osm repo creation input schema",
783 "$schema": "http://json-schema.org/draft-04/schema#",
784 "type": "object",
785 "properties": osmrepo_properties,
786 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100787 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200788}
789osmrepo_edit_schema = {
790 "title": "osm repo edit input schema",
791 "$schema": "http://json-schema.org/draft-04/schema#",
792 "type": "object",
793 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100794 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200795}
796
tiernocb83c942018-09-24 17:28:13 +0200797# PDUs
798pdu_interface = {
799 "type": "object",
800 "properties": {
tiernofd160572019-01-21 10:41:37 +0000801 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200802 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100803 "type": {"enum": ["overlay", "underlay"]},
tierno36ec8602018-11-02 17:27:11 +0100804 "ip-address": ip_schema,
tiernocb83c942018-09-24 17:28:13 +0200805 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100806 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000807 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
808 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100809 # # provide this in case SDN assist must deal with this interface
810 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000811 # "switch-port": shortname_schema,
812 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100813 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200814 },
tierno36ec8602018-11-02 17:27:11 +0100815 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100816 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200817}
tiernocb83c942018-09-24 17:28:13 +0200818pdu_new_schema = {
819 "title": "pdu creation input schema",
820 "$schema": "http://json-schema.org/draft-04/schema#",
821 "type": "object",
822 "properties": {
tiernofd160572019-01-21 10:41:37 +0000823 "name": shortname_schema,
824 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200825 "description": description_schema,
826 "shared": bool_schema,
827 "vims": nameshort_list_schema,
828 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100829 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +0200830 },
831 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +0100832 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +0200833}
tiernocb83c942018-09-24 17:28:13 +0200834pdu_edit_schema = {
835 "title": "pdu edit input schema",
836 "$schema": "http://json-schema.org/draft-04/schema#",
837 "type": "object",
838 "properties": {
tiernofd160572019-01-21 10:41:37 +0000839 "name": shortname_schema,
840 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200841 "description": description_schema,
842 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +0100843 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
844 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +0100845 "interfaces": {
846 "oneOf": [
847 array_edition_schema,
848 {"type": "array", "items": pdu_interface, "minItems": 1},
849 ]
850 },
tiernocb83c942018-09-24 17:28:13 +0200851 },
852 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +0100853 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +0200854}
855
delacruzramo271d2002019-12-02 21:00:37 +0100856# VNF PKG OPERATIONS
857vnfpkgop_new_schema = {
858 "title": "VNF PKG operation creation input schema",
859 "$schema": "http://json-schema.org/draft-04/schema#",
860 "type": "object",
861 "properties": {
862 "lcmOperationType": string_schema,
863 "vnfPkgId": id_schema,
864 "kdu_name": name_schema,
865 "primitive": name_schema,
866 "primitive_params": {"type": "object"},
867 },
garciadeblas4568a372021-03-24 09:19:48 +0100868 "required": [
869 "lcmOperationType",
870 "vnfPkgId",
871 "kdu_name",
872 "primitive",
873 "primitive_params",
874 ],
875 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +0100876}
877
tiernocb83c942018-09-24 17:28:13 +0200878# USERS
tiernocf042d32019-06-13 09:06:40 +0000879project_role_mappings = {
880 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100881 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +0000882 "type": "array",
883 "items": {
884 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100885 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000886 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +0100887 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100888 },
garciadeblas4568a372021-03-24 09:19:48 +0100889 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +0000890}
891project_role_mappings_optional = {
892 "title": "list of projects/roles or projects only",
893 "$schema": "http://json-schema.org/draft-04/schema#",
894 "type": "array",
895 "items": {
896 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100897 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000898 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +0100899 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +0000900 },
garciadeblas4568a372021-03-24 09:19:48 +0100901 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100902}
tiernocd54a4a2018-09-12 16:40:35 +0200903user_new_schema = {
904 "$schema": "http://json-schema.org/draft-04/schema#",
905 "title": "New user schema",
906 "type": "object",
907 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +0100908 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +0000909 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200910 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200911 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +0000912 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +0200913 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100914 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +0100915 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200916}
917user_edit_schema = {
918 "$schema": "http://json-schema.org/draft-04/schema#",
919 "title": "User edit schema for administrators",
920 "type": "object",
921 "properties": {
922 "password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100923 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +0100924 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +0000925 "project_role_mappings": project_role_mappings,
926 "add_project_role_mappings": project_role_mappings,
927 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +0200928 },
929 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100930 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200931}
932
933# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +0100934topics_with_quota = [
935 "vnfds",
936 "nsds",
937 "slice_templates",
938 "pduds",
939 "ns_instances",
940 "slice_instances",
941 "vim_accounts",
942 "wim_accounts",
943 "sdn_controllers",
944 "k8sclusters",
945 "vca",
946 "k8srepos",
947 "osmrepos",
948 "ns_subscriptions",
949]
tiernocd54a4a2018-09-12 16:40:35 +0200950project_new_schema = {
951 "$schema": "http://json-schema.org/draft-04/schema#",
952 "title": "New project schema for administrators",
953 "type": "object",
954 "properties": {
tiernofd160572019-01-21 10:41:37 +0000955 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200956 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +0000957 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +0200958 "quotas": {
959 "type": "object",
960 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +0100961 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +0200962 },
tiernocd54a4a2018-09-12 16:40:35 +0200963 },
964 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100965 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200966}
967project_edit_schema = {
968 "$schema": "http://json-schema.org/draft-04/schema#",
969 "title": "Project edit schema for administrators",
970 "type": "object",
971 "properties": {
972 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100973 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +0200974 "quotas": {
975 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100976 "properties": {
977 topic: {"oneOf": [integer0_schema, null_schema]}
978 for topic in topics_with_quota
979 },
980 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +0200981 },
tiernocd54a4a2018-09-12 16:40:35 +0200982 },
983 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +0100984 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +0200985}
986
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100987# ROLES
988roles_new_schema = {
989 "$schema": "http://json-schema.org/draft-04/schema#",
990 "title": "New role schema for administrators",
991 "type": "object",
992 "properties": {
993 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +0000994 "permissions": {
995 "type": "object",
996 "patternProperties": {
997 ".": bool_schema,
998 },
999 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001000 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001001 },
tierno1f029d82019-06-13 22:37:04 +00001002 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001003 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001004}
1005roles_edit_schema = {
1006 "$schema": "http://json-schema.org/draft-04/schema#",
1007 "title": "Roles edit schema for administrators",
1008 "type": "object",
1009 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001010 "name": shortname_schema,
1011 "permissions": {
1012 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001013 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001014 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001015 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001016 },
tierno1f029d82019-06-13 22:37:04 +00001017 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001018 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001019}
1020
tiernocd54a4a2018-09-12 16:40:35 +02001021# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001022
1023nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001024 "users": user_new_schema,
1025 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001026 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001027 "sdns": sdn_new_schema,
1028 "ns_instantiate": ns_instantiate,
1029 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001030 "ns_scale": ns_scale,
1031 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001032}
1033
1034nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001035 "users": user_edit_schema,
1036 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001037 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001038 "sdns": sdn_edit_schema,
1039 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001040}
1041
Felipe Vicens07f31722018-10-29 15:16:44 +01001042# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001043nsi_subnet_instantiate = deepcopy(ns_instantiate)
1044nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1045nsi_subnet_instantiate["properties"]["id"] = name_schema
1046del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001047
1048nsi_vld_instantiate = {
1049 "title": "netslice vld instantiation params input schema",
1050 "$schema": "http://json-schema.org/draft-04/schema#",
1051 "type": "object",
1052 "properties": {
1053 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001054 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1055 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001056 "ip-profile": object_schema,
1057 },
delacruzramoc061f562019-04-05 11:00:02 +02001058 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001059 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001060}
1061
Felipe Vicens07f31722018-10-29 15:16:44 +01001062nsi_instantiate = {
1063 "title": "netslice action instantiate input schema",
1064 "$schema": "http://json-schema.org/draft-04/schema#",
1065 "type": "object",
1066 "properties": {
1067 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001068 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001069 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001070 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001071 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001072 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001073 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001074 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001075 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001076 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001077 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001078 "type": "array",
1079 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001080 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001081 },
garciadeblas4568a372021-03-24 09:19:48 +01001082 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001083 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001084 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001085 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001086}
1087
garciadeblas4568a372021-03-24 09:19:48 +01001088nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001089
garciadeblas4568a372021-03-24 09:19:48 +01001090nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001091
preethika.p329b8182020-04-22 12:25:39 +05301092nsinstancesubscriptionfilter_schema = {
1093 "title": "instance identifier schema",
1094 "$schema": "http://json-schema.org/draft-07/schema#",
1095 "type": "object",
1096 "properties": {
1097 "nsdIds": {"type": "array"},
1098 "vnfdIds": {"type": "array"},
1099 "pnfdIds": {"type": "array"},
1100 "nsInstanceIds": {"type": "array"},
1101 "nsInstanceNames": {"type": "array"},
1102 },
1103}
1104
1105nslcmsub_schema = {
1106 "title": "nslcmsubscription input schema",
1107 "$schema": "http://json-schema.org/draft-07/schema#",
1108 "type": "object",
1109 "properties": {
1110 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1111 "notificationTypes": {
1112 "type": "array",
1113 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001114 "enum": [
1115 "NsLcmOperationOccurrenceNotification",
1116 "NsChangeNotification",
1117 "NsIdentifierCreationNotification",
1118 "NsIdentifierDeletionNotification",
1119 ]
1120 },
preethika.p329b8182020-04-22 12:25:39 +05301121 },
1122 "operationTypes": {
1123 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001124 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301125 },
1126 "operationStates": {
1127 "type": "array",
1128 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001129 "enum": [
1130 "PROCESSING",
1131 "COMPLETED",
1132 "PARTIALLY_COMPLETED",
1133 "FAILED",
1134 "FAILED_TEMP",
1135 "ROLLING_BACK",
1136 "ROLLED_BACK",
1137 ]
1138 },
preethika.p329b8182020-04-22 12:25:39 +05301139 },
garciadeblas4568a372021-03-24 09:19:48 +01001140 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301141 "lcmOpNameImpactingNsComponent": {
1142 "type": "array",
1143 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001144 "enum": [
1145 "VNF_INSTANTIATE",
1146 "VNF_SCALE",
1147 "VNF_SCALE_TO_LEVEL",
1148 "VNF_CHANGE_FLAVOUR",
1149 "VNF_TERMINATE",
1150 "VNF_HEAL",
1151 "VNF_OPERATE",
1152 "VNF_CHANGE_EXT_CONN",
1153 "VNF_MODIFY_INFO",
1154 "NS_INSTANTIATE",
1155 "NS_SCALE",
1156 "NS_UPDATE",
1157 "NS_TERMINATE",
1158 "NS_HEAL",
1159 ]
1160 },
preethika.p329b8182020-04-22 12:25:39 +05301161 },
1162 "lcmOpOccStatusImpactingNsComponent": {
1163 "type": "array",
1164 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001165 "enum": [
1166 "START",
1167 "COMPLETED",
1168 "PARTIALLY_COMPLETED",
1169 "FAILED",
1170 "ROLLED_BACK",
1171 ]
1172 },
preethika.p329b8182020-04-22 12:25:39 +05301173 },
1174 },
1175 "allOf": [
1176 {
1177 "if": {
1178 "properties": {
1179 "notificationTypes": {
1180 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1181 }
1182 },
1183 },
1184 "then": {
1185 "anyOf": [
1186 {"required": ["operationTypes"]},
1187 {"required": ["operationStates"]},
1188 ]
garciadeblas4568a372021-03-24 09:19:48 +01001189 },
preethika.p329b8182020-04-22 12:25:39 +05301190 },
1191 {
1192 "if": {
1193 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001194 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301195 },
1196 },
1197 "then": {
1198 "anyOf": [
1199 {"required": ["nsComponentTypes"]},
1200 {"required": ["lcmOpNameImpactingNsComponent"]},
1201 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1202 ]
garciadeblas4568a372021-03-24 09:19:48 +01001203 },
1204 },
1205 ],
preethika.p329b8182020-04-22 12:25:39 +05301206}
1207
1208authentication_schema = {
1209 "title": "authentication schema for subscription",
1210 "$schema": "http://json-schema.org/draft-07/schema#",
1211 "type": "object",
1212 "properties": {
1213 "authType": {"enum": ["basic"]},
1214 "paramsBasic": {
1215 "type": "object",
1216 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001217 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301218 "password": passwd_schema,
1219 },
1220 },
1221 },
1222}
1223
1224subscription = {
1225 "title": "subscription input schema",
1226 "$schema": "http://json-schema.org/draft-07/schema#",
1227 "type": "object",
1228 "properties": {
1229 "filter": nslcmsub_schema,
1230 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001231 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301232 },
1233 "required": ["CallbackUri"],
1234}
1235
tierno0f98af52018-03-19 10:28:22 +01001236
1237class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001238 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1239 self.http_code = http_code
1240 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001241
1242
tiernob24258a2018-10-04 18:39:49 +02001243def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001244 """
tiernocd54a4a2018-09-12 16:40:35 +02001245 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001246 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001247 :param schema_to_use: jsonschema to test
1248 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001249 """
1250 try:
tierno0f98af52018-03-19 10:28:22 +01001251 if schema_to_use:
1252 js_v(indata, schema_to_use)
1253 return None
1254 except js_e.ValidationError as e:
1255 if e.path:
tierno0da52252018-06-27 15:47:22 +02001256 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001257 else:
1258 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001259 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001260 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001261 raise ValidationError(
1262 "Bad json schema {}".format(schema_to_use),
1263 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1264 )
delacruzramoc061f562019-04-05 11:00:02 +02001265
1266
1267def is_valid_uuid(x):
1268 """
1269 Test for a valid UUID
1270 :param x: string to test
1271 :return: True if x is a valid uuid, False otherwise
1272 """
1273 try:
1274 if UUID(x):
1275 return True
tiernobdebce92019-07-01 15:36:49 +00001276 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001277 return False