blob: 9bbde280203542234fd552fbcc3c307d2a8dfee6 [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}
garciadeblas1a01e1f2021-10-26 17:27:35 +020097ipv6_schema = {
98 "type": "string",
99 "pattern": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))",
100}
garciadeblas4568a372021-03-24 09:19:48 +0100101ip_prefix_schema = {
102 "type": "string",
103 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
104 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
105}
tierno0f98af52018-03-19 10:28:22 +0100106port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
107object_schema = {"type": "object"}
108schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
109# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
garciadeblas4568a372021-03-24 09:19:48 +0100110log_level_schema = {
111 "type": "string",
112 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
113}
tierno0f98af52018-03-19 10:28:22 +0100114checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
115size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +0200116array_edition_schema = {
117 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100118 "patternProperties": {"^\\$": {}},
tiernocd54a4a2018-09-12 16:40:35 +0200119 "additionalProperties": False,
120 "minProperties": 1,
121}
tiernocb83c942018-09-24 17:28:13 +0200122nameshort_list_schema = {
123 "type": "array",
124 "minItems": 1,
tiernofd160572019-01-21 10:41:37 +0000125 "items": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200126}
tiernocd54a4a2018-09-12 16:40:35 +0200127
David Garciaecb41322021-03-31 19:10:46 +0200128description_list_schema = {
129 "type": "array",
130 "minItems": 1,
131 "items": description_schema,
132}
tierno0f98af52018-03-19 10:28:22 +0100133
tierno441dbbf2018-07-10 12:52:48 +0200134ns_instantiate_vdu = {
135 "title": "ns action instantiate input schema for vdu",
136 "$schema": "http://json-schema.org/draft-04/schema#",
137 "type": "object",
138 "properties": {
139 "id": name_schema,
140 "volume": {
141 "type": "array",
142 "minItems": 1,
143 "items": {
144 "type": "object",
145 "properties": {
146 "name": name_schema,
147 "vim-volume-id": name_schema,
148 },
149 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100150 "additionalProperties": False,
151 },
tierno441dbbf2018-07-10 12:52:48 +0200152 },
153 "interface": {
154 "type": "array",
155 "minItems": 1,
156 "items": {
157 "type": "object",
158 "properties": {
159 "name": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200160 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200161 "mac-address": mac_schema,
162 "floating-ip-required": bool_schema,
163 },
164 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100165 "additionalProperties": False,
166 },
167 },
tierno441dbbf2018-07-10 12:52:48 +0200168 },
169 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100170 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200171}
172
173ip_profile_dns_schema = {
174 "type": "array",
175 "minItems": 1,
176 "items": {
177 "type": "object",
178 "properties": {
garciadeblas9fb32712022-04-04 16:33:59 +0200179 "address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200180 },
181 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100182 "additionalProperties": False,
183 },
tierno441dbbf2018-07-10 12:52:48 +0200184}
185
186ip_profile_dhcp_schema = {
187 "type": "object",
188 "properties": {
189 "enabled": {"type": "boolean"},
190 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100191 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200192 },
193 "additionalProperties": False,
194}
195
196ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000197 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200198 "$schema": "http://json-schema.org/draft-04/schema#",
199 "type": "object",
200 "properties": {
201 "ip-version": {"enum": ["ipv4", "ipv6"]},
202 "subnet-address": ip_prefix_schema,
203 "gateway-address": ip_schema,
204 "dns-server": ip_profile_dns_schema,
205 "dhcp-params": ip_profile_dhcp_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100206 },
tierno441dbbf2018-07-10 12:52:48 +0200207}
208
209ip_profile_update_schema = {
tierno2a929042020-03-10 16:34:25 +0000210 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200211 "$schema": "http://json-schema.org/draft-04/schema#",
212 "type": "object",
213 "properties": {
214 "ip-version": {"enum": ["ipv4", "ipv6"]},
215 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
216 "gateway-address": {"oneOf": [null_schema, ip_schema]},
217 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200218 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
219 },
garciadeblas4568a372021-03-24 09:19:48 +0100220 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200221}
222
kbsub21f03f52019-10-17 16:26:56 +0000223provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000224 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000225 "$schema": "http://json-schema.org/draft-04/schema#",
226 "type": "object",
227 "properties": {
228 "physical-network": name_schema,
229 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000230 "sdn-ports": { # external ports to append to the SDN-assist network
231 "type": "array",
232 "items": {
233 "type": "object",
234 "properties": {
235 "switch_id": shortname_schema,
236 "switch_port": shortname_schema,
237 "mac_address": mac_schema,
238 "vlan": vlan_schema,
239 },
garciadeblas4568a372021-03-24 09:19:48 +0100240 "additionalProperties": True,
241 },
tierno2a929042020-03-10 16:34:25 +0000242 },
243 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000244 },
garciadeblas4568a372021-03-24 09:19:48 +0100245 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000246}
247
tierno441dbbf2018-07-10 12:52:48 +0200248ns_instantiate_internal_vld = {
garciadeblas9fb32712022-04-04 16:33:59 +0200249 "title": "ns action instantiate input schema for vld",
tierno441dbbf2018-07-10 12:52:48 +0200250 "$schema": "http://json-schema.org/draft-04/schema#",
251 "type": "object",
252 "properties": {
253 "name": name_schema,
254 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100255 "vim-network-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200256 "ip-profile": ip_profile_update_schema,
kbsub21f03f52019-10-17 16:26:56 +0000257 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200258 "internal-connection-point": {
259 "type": "array",
260 "minItems": 1,
261 "items": {
262 "type": "object",
263 "properties": {
264 "id-ref": name_schema,
265 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200266 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200267 },
tiernob7c6f2a2018-09-03 14:32:10 +0200268 "required": ["id-ref"],
269 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100270 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200271 },
garciadeblas4568a372021-03-24 09:19:48 +0100272 },
tierno441dbbf2018-07-10 12:52:48 +0200273 },
274 "required": ["name"],
275 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100276 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200277}
tierno65acb4d2018-04-06 16:42:40 +0200278
tiernofd160572019-01-21 10:41:37 +0000279additional_params_for_vnf = {
280 "type": "array",
281 "items": {
282 "type": "object",
283 "properties": {
284 "member-vnf-index": name_schema,
285 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000286 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000287 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000288 "additionalParamsForVdu": {
289 "type": "array",
290 "items": {
291 "type": "object",
292 "properties": {
293 "vdu_id": name_schema,
294 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100295 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000296 },
tiernof62ac6a2020-04-29 13:46:13 +0000297 "required": ["vdu_id"],
298 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000299 "additionalProperties": False,
300 },
301 },
302 "additionalParamsForKdu": {
303 "type": "array",
304 "items": {
305 "type": "object",
306 "properties": {
307 "kdu_name": name_schema,
308 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000309 "kdu_model": name_schema,
310 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100311 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200312 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000313 },
tierno54db2e42020-04-06 15:29:42 +0000314 "required": ["kdu_name"],
315 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000316 "additionalProperties": False,
317 },
318 },
Alexis Romeroee31f532022-04-26 19:10:21 +0200319 "affinity-or-anti-affinity-group": {
320 "type": "array",
321 "items": {
322 "type": "object",
323 "properties": {
324 "id": name_schema,
325 "vim-affinity-group-id": name_schema,
326 },
327 "required": ["id"],
328 "minProperties": 2,
329 "additionalProperties": False,
330 },
331 },
tiernofd160572019-01-21 10:41:37 +0000332 },
tierno714954e2019-11-29 13:43:26 +0000333 "required": ["member-vnf-index"],
334 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100335 "additionalProperties": False,
336 },
tiernofd160572019-01-21 10:41:37 +0000337}
338
tierno65acb4d2018-04-06 16:42:40 +0200339ns_instantiate = {
340 "title": "ns action instantiate input schema",
341 "$schema": "http://json-schema.org/draft-04/schema#",
342 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200343 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200344 "lcmOperationType": string_schema,
345 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100346 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200347 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000348 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200349 "nsdId": id_schema,
350 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000351 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100352 "placement-engine": string_schema,
353 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000354 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000355 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100356 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000357 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100358 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000359 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200360 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200361 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200362 "vnf": {
363 "type": "array",
364 "minItems": 1,
365 "items": {
366 "type": "object",
367 "properties": {
368 "member-vnf-index": name_schema,
369 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200370 "vdu": {
371 "type": "array",
372 "minItems": 1,
373 "items": ns_instantiate_vdu,
374 },
375 "internal-vld": {
376 "type": "array",
377 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100378 "items": ns_instantiate_internal_vld,
379 },
tierno0da52252018-06-27 15:47:22 +0200380 },
tierno441dbbf2018-07-10 12:52:48 +0200381 "required": ["member-vnf-index"],
382 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100383 "additionalProperties": False,
384 },
tierno0da52252018-06-27 15:47:22 +0200385 },
386 "vld": {
387 "type": "array",
388 "minItems": 1,
389 "items": {
390 "type": "object",
391 "properties": {
392 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000393 "vim-network-name": {"oneOf": [string_schema, object_schema]},
394 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100395 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000396 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200397 "ip-profile": object_schema,
kbsub21f03f52019-10-17 16:26:56 +0000398 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200399 "vnfd-connection-point-ref": {
400 "type": "array",
401 "minItems": 1,
402 "items": {
403 "type": "object",
404 "properties": {
405 "member-vnf-index-ref": name_schema,
406 "vnfd-connection-point-ref": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200407 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernob7c6f2a2018-09-03 14:32:10 +0200408 # "mac-address": mac_schema,
409 },
garciadeblas4568a372021-03-24 09:19:48 +0100410 "required": [
411 "member-vnf-index-ref",
412 "vnfd-connection-point-ref",
413 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200414 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100415 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200416 },
garciadeblas4568a372021-03-24 09:19:48 +0100417 },
tierno0da52252018-06-27 15:47:22 +0200418 },
tierno441dbbf2018-07-10 12:52:48 +0200419 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100420 "additionalProperties": False,
421 },
tierno0da52252018-06-27 15:47:22 +0200422 },
423 },
tierno441dbbf2018-07-10 12:52:48 +0200424 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100425 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200426}
tierno0da52252018-06-27 15:47:22 +0200427
tierno1c38f2f2020-03-24 11:51:39 +0000428ns_terminate = {
429 "title": "ns terminate input schema",
430 "$schema": "http://json-schema.org/draft-04/schema#",
431 "type": "object",
432 "properties": {
433 "lcmOperationType": string_schema,
434 "nsInstanceId": id_schema,
435 "autoremove": bool_schema,
436 "timeout_ns_terminate": integer1_schema,
437 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000438 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000439 },
garciadeblas4568a372021-03-24 09:19:48 +0100440 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000441}
442
garciadeblas4568a372021-03-24 09:19:48 +0100443ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200444 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200445 "$schema": "http://json-schema.org/draft-04/schema#",
446 "type": "object",
447 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200448 "lcmOperationType": string_schema,
449 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200450 "member_vnf_index": name_schema,
451 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200452 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000453 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000454 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200455 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000456 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200457 "primitive_params": {"type": "object"},
458 },
garciadeblas4568a372021-03-24 09:19:48 +0100459 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
460 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200461}
garciadeblas4568a372021-03-24 09:19:48 +0100462ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200463 "title": "ns scale input schema",
464 "$schema": "http://json-schema.org/draft-04/schema#",
465 "type": "object",
466 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200467 "lcmOperationType": string_schema,
468 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200469 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000470 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200471 "scaleVnfData": {
472 "type": "object",
473 "properties": {
474 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100475 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200476 "scaleByStepData": {
477 "type": "object",
478 "properties": {
479 "scaling-group-descriptor": name_schema,
480 "member-vnf-index": name_schema,
481 "scaling-policy": name_schema,
482 },
483 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100484 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200485 },
486 },
487 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100488 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200489 },
490 "scaleTime": time_schema,
491 },
492 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100493 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200494}
tierno65acb4d2018-04-06 16:42:40 +0200495
496
tierno0f98af52018-03-19 10:28:22 +0100497schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000498schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000499vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200500
tierno09c073e2018-04-26 13:36:48 +0200501vim_account_edit_schema = {
502 "title": "vim_account edit input schema",
503 "$schema": "http://json-schema.org/draft-04/schema#",
504 "type": "object",
505 "properties": {
506 "name": name_schema,
507 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200508 "vim": name_schema,
509 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200510 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200511 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200512 # "vim_url_admin": description_schema,
513 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200514 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200515 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200516 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200517 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100518 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000519 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200520 },
garciadeblas4568a372021-03-24 09:19:48 +0100521 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200522}
tierno0f98af52018-03-19 10:28:22 +0100523
tierno09c073e2018-04-26 13:36:48 +0200524vim_account_new_schema = {
525 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100526 "$schema": "http://json-schema.org/draft-04/schema#",
527 "type": "object",
528 "properties": {
529 "schema_version": schema_version,
530 "schema_type": schema_type,
531 "name": name_schema,
532 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200533 "vim": name_schema,
534 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200535 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100536 "vim_url": description_schema,
537 # "vim_url_admin": description_schema,
538 # "vim_tenant": name_schema,
539 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200540 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200541 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200542 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100543 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000544 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100545 },
garciadeblas4568a372021-03-24 09:19:48 +0100546 "required": [
547 "name",
548 "vim_url",
549 "vim_type",
550 "vim_user",
551 "vim_password",
552 "vim_tenant_name",
553 ],
554 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100555}
tierno0f98af52018-03-19 10:28:22 +0100556
tierno85807722019-12-20 14:11:35 +0000557wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200558
tierno55ba2e62018-12-11 17:22:22 +0000559wim_account_edit_schema = {
560 "title": "wim_account edit input schema",
561 "$schema": "http://json-schema.org/draft-04/schema#",
562 "type": "object",
563 "properties": {
564 "name": name_schema,
565 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000566 "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,
garciadeblas4568a372021-03-24 09:19:48 +0100571 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000572 },
garciadeblas4568a372021-03-24 09:19:48 +0100573 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000574}
575
576wim_account_new_schema = {
577 "title": "wim_account creation input schema",
578 "$schema": "http://json-schema.org/draft-04/schema#",
579 "type": "object",
580 "properties": {
581 "schema_version": schema_version,
582 "schema_type": schema_type,
583 "name": name_schema,
584 "description": description_schema,
585 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200586 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000587 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100588 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000589 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000590 "config": {
591 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100592 "patternProperties": {".": {"not": {"type": "null"}}},
593 },
tierno55ba2e62018-12-11 17:22:22 +0000594 },
595 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100596 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000597}
tierno0f98af52018-03-19 10:28:22 +0100598
599sdn_properties = {
600 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000601 "type": {"type": "string"},
602 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100603 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000604 "password": passwd_schema,
605 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200606 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000607 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200608 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100609 "ip": ip_schema,
610 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100611 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100612}
613sdn_new_schema = {
614 "title": "sdn controller information schema",
615 "$schema": "http://json-schema.org/draft-04/schema#",
616 "type": "object",
617 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100618 "required": ["name", "type"],
619 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100620}
621sdn_edit_schema = {
622 "title": "sdn controller update information schema",
623 "$schema": "http://json-schema.org/draft-04/schema#",
624 "type": "object",
625 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200626 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100627 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100628}
629sdn_port_mapping_schema = {
630 "$schema": "http://json-schema.org/draft-04/schema#",
631 "title": "sdn port mapping information schema",
632 "type": "array",
633 "items": {
634 "type": "object",
635 "properties": {
tiernofd160572019-01-21 10:41:37 +0000636 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100637 "ports": {
638 "type": "array",
639 "items": {
640 "type": "object",
641 "properties": {
tierno42fce592018-11-02 09:23:43 +0100642 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000643 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100644 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100645 },
garciadeblas4568a372021-03-24 09:19:48 +0100646 "required": ["pci"],
647 },
648 },
tierno0f98af52018-03-19 10:28:22 +0100649 },
garciadeblas4568a372021-03-24 09:19:48 +0100650 "required": ["compute_node", "ports"],
651 },
tierno0f98af52018-03-19 10:28:22 +0100652}
653sdn_external_port_schema = {
654 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200655 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100656 "type": "object",
657 "properties": {
658 "port": {"type": "string", "minLength": 1, "maxLength": 60},
659 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100660 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100661 },
garciadeblas4568a372021-03-24 09:19:48 +0100662 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100663}
664
delacruzramofe598fe2019-10-23 18:25:11 +0200665# K8s Clusters
666k8scluster_nets_schema = {
667 "title": "k8scluster nets input schema",
668 "$schema": "http://json-schema.org/draft-04/schema#",
669 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000670 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200671 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100672 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200673}
674k8scluster_new_schema = {
675 "title": "k8scluster creation input schema",
676 "$schema": "http://json-schema.org/draft-04/schema#",
677 "type": "object",
678 "properties": {
679 "schema_version": schema_version,
680 "schema_type": schema_type,
681 "name": name_schema,
682 "description": description_schema,
683 "credentials": object_schema,
684 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200685 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200686 "k8s_version": string_schema,
687 "nets": k8scluster_nets_schema,
688 "namespace": name_schema,
689 "cni": nameshort_list_schema,
690 },
691 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100692 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200693}
694k8scluster_edit_schema = {
695 "title": "vim_account edit input schema",
696 "$schema": "http://json-schema.org/draft-04/schema#",
697 "type": "object",
698 "properties": {
699 "name": name_schema,
700 "description": description_schema,
701 "credentials": object_schema,
702 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200703 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200704 "k8s_version": string_schema,
705 "nets": k8scluster_nets_schema,
706 "namespace": name_schema,
707 "cni": nameshort_list_schema,
708 },
garciadeblas4568a372021-03-24 09:19:48 +0100709 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200710}
711
David Garciaecb41322021-03-31 19:10:46 +0200712# VCA
713vca_new_schema = {
714 "title": "vca creation input schema",
715 "$schema": "http://json-schema.org/draft-04/schema#",
716 "type": "object",
717 "properties": {
718 "schema_version": schema_version,
719 "schema_type": schema_type,
720 "name": name_schema,
721 "description": description_schema,
722 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100723 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200724 "secret": passwd_schema,
725 "cacert": long_description_schema,
726 "lxd-cloud": shortname_schema,
727 "lxd-credentials": shortname_schema,
728 "k8s-cloud": shortname_schema,
729 "k8s-credentials": shortname_schema,
730 "model-config": object_schema,
731 },
732 "required": [
733 "name",
734 "endpoints",
735 "user",
736 "secret",
737 "cacert",
738 "lxd-cloud",
739 "lxd-credentials",
740 "k8s-cloud",
741 "k8s-credentials",
742 ],
743 "additionalProperties": False,
744}
745vca_edit_schema = {
746 "title": "vca creation input schema",
747 "$schema": "http://json-schema.org/draft-04/schema#",
748 "type": "object",
749 "properties": {
750 "name": name_schema,
751 "description": description_schema,
752 "endpoints": description_list_schema,
753 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100754 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200755 "secret": passwd_schema,
756 "cacert": long_description_schema,
757 "lxd-cloud": shortname_schema,
758 "lxd-credentials": shortname_schema,
759 "k8s-cloud": shortname_schema,
760 "k8s-credentials": shortname_schema,
761 "model-config": object_schema,
762 },
763 "additionalProperties": False,
764}
765
delacruzramofe598fe2019-10-23 18:25:11 +0200766# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000767k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200768k8srepo_properties = {
769 "name": name_schema,
770 "description": description_schema,
771 "type": k8srepo_types,
772 "url": description_schema,
773}
774k8srepo_new_schema = {
775 "title": "k8scluster creation input schema",
776 "$schema": "http://json-schema.org/draft-04/schema#",
777 "type": "object",
778 "properties": k8srepo_properties,
779 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100780 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200781}
782k8srepo_edit_schema = {
783 "title": "vim_account edit input schema",
784 "$schema": "http://json-schema.org/draft-04/schema#",
785 "type": "object",
786 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100787 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200788}
789
Felipe Vicensb66b0412020-05-06 10:11:00 +0200790# OSM Repos
791osmrepo_types = {"enum": ["osm"]}
792osmrepo_properties = {
793 "name": name_schema,
794 "description": description_schema,
795 "type": osmrepo_types,
796 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100797 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200798 # "password": passwd_schema
799}
800osmrepo_new_schema = {
801 "title": "osm repo creation input schema",
802 "$schema": "http://json-schema.org/draft-04/schema#",
803 "type": "object",
804 "properties": osmrepo_properties,
805 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100806 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200807}
808osmrepo_edit_schema = {
809 "title": "osm repo edit input schema",
810 "$schema": "http://json-schema.org/draft-04/schema#",
811 "type": "object",
812 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100813 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200814}
815
tiernocb83c942018-09-24 17:28:13 +0200816# PDUs
817pdu_interface = {
818 "type": "object",
819 "properties": {
tiernofd160572019-01-21 10:41:37 +0000820 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200821 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100822 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200823 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200824 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100825 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000826 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
827 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100828 # # provide this in case SDN assist must deal with this interface
829 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000830 # "switch-port": shortname_schema,
831 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100832 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200833 },
tierno36ec8602018-11-02 17:27:11 +0100834 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100835 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200836}
tiernocb83c942018-09-24 17:28:13 +0200837pdu_new_schema = {
838 "title": "pdu creation input schema",
839 "$schema": "http://json-schema.org/draft-04/schema#",
840 "type": "object",
841 "properties": {
tiernofd160572019-01-21 10:41:37 +0000842 "name": shortname_schema,
843 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200844 "description": description_schema,
845 "shared": bool_schema,
846 "vims": nameshort_list_schema,
847 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100848 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +0200849 },
850 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +0100851 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +0200852}
tiernocb83c942018-09-24 17:28:13 +0200853pdu_edit_schema = {
854 "title": "pdu edit input schema",
855 "$schema": "http://json-schema.org/draft-04/schema#",
856 "type": "object",
857 "properties": {
tiernofd160572019-01-21 10:41:37 +0000858 "name": shortname_schema,
859 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200860 "description": description_schema,
861 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +0100862 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
863 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +0100864 "interfaces": {
865 "oneOf": [
866 array_edition_schema,
867 {"type": "array", "items": pdu_interface, "minItems": 1},
868 ]
869 },
tiernocb83c942018-09-24 17:28:13 +0200870 },
871 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +0100872 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +0200873}
874
delacruzramo271d2002019-12-02 21:00:37 +0100875# VNF PKG OPERATIONS
876vnfpkgop_new_schema = {
877 "title": "VNF PKG operation creation input schema",
878 "$schema": "http://json-schema.org/draft-04/schema#",
879 "type": "object",
880 "properties": {
881 "lcmOperationType": string_schema,
882 "vnfPkgId": id_schema,
883 "kdu_name": name_schema,
884 "primitive": name_schema,
885 "primitive_params": {"type": "object"},
886 },
garciadeblas4568a372021-03-24 09:19:48 +0100887 "required": [
888 "lcmOperationType",
889 "vnfPkgId",
890 "kdu_name",
891 "primitive",
892 "primitive_params",
893 ],
894 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +0100895}
896
tiernocb83c942018-09-24 17:28:13 +0200897# USERS
tiernocf042d32019-06-13 09:06:40 +0000898project_role_mappings = {
899 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100900 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +0000901 "type": "array",
902 "items": {
903 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100904 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000905 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +0100906 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100907 },
garciadeblas4568a372021-03-24 09:19:48 +0100908 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +0000909}
910project_role_mappings_optional = {
911 "title": "list of projects/roles or projects only",
912 "$schema": "http://json-schema.org/draft-04/schema#",
913 "type": "array",
914 "items": {
915 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100916 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000917 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +0100918 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +0000919 },
garciadeblas4568a372021-03-24 09:19:48 +0100920 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100921}
tiernocd54a4a2018-09-12 16:40:35 +0200922user_new_schema = {
923 "$schema": "http://json-schema.org/draft-04/schema#",
924 "title": "New user schema",
925 "type": "object",
926 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +0100927 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +0000928 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200929 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200930 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +0000931 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +0200932 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100933 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +0100934 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200935}
936user_edit_schema = {
937 "$schema": "http://json-schema.org/draft-04/schema#",
938 "title": "User edit schema for administrators",
939 "type": "object",
940 "properties": {
941 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +0000942 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100943 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +0100944 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +0000945 "project_role_mappings": project_role_mappings,
946 "add_project_role_mappings": project_role_mappings,
947 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +0200948 },
949 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100950 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200951}
952
953# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +0100954topics_with_quota = [
955 "vnfds",
956 "nsds",
957 "slice_templates",
958 "pduds",
959 "ns_instances",
960 "slice_instances",
961 "vim_accounts",
962 "wim_accounts",
963 "sdn_controllers",
964 "k8sclusters",
965 "vca",
966 "k8srepos",
967 "osmrepos",
968 "ns_subscriptions",
969]
tiernocd54a4a2018-09-12 16:40:35 +0200970project_new_schema = {
971 "$schema": "http://json-schema.org/draft-04/schema#",
972 "title": "New project schema for administrators",
973 "type": "object",
974 "properties": {
tiernofd160572019-01-21 10:41:37 +0000975 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200976 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +0000977 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +0200978 "quotas": {
979 "type": "object",
980 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +0100981 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +0200982 },
tiernocd54a4a2018-09-12 16:40:35 +0200983 },
984 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100985 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200986}
987project_edit_schema = {
988 "$schema": "http://json-schema.org/draft-04/schema#",
989 "title": "Project edit schema for administrators",
990 "type": "object",
991 "properties": {
992 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100993 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +0200994 "quotas": {
995 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100996 "properties": {
997 topic: {"oneOf": [integer0_schema, null_schema]}
998 for topic in topics_with_quota
999 },
1000 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001001 },
tiernocd54a4a2018-09-12 16:40:35 +02001002 },
1003 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001004 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001005}
1006
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001007# ROLES
1008roles_new_schema = {
1009 "$schema": "http://json-schema.org/draft-04/schema#",
1010 "title": "New role schema for administrators",
1011 "type": "object",
1012 "properties": {
1013 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001014 "permissions": {
1015 "type": "object",
1016 "patternProperties": {
1017 ".": bool_schema,
1018 },
1019 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001020 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001021 },
tierno1f029d82019-06-13 22:37:04 +00001022 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001023 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001024}
1025roles_edit_schema = {
1026 "$schema": "http://json-schema.org/draft-04/schema#",
1027 "title": "Roles edit schema for administrators",
1028 "type": "object",
1029 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001030 "name": shortname_schema,
1031 "permissions": {
1032 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001033 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001034 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001035 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001036 },
tierno1f029d82019-06-13 22:37:04 +00001037 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001038 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001039}
1040
tiernocd54a4a2018-09-12 16:40:35 +02001041# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001042
1043nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001044 "users": user_new_schema,
1045 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001046 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001047 "sdns": sdn_new_schema,
1048 "ns_instantiate": ns_instantiate,
1049 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001050 "ns_scale": ns_scale,
1051 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001052}
1053
1054nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001055 "users": user_edit_schema,
1056 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001057 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001058 "sdns": sdn_edit_schema,
1059 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001060}
1061
Felipe Vicens07f31722018-10-29 15:16:44 +01001062# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001063nsi_subnet_instantiate = deepcopy(ns_instantiate)
1064nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1065nsi_subnet_instantiate["properties"]["id"] = name_schema
1066del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001067
1068nsi_vld_instantiate = {
1069 "title": "netslice vld instantiation params input schema",
1070 "$schema": "http://json-schema.org/draft-04/schema#",
1071 "type": "object",
1072 "properties": {
1073 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001074 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1075 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001076 "ip-profile": object_schema,
1077 },
delacruzramoc061f562019-04-05 11:00:02 +02001078 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001079 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001080}
1081
Felipe Vicens07f31722018-10-29 15:16:44 +01001082nsi_instantiate = {
1083 "title": "netslice action instantiate input schema",
1084 "$schema": "http://json-schema.org/draft-04/schema#",
1085 "type": "object",
1086 "properties": {
1087 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001088 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001089 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001090 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001091 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001092 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001093 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001094 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001095 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001096 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001097 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001098 "type": "array",
1099 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001100 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001101 },
garciadeblas4568a372021-03-24 09:19:48 +01001102 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001103 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001104 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001105 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001106}
1107
garciadeblas4568a372021-03-24 09:19:48 +01001108nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001109
garciadeblas4568a372021-03-24 09:19:48 +01001110nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001111
preethika.p329b8182020-04-22 12:25:39 +05301112nsinstancesubscriptionfilter_schema = {
1113 "title": "instance identifier schema",
1114 "$schema": "http://json-schema.org/draft-07/schema#",
1115 "type": "object",
1116 "properties": {
1117 "nsdIds": {"type": "array"},
1118 "vnfdIds": {"type": "array"},
1119 "pnfdIds": {"type": "array"},
1120 "nsInstanceIds": {"type": "array"},
1121 "nsInstanceNames": {"type": "array"},
1122 },
1123}
1124
1125nslcmsub_schema = {
1126 "title": "nslcmsubscription input schema",
1127 "$schema": "http://json-schema.org/draft-07/schema#",
1128 "type": "object",
1129 "properties": {
1130 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1131 "notificationTypes": {
1132 "type": "array",
1133 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001134 "enum": [
1135 "NsLcmOperationOccurrenceNotification",
1136 "NsChangeNotification",
1137 "NsIdentifierCreationNotification",
1138 "NsIdentifierDeletionNotification",
1139 ]
1140 },
preethika.p329b8182020-04-22 12:25:39 +05301141 },
1142 "operationTypes": {
1143 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001144 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301145 },
1146 "operationStates": {
1147 "type": "array",
1148 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001149 "enum": [
1150 "PROCESSING",
1151 "COMPLETED",
1152 "PARTIALLY_COMPLETED",
1153 "FAILED",
1154 "FAILED_TEMP",
1155 "ROLLING_BACK",
1156 "ROLLED_BACK",
1157 ]
1158 },
preethika.p329b8182020-04-22 12:25:39 +05301159 },
garciadeblas4568a372021-03-24 09:19:48 +01001160 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301161 "lcmOpNameImpactingNsComponent": {
1162 "type": "array",
1163 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001164 "enum": [
1165 "VNF_INSTANTIATE",
1166 "VNF_SCALE",
1167 "VNF_SCALE_TO_LEVEL",
1168 "VNF_CHANGE_FLAVOUR",
1169 "VNF_TERMINATE",
1170 "VNF_HEAL",
1171 "VNF_OPERATE",
1172 "VNF_CHANGE_EXT_CONN",
1173 "VNF_MODIFY_INFO",
1174 "NS_INSTANTIATE",
1175 "NS_SCALE",
1176 "NS_UPDATE",
1177 "NS_TERMINATE",
1178 "NS_HEAL",
1179 ]
1180 },
preethika.p329b8182020-04-22 12:25:39 +05301181 },
1182 "lcmOpOccStatusImpactingNsComponent": {
1183 "type": "array",
1184 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001185 "enum": [
1186 "START",
1187 "COMPLETED",
1188 "PARTIALLY_COMPLETED",
1189 "FAILED",
1190 "ROLLED_BACK",
1191 ]
1192 },
preethika.p329b8182020-04-22 12:25:39 +05301193 },
1194 },
1195 "allOf": [
1196 {
1197 "if": {
1198 "properties": {
1199 "notificationTypes": {
1200 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1201 }
1202 },
1203 },
1204 "then": {
1205 "anyOf": [
1206 {"required": ["operationTypes"]},
1207 {"required": ["operationStates"]},
1208 ]
garciadeblas4568a372021-03-24 09:19:48 +01001209 },
preethika.p329b8182020-04-22 12:25:39 +05301210 },
1211 {
1212 "if": {
1213 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001214 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301215 },
1216 },
1217 "then": {
1218 "anyOf": [
1219 {"required": ["nsComponentTypes"]},
1220 {"required": ["lcmOpNameImpactingNsComponent"]},
1221 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1222 ]
garciadeblas4568a372021-03-24 09:19:48 +01001223 },
1224 },
1225 ],
preethika.p329b8182020-04-22 12:25:39 +05301226}
1227
1228authentication_schema = {
1229 "title": "authentication schema for subscription",
1230 "$schema": "http://json-schema.org/draft-07/schema#",
1231 "type": "object",
1232 "properties": {
1233 "authType": {"enum": ["basic"]},
1234 "paramsBasic": {
1235 "type": "object",
1236 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001237 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301238 "password": passwd_schema,
1239 },
1240 },
1241 },
1242}
1243
1244subscription = {
1245 "title": "subscription input schema",
1246 "$schema": "http://json-schema.org/draft-07/schema#",
1247 "type": "object",
1248 "properties": {
1249 "filter": nslcmsub_schema,
1250 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001251 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301252 },
1253 "required": ["CallbackUri"],
1254}
1255
tierno0f98af52018-03-19 10:28:22 +01001256
1257class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001258 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1259 self.http_code = http_code
1260 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001261
1262
tiernob24258a2018-10-04 18:39:49 +02001263def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001264 """
tiernocd54a4a2018-09-12 16:40:35 +02001265 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001266 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001267 :param schema_to_use: jsonschema to test
1268 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001269 """
1270 try:
tierno0f98af52018-03-19 10:28:22 +01001271 if schema_to_use:
1272 js_v(indata, schema_to_use)
1273 return None
1274 except js_e.ValidationError as e:
1275 if e.path:
tierno0da52252018-06-27 15:47:22 +02001276 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001277 else:
1278 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001279 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001280 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001281 raise ValidationError(
1282 "Bad json schema {}".format(schema_to_use),
1283 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1284 )
delacruzramoc061f562019-04-05 11:00:02 +02001285
1286
1287def is_valid_uuid(x):
1288 """
1289 Test for a valid UUID
1290 :param x: string to test
1291 :return: True if x is a valid uuid, False otherwise
1292 """
1293 try:
1294 if UUID(x):
1295 return True
tiernobdebce92019-07-01 15:36:49 +00001296 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001297 return False