blob: e5c2a0328fe2addfbad187fd8aef8325b7f3fe15 [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",
garciadeblasf2af4a12023-01-24 16:56:54 +010099 "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]))", # noqa: W605
garciadeblas1a01e1f2021-10-26 17:27:35 +0200100}
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,
Gabriel Cubae88401b2023-04-05 15:24:52 -0500140 "vim-flavor-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200141 "volume": {
142 "type": "array",
143 "minItems": 1,
144 "items": {
145 "type": "object",
146 "properties": {
147 "name": name_schema,
148 "vim-volume-id": name_schema,
149 },
150 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100151 "additionalProperties": False,
152 },
tierno441dbbf2018-07-10 12:52:48 +0200153 },
154 "interface": {
155 "type": "array",
156 "minItems": 1,
157 "items": {
158 "type": "object",
159 "properties": {
160 "name": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200161 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200162 "mac-address": mac_schema,
163 "floating-ip-required": bool_schema,
164 },
165 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100166 "additionalProperties": False,
167 },
168 },
tierno441dbbf2018-07-10 12:52:48 +0200169 },
170 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100171 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200172}
173
174ip_profile_dns_schema = {
175 "type": "array",
176 "minItems": 1,
177 "items": {
178 "type": "object",
179 "properties": {
garciadeblas9fb32712022-04-04 16:33:59 +0200180 "address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200181 },
182 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100183 "additionalProperties": False,
184 },
tierno441dbbf2018-07-10 12:52:48 +0200185}
186
187ip_profile_dhcp_schema = {
188 "type": "object",
189 "properties": {
190 "enabled": {"type": "boolean"},
191 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100192 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200193 },
194 "additionalProperties": False,
195}
196
197ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000198 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200199 "$schema": "http://json-schema.org/draft-04/schema#",
200 "type": "object",
201 "properties": {
202 "ip-version": {"enum": ["ipv4", "ipv6"]},
tierno441dbbf2018-07-10 12:52:48 +0200203 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
204 "gateway-address": {"oneOf": [null_schema, ip_schema]},
205 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200206 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
207 },
garciadeblas4568a372021-03-24 09:19:48 +0100208 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200209}
210
kbsub21f03f52019-10-17 16:26:56 +0000211provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000212 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000213 "$schema": "http://json-schema.org/draft-04/schema#",
214 "type": "object",
215 "properties": {
216 "physical-network": name_schema,
217 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000218 "sdn-ports": { # external ports to append to the SDN-assist network
219 "type": "array",
220 "items": {
221 "type": "object",
222 "properties": {
223 "switch_id": shortname_schema,
224 "switch_port": shortname_schema,
225 "mac_address": mac_schema,
226 "vlan": vlan_schema,
227 },
garciadeblas4568a372021-03-24 09:19:48 +0100228 "additionalProperties": True,
229 },
tierno2a929042020-03-10 16:34:25 +0000230 },
231 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000232 },
garciadeblas4568a372021-03-24 09:19:48 +0100233 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000234}
235
tierno441dbbf2018-07-10 12:52:48 +0200236ns_instantiate_internal_vld = {
garciadeblas9fb32712022-04-04 16:33:59 +0200237 "title": "ns action instantiate input schema for vld",
tierno441dbbf2018-07-10 12:52:48 +0200238 "$schema": "http://json-schema.org/draft-04/schema#",
239 "type": "object",
240 "properties": {
241 "name": name_schema,
242 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100243 "vim-network-id": name_schema,
garciadeblas120105b2023-02-22 16:52:24 +0100244 "ip-profile": ip_profile_schema,
kbsub21f03f52019-10-17 16:26:56 +0000245 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200246 "internal-connection-point": {
247 "type": "array",
248 "minItems": 1,
249 "items": {
250 "type": "object",
251 "properties": {
252 "id-ref": name_schema,
253 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200254 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200255 },
tiernob7c6f2a2018-09-03 14:32:10 +0200256 "required": ["id-ref"],
257 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100258 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200259 },
garciadeblas4568a372021-03-24 09:19:48 +0100260 },
tierno441dbbf2018-07-10 12:52:48 +0200261 },
262 "required": ["name"],
263 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100264 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200265}
tierno65acb4d2018-04-06 16:42:40 +0200266
tiernofd160572019-01-21 10:41:37 +0000267additional_params_for_vnf = {
268 "type": "array",
269 "items": {
270 "type": "object",
271 "properties": {
272 "member-vnf-index": name_schema,
273 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000274 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000275 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000276 "additionalParamsForVdu": {
277 "type": "array",
278 "items": {
279 "type": "object",
280 "properties": {
281 "vdu_id": name_schema,
282 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100283 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000284 },
tiernof62ac6a2020-04-29 13:46:13 +0000285 "required": ["vdu_id"],
286 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000287 "additionalProperties": False,
288 },
289 },
290 "additionalParamsForKdu": {
291 "type": "array",
292 "items": {
293 "type": "object",
294 "properties": {
295 "kdu_name": name_schema,
296 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000297 "kdu_model": name_schema,
298 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100299 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200300 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000301 },
tierno54db2e42020-04-06 15:29:42 +0000302 "required": ["kdu_name"],
303 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000304 "additionalProperties": False,
305 },
306 },
Alexis Romeroee31f532022-04-26 19:10:21 +0200307 "affinity-or-anti-affinity-group": {
308 "type": "array",
309 "items": {
310 "type": "object",
311 "properties": {
312 "id": name_schema,
313 "vim-affinity-group-id": name_schema,
314 },
315 "required": ["id"],
316 "minProperties": 2,
317 "additionalProperties": False,
318 },
319 },
tiernofd160572019-01-21 10:41:37 +0000320 },
tierno714954e2019-11-29 13:43:26 +0000321 "required": ["member-vnf-index"],
322 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100323 "additionalProperties": False,
324 },
tiernofd160572019-01-21 10:41:37 +0000325}
326
tierno65acb4d2018-04-06 16:42:40 +0200327ns_instantiate = {
328 "title": "ns action instantiate input schema",
329 "$schema": "http://json-schema.org/draft-04/schema#",
330 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200331 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200332 "lcmOperationType": string_schema,
333 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100334 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200335 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000336 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200337 "nsdId": id_schema,
338 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000339 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100340 "placement-engine": string_schema,
341 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000342 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000343 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100344 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000345 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100346 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000347 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200348 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200349 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200350 "vnf": {
351 "type": "array",
352 "minItems": 1,
353 "items": {
354 "type": "object",
355 "properties": {
356 "member-vnf-index": name_schema,
357 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200358 "vdu": {
359 "type": "array",
360 "minItems": 1,
361 "items": ns_instantiate_vdu,
362 },
363 "internal-vld": {
364 "type": "array",
365 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100366 "items": ns_instantiate_internal_vld,
367 },
tierno0da52252018-06-27 15:47:22 +0200368 },
tierno441dbbf2018-07-10 12:52:48 +0200369 "required": ["member-vnf-index"],
370 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100371 "additionalProperties": False,
372 },
tierno0da52252018-06-27 15:47:22 +0200373 },
374 "vld": {
375 "type": "array",
376 "minItems": 1,
377 "items": {
378 "type": "object",
379 "properties": {
380 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000381 "vim-network-name": {"oneOf": [string_schema, object_schema]},
382 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100383 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000384 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
garciadeblas120105b2023-02-22 16:52:24 +0100385 "ip-profile": ip_profile_schema,
kbsub21f03f52019-10-17 16:26:56 +0000386 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200387 "vnfd-connection-point-ref": {
388 "type": "array",
389 "minItems": 1,
390 "items": {
391 "type": "object",
392 "properties": {
393 "member-vnf-index-ref": name_schema,
394 "vnfd-connection-point-ref": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200395 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernob7c6f2a2018-09-03 14:32:10 +0200396 # "mac-address": mac_schema,
397 },
garciadeblas4568a372021-03-24 09:19:48 +0100398 "required": [
399 "member-vnf-index-ref",
400 "vnfd-connection-point-ref",
401 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200402 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100403 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200404 },
garciadeblas4568a372021-03-24 09:19:48 +0100405 },
tierno0da52252018-06-27 15:47:22 +0200406 },
tierno441dbbf2018-07-10 12:52:48 +0200407 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100408 "additionalProperties": False,
409 },
tierno0da52252018-06-27 15:47:22 +0200410 },
411 },
tierno441dbbf2018-07-10 12:52:48 +0200412 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100413 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200414}
tierno0da52252018-06-27 15:47:22 +0200415
tierno1c38f2f2020-03-24 11:51:39 +0000416ns_terminate = {
417 "title": "ns terminate input schema",
418 "$schema": "http://json-schema.org/draft-04/schema#",
419 "type": "object",
420 "properties": {
421 "lcmOperationType": string_schema,
422 "nsInstanceId": id_schema,
423 "autoremove": bool_schema,
424 "timeout_ns_terminate": integer1_schema,
425 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000426 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000427 },
garciadeblas4568a372021-03-24 09:19:48 +0100428 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000429}
430
aticig544a2ae2022-04-05 09:00:17 +0300431ns_update = {
432 "title": "ns update input schema",
433 "$schema": "http://json-schema.org/draft-04/schema#",
434 "type": "object",
435 "properties": {
436 "lcmOperationType": string_schema,
437 "nsInstanceId": id_schema,
garciadeblaseab15072022-05-19 10:31:52 +0200438 "timeout_ns_update": integer1_schema,
aticig544a2ae2022-04-05 09:00:17 +0300439 "updateType": {
garciadeblasf2af4a12023-01-24 16:56:54 +0100440 "enum": [
441 "CHANGE_VNFPKG",
442 "REMOVE_VNF",
443 "MODIFY_VNF_INFORMATION",
444 "OPERATE_VNF",
445 ]
aticig544a2ae2022-04-05 09:00:17 +0300446 },
447 "modifyVnfInfoData": {
448 "type": "object",
449 "properties": {
450 "vnfInstanceId": id_schema,
451 "vnfdId": id_schema,
452 },
453 "required": ["vnfInstanceId", "vnfdId"],
454 },
455 "removeVnfInstanceId": id_schema,
456 "changeVnfPackageData": {
457 "type": "object",
458 "properties": {
459 "vnfInstanceId": id_schema,
460 "vnfdId": id_schema,
461 },
462 "required": ["vnfInstanceId", "vnfdId"],
463 },
k4.rahule3dca382022-04-29 12:30:36 +0000464 "operateVnfData": {
465 "type": "object",
466 "properties": {
467 "vnfInstanceId": id_schema,
468 "changeStateTo": name_schema,
469 "additionalParam": {
470 "type": "object",
471 "properties": {
472 "run-day1": bool_schema,
473 "vdu_id": name_schema,
474 "count-index": integer0_schema,
475 },
476 "required": ["vdu_id", "count-index"],
477 "additionalProperties": False,
garciadeblasf2af4a12023-01-24 16:56:54 +0100478 },
k4.rahule3dca382022-04-29 12:30:36 +0000479 },
480 "required": ["vnfInstanceId", "changeStateTo"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100481 },
aticig544a2ae2022-04-05 09:00:17 +0300482 },
483 "required": ["updateType"],
484 "additionalProperties": False,
485}
486
garciadeblas4568a372021-03-24 09:19:48 +0100487ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200488 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200489 "$schema": "http://json-schema.org/draft-04/schema#",
490 "type": "object",
491 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200492 "lcmOperationType": string_schema,
493 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200494 "member_vnf_index": name_schema,
495 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200496 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000497 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000498 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200499 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000500 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200501 "primitive_params": {"type": "object"},
502 },
garciadeblas4568a372021-03-24 09:19:48 +0100503 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
504 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200505}
garciadeblas0964edf2022-02-11 00:43:44 +0100506
garciadeblas4568a372021-03-24 09:19:48 +0100507ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200508 "title": "ns scale input schema",
509 "$schema": "http://json-schema.org/draft-04/schema#",
510 "type": "object",
511 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200512 "lcmOperationType": string_schema,
513 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200514 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000515 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200516 "scaleVnfData": {
517 "type": "object",
518 "properties": {
519 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100520 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200521 "scaleByStepData": {
522 "type": "object",
523 "properties": {
524 "scaling-group-descriptor": name_schema,
525 "member-vnf-index": name_schema,
526 "scaling-policy": name_schema,
527 },
528 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100529 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200530 },
531 },
532 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100533 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200534 },
535 "scaleTime": time_schema,
536 },
537 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100538 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200539}
tierno65acb4d2018-04-06 16:42:40 +0200540
elumalai8e3806c2022-04-28 17:26:24 +0530541ns_migrate = {
542 "title": "ns migrate input schema",
543 "$schema": "http://json-schema.org/draft-04/schema#",
544 "type": "object",
545 "properties": {
546 "lcmOperationType": string_schema,
547 "nsInstanceId": id_schema,
548 "vnfInstanceId": id_schema,
549 "migrateToHost": string_schema,
550 "vdu": {
551 "type": "object",
garciadeblasf2af4a12023-01-24 16:56:54 +0100552 "properties": {
553 "vduId": name_schema,
554 "vduCountIndex": integer0_schema,
555 },
556 "required": ["vduId"],
557 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530558 },
559 },
560 "required": ["vnfInstanceId"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100561 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530562}
tierno65acb4d2018-04-06 16:42:40 +0200563
garciadeblas0964edf2022-02-11 00:43:44 +0100564ns_heal = {
565 "title": "ns heal input schema",
566 "$schema": "http://json-schema.org/draft-04/schema#",
567 "type": "object",
568 "properties": {
569 "lcmOperationType": string_schema,
570 "nsInstanceId": id_schema,
571 "timeout_ns_heal": integer1_schema,
572 "healVnfData": {
573 "type": "array",
574 "items": {
575 "type": "object",
576 "properties": {
577 "vnfInstanceId": id_schema,
578 "cause": description_schema,
579 "additionalParams": {
580 "type": "object",
581 "properties": {
582 "run-day1": bool_schema,
583 "vdu": {
584 "type": "array",
585 "items": {
586 "type": "object",
587 "properties": {
588 "run-day1": bool_schema,
589 "vdu-id": name_schema,
590 "count-index": integer0_schema,
591 },
592 "required": ["vdu-id"],
593 "additionalProperties": False,
594 },
595 },
596 },
597 "additionalProperties": False,
598 },
599 },
600 "required": ["vnfInstanceId"],
601 "additionalProperties": False,
602 },
603 },
604 },
605 "required": ["healVnfData"],
606 "additionalProperties": False,
607}
608
govindarajul519da482022-04-29 19:05:22 +0530609ns_verticalscale = {
610 "title": "vertial scale input schema",
611 "$schema": "http://json-schema.org/draft-04/schema#",
612 "type": "object",
613 "properties": {
614 "lcmOperationType": string_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000615 "verticalScale": string_schema,
govindarajul519da482022-04-29 19:05:22 +0530616 "nsInstanceId": id_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000617 "changeVnfFlavorData": {
govindarajul519da482022-04-29 19:05:22 +0530618 "type": "object",
govindarajul69964ec2022-07-06 10:24:38 +0000619 "properties": {
620 "vnfInstanceId": id_schema,
621 "additionalParams": {
622 "type": "object",
623 "properties": {
624 "vduid": string_schema,
625 "vduCountIndex": integer0_schema,
626 "virtualMemory": integer1_schema,
627 "sizeOfStorage": integer0_schema,
628 "numVirtualCpu": integer1_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +0100629 },
govindarajul519da482022-04-29 19:05:22 +0530630 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100631 },
govindarajul69964ec2022-07-06 10:24:38 +0000632 "required": ["vnfInstanceId", "additionalParams"],
633 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530634 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100635 },
govindarajul69964ec2022-07-06 10:24:38 +0000636 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
637 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530638}
639
tierno0f98af52018-03-19 10:28:22 +0100640schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000641schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000642vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200643
tierno09c073e2018-04-26 13:36:48 +0200644vim_account_edit_schema = {
645 "title": "vim_account edit input schema",
646 "$schema": "http://json-schema.org/draft-04/schema#",
647 "type": "object",
648 "properties": {
649 "name": name_schema,
650 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200651 "vim": name_schema,
652 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200653 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200654 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200655 # "vim_url_admin": description_schema,
656 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200657 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200658 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200659 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200660 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100661 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000662 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200663 },
garciadeblas4568a372021-03-24 09:19:48 +0100664 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200665}
tierno0f98af52018-03-19 10:28:22 +0100666
tierno09c073e2018-04-26 13:36:48 +0200667vim_account_new_schema = {
668 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100669 "$schema": "http://json-schema.org/draft-04/schema#",
670 "type": "object",
671 "properties": {
672 "schema_version": schema_version,
673 "schema_type": schema_type,
674 "name": name_schema,
675 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200676 "vim": name_schema,
677 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200678 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100679 "vim_url": description_schema,
680 # "vim_url_admin": description_schema,
681 # "vim_tenant": name_schema,
682 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200683 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200684 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200685 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100686 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000687 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100688 },
garciadeblas4568a372021-03-24 09:19:48 +0100689 "required": [
690 "name",
691 "vim_url",
692 "vim_type",
693 "vim_user",
694 "vim_password",
695 "vim_tenant_name",
696 ],
697 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100698}
tierno0f98af52018-03-19 10:28:22 +0100699
tierno85807722019-12-20 14:11:35 +0000700wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200701
tierno55ba2e62018-12-11 17:22:22 +0000702wim_account_edit_schema = {
703 "title": "wim_account edit input schema",
704 "$schema": "http://json-schema.org/draft-04/schema#",
705 "type": "object",
706 "properties": {
707 "name": name_schema,
708 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000709 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200710 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000711 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100712 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000713 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100714 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000715 },
garciadeblas4568a372021-03-24 09:19:48 +0100716 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000717}
718
719wim_account_new_schema = {
720 "title": "wim_account creation input schema",
721 "$schema": "http://json-schema.org/draft-04/schema#",
722 "type": "object",
723 "properties": {
724 "schema_version": schema_version,
725 "schema_type": schema_type,
726 "name": name_schema,
727 "description": description_schema,
728 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200729 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000730 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100731 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000732 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000733 "config": {
734 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100735 "patternProperties": {".": {"not": {"type": "null"}}},
736 },
tierno55ba2e62018-12-11 17:22:22 +0000737 },
738 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100739 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000740}
tierno0f98af52018-03-19 10:28:22 +0100741
742sdn_properties = {
743 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000744 "type": {"type": "string"},
745 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100746 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000747 "password": passwd_schema,
748 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200749 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000750 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200751 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100752 "ip": ip_schema,
753 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100754 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100755}
756sdn_new_schema = {
757 "title": "sdn controller information schema",
758 "$schema": "http://json-schema.org/draft-04/schema#",
759 "type": "object",
760 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100761 "required": ["name", "type"],
762 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100763}
764sdn_edit_schema = {
765 "title": "sdn controller update information schema",
766 "$schema": "http://json-schema.org/draft-04/schema#",
767 "type": "object",
768 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200769 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100770 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100771}
772sdn_port_mapping_schema = {
773 "$schema": "http://json-schema.org/draft-04/schema#",
774 "title": "sdn port mapping information schema",
775 "type": "array",
776 "items": {
777 "type": "object",
778 "properties": {
tiernofd160572019-01-21 10:41:37 +0000779 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100780 "ports": {
781 "type": "array",
782 "items": {
783 "type": "object",
784 "properties": {
tierno42fce592018-11-02 09:23:43 +0100785 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000786 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100787 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100788 },
garciadeblas4568a372021-03-24 09:19:48 +0100789 "required": ["pci"],
790 },
791 },
tierno0f98af52018-03-19 10:28:22 +0100792 },
garciadeblas4568a372021-03-24 09:19:48 +0100793 "required": ["compute_node", "ports"],
794 },
tierno0f98af52018-03-19 10:28:22 +0100795}
796sdn_external_port_schema = {
797 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200798 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100799 "type": "object",
800 "properties": {
801 "port": {"type": "string", "minLength": 1, "maxLength": 60},
802 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100803 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100804 },
garciadeblas4568a372021-03-24 09:19:48 +0100805 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100806}
807
delacruzramofe598fe2019-10-23 18:25:11 +0200808# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500809k8scluster_deploy_method_schema = {
810 "$schema": "http://json-schema.org/draft-04/schema#",
811 "title": "Deployment methods for K8s cluster",
812 "type": "object",
813 "properties": {
814 "helm-chart": {"type": "boolean"},
815 "juju-bundle": {"type": "boolean"},
816 "helm-chart-v3": {"type": "boolean"},
817 },
818 "additionalProperties": False,
819 "minProperties": 3,
820}
delacruzramofe598fe2019-10-23 18:25:11 +0200821k8scluster_nets_schema = {
822 "title": "k8scluster nets input schema",
823 "$schema": "http://json-schema.org/draft-04/schema#",
824 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000825 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200826 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100827 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200828}
829k8scluster_new_schema = {
830 "title": "k8scluster creation input schema",
831 "$schema": "http://json-schema.org/draft-04/schema#",
832 "type": "object",
833 "properties": {
834 "schema_version": schema_version,
835 "schema_type": schema_type,
836 "name": name_schema,
837 "description": description_schema,
838 "credentials": object_schema,
839 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200840 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200841 "k8s_version": string_schema,
842 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500843 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200844 "namespace": name_schema,
845 "cni": nameshort_list_schema,
846 },
847 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100848 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200849}
850k8scluster_edit_schema = {
851 "title": "vim_account edit input schema",
852 "$schema": "http://json-schema.org/draft-04/schema#",
853 "type": "object",
854 "properties": {
855 "name": name_schema,
856 "description": description_schema,
857 "credentials": object_schema,
858 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200859 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200860 "k8s_version": string_schema,
861 "nets": k8scluster_nets_schema,
862 "namespace": name_schema,
863 "cni": nameshort_list_schema,
864 },
garciadeblas4568a372021-03-24 09:19:48 +0100865 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200866}
867
David Garciaecb41322021-03-31 19:10:46 +0200868# VCA
869vca_new_schema = {
870 "title": "vca creation input schema",
871 "$schema": "http://json-schema.org/draft-04/schema#",
872 "type": "object",
873 "properties": {
874 "schema_version": schema_version,
875 "schema_type": schema_type,
876 "name": name_schema,
877 "description": description_schema,
878 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100879 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200880 "secret": passwd_schema,
881 "cacert": long_description_schema,
882 "lxd-cloud": shortname_schema,
883 "lxd-credentials": shortname_schema,
884 "k8s-cloud": shortname_schema,
885 "k8s-credentials": shortname_schema,
886 "model-config": object_schema,
887 },
888 "required": [
889 "name",
890 "endpoints",
891 "user",
892 "secret",
893 "cacert",
894 "lxd-cloud",
895 "lxd-credentials",
896 "k8s-cloud",
897 "k8s-credentials",
898 ],
899 "additionalProperties": False,
900}
901vca_edit_schema = {
902 "title": "vca creation input schema",
903 "$schema": "http://json-schema.org/draft-04/schema#",
904 "type": "object",
905 "properties": {
906 "name": name_schema,
907 "description": description_schema,
908 "endpoints": description_list_schema,
909 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100910 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200911 "secret": passwd_schema,
912 "cacert": long_description_schema,
913 "lxd-cloud": shortname_schema,
914 "lxd-credentials": shortname_schema,
915 "k8s-cloud": shortname_schema,
916 "k8s-credentials": shortname_schema,
917 "model-config": object_schema,
918 },
919 "additionalProperties": False,
920}
921
delacruzramofe598fe2019-10-23 18:25:11 +0200922# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000923k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200924k8srepo_properties = {
925 "name": name_schema,
926 "description": description_schema,
927 "type": k8srepo_types,
928 "url": description_schema,
929}
930k8srepo_new_schema = {
931 "title": "k8scluster creation input schema",
932 "$schema": "http://json-schema.org/draft-04/schema#",
933 "type": "object",
934 "properties": k8srepo_properties,
935 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100936 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200937}
938k8srepo_edit_schema = {
939 "title": "vim_account edit input schema",
940 "$schema": "http://json-schema.org/draft-04/schema#",
941 "type": "object",
942 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100943 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200944}
945
Felipe Vicensb66b0412020-05-06 10:11:00 +0200946# OSM Repos
947osmrepo_types = {"enum": ["osm"]}
948osmrepo_properties = {
949 "name": name_schema,
950 "description": description_schema,
951 "type": osmrepo_types,
952 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100953 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200954 # "password": passwd_schema
955}
956osmrepo_new_schema = {
957 "title": "osm repo creation input schema",
958 "$schema": "http://json-schema.org/draft-04/schema#",
959 "type": "object",
960 "properties": osmrepo_properties,
961 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100962 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200963}
964osmrepo_edit_schema = {
965 "title": "osm repo edit input schema",
966 "$schema": "http://json-schema.org/draft-04/schema#",
967 "type": "object",
968 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100969 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200970}
971
tiernocb83c942018-09-24 17:28:13 +0200972# PDUs
973pdu_interface = {
974 "type": "object",
975 "properties": {
tiernofd160572019-01-21 10:41:37 +0000976 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200977 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100978 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200979 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200980 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100981 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000982 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
983 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100984 # # provide this in case SDN assist must deal with this interface
985 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000986 # "switch-port": shortname_schema,
987 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100988 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200989 },
tierno36ec8602018-11-02 17:27:11 +0100990 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100991 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200992}
tiernocb83c942018-09-24 17:28:13 +0200993pdu_new_schema = {
994 "title": "pdu creation input schema",
995 "$schema": "http://json-schema.org/draft-04/schema#",
996 "type": "object",
997 "properties": {
tiernofd160572019-01-21 10:41:37 +0000998 "name": shortname_schema,
999 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001000 "description": description_schema,
1001 "shared": bool_schema,
1002 "vims": nameshort_list_schema,
1003 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001004 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +02001005 },
1006 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +01001007 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +02001008}
tiernocb83c942018-09-24 17:28:13 +02001009pdu_edit_schema = {
1010 "title": "pdu edit input schema",
1011 "$schema": "http://json-schema.org/draft-04/schema#",
1012 "type": "object",
1013 "properties": {
tiernofd160572019-01-21 10:41:37 +00001014 "name": shortname_schema,
1015 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001016 "description": description_schema,
1017 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +01001018 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1019 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +01001020 "interfaces": {
1021 "oneOf": [
1022 array_edition_schema,
1023 {"type": "array", "items": pdu_interface, "minItems": 1},
1024 ]
1025 },
tiernocb83c942018-09-24 17:28:13 +02001026 },
1027 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001028 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001029}
1030
delacruzramo271d2002019-12-02 21:00:37 +01001031# VNF PKG OPERATIONS
1032vnfpkgop_new_schema = {
1033 "title": "VNF PKG operation creation input schema",
1034 "$schema": "http://json-schema.org/draft-04/schema#",
1035 "type": "object",
1036 "properties": {
1037 "lcmOperationType": string_schema,
1038 "vnfPkgId": id_schema,
1039 "kdu_name": name_schema,
1040 "primitive": name_schema,
1041 "primitive_params": {"type": "object"},
1042 },
garciadeblas4568a372021-03-24 09:19:48 +01001043 "required": [
1044 "lcmOperationType",
1045 "vnfPkgId",
1046 "kdu_name",
1047 "primitive",
1048 "primitive_params",
1049 ],
1050 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001051}
1052
tiernocb83c942018-09-24 17:28:13 +02001053# USERS
tiernocf042d32019-06-13 09:06:40 +00001054project_role_mappings = {
1055 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001056 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001057 "type": "array",
1058 "items": {
1059 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001060 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001061 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001062 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001063 },
garciadeblas4568a372021-03-24 09:19:48 +01001064 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001065}
1066project_role_mappings_optional = {
1067 "title": "list of projects/roles or projects only",
1068 "$schema": "http://json-schema.org/draft-04/schema#",
1069 "type": "array",
1070 "items": {
1071 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001072 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001073 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001074 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001075 },
garciadeblas4568a372021-03-24 09:19:48 +01001076 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001077}
tiernocd54a4a2018-09-12 16:40:35 +02001078user_new_schema = {
1079 "$schema": "http://json-schema.org/draft-04/schema#",
1080 "title": "New user schema",
1081 "type": "object",
1082 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001083 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001084 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001085 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001086 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001087 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001088 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001089 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001090 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001091}
1092user_edit_schema = {
1093 "$schema": "http://json-schema.org/draft-04/schema#",
1094 "title": "User edit schema for administrators",
1095 "type": "object",
1096 "properties": {
1097 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001098 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001099 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001100 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001101 "project_role_mappings": project_role_mappings,
1102 "add_project_role_mappings": project_role_mappings,
1103 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +02001104 },
1105 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001106 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001107}
1108
1109# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001110topics_with_quota = [
1111 "vnfds",
1112 "nsds",
1113 "slice_templates",
1114 "pduds",
1115 "ns_instances",
1116 "slice_instances",
1117 "vim_accounts",
1118 "wim_accounts",
1119 "sdn_controllers",
1120 "k8sclusters",
1121 "vca",
1122 "k8srepos",
1123 "osmrepos",
1124 "ns_subscriptions",
1125]
tiernocd54a4a2018-09-12 16:40:35 +02001126project_new_schema = {
1127 "$schema": "http://json-schema.org/draft-04/schema#",
1128 "title": "New project schema for administrators",
1129 "type": "object",
1130 "properties": {
tiernofd160572019-01-21 10:41:37 +00001131 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001132 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001133 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001134 "quotas": {
1135 "type": "object",
1136 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001137 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001138 },
tiernocd54a4a2018-09-12 16:40:35 +02001139 },
1140 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001141 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001142}
1143project_edit_schema = {
1144 "$schema": "http://json-schema.org/draft-04/schema#",
1145 "title": "Project edit schema for administrators",
1146 "type": "object",
1147 "properties": {
1148 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001149 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001150 "quotas": {
1151 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001152 "properties": {
1153 topic: {"oneOf": [integer0_schema, null_schema]}
1154 for topic in topics_with_quota
1155 },
1156 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001157 },
tiernocd54a4a2018-09-12 16:40:35 +02001158 },
1159 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001160 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001161}
1162
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001163# ROLES
1164roles_new_schema = {
1165 "$schema": "http://json-schema.org/draft-04/schema#",
1166 "title": "New role schema for administrators",
1167 "type": "object",
1168 "properties": {
1169 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001170 "permissions": {
1171 "type": "object",
1172 "patternProperties": {
1173 ".": bool_schema,
1174 },
1175 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001176 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001177 },
tierno1f029d82019-06-13 22:37:04 +00001178 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001179 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001180}
1181roles_edit_schema = {
1182 "$schema": "http://json-schema.org/draft-04/schema#",
1183 "title": "Roles edit schema for administrators",
1184 "type": "object",
1185 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001186 "name": shortname_schema,
1187 "permissions": {
1188 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001189 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001190 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001191 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001192 },
tierno1f029d82019-06-13 22:37:04 +00001193 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001194 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001195}
1196
tiernocd54a4a2018-09-12 16:40:35 +02001197# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001198
1199nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001200 "users": user_new_schema,
1201 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001202 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001203 "sdns": sdn_new_schema,
1204 "ns_instantiate": ns_instantiate,
1205 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001206 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001207 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001208 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001209 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001210}
1211
1212nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001213 "users": user_edit_schema,
1214 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001215 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001216 "sdns": sdn_edit_schema,
1217 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001218}
1219
Felipe Vicens07f31722018-10-29 15:16:44 +01001220# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001221nsi_subnet_instantiate = deepcopy(ns_instantiate)
1222nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1223nsi_subnet_instantiate["properties"]["id"] = name_schema
1224del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001225
1226nsi_vld_instantiate = {
1227 "title": "netslice vld instantiation params input schema",
1228 "$schema": "http://json-schema.org/draft-04/schema#",
1229 "type": "object",
1230 "properties": {
1231 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001232 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1233 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001234 "ip-profile": object_schema,
1235 },
delacruzramoc061f562019-04-05 11:00:02 +02001236 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001237 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001238}
1239
Felipe Vicens07f31722018-10-29 15:16:44 +01001240nsi_instantiate = {
1241 "title": "netslice action instantiate input schema",
1242 "$schema": "http://json-schema.org/draft-04/schema#",
1243 "type": "object",
1244 "properties": {
1245 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001246 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001247 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001248 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001249 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001250 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001251 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001252 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001253 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001254 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001255 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001256 "type": "array",
1257 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001258 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001259 },
garciadeblas4568a372021-03-24 09:19:48 +01001260 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001261 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001262 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001263 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001264}
1265
garciadeblas4568a372021-03-24 09:19:48 +01001266nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001267
garciadeblas4568a372021-03-24 09:19:48 +01001268nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001269
preethika.p329b8182020-04-22 12:25:39 +05301270nsinstancesubscriptionfilter_schema = {
1271 "title": "instance identifier schema",
1272 "$schema": "http://json-schema.org/draft-07/schema#",
1273 "type": "object",
1274 "properties": {
1275 "nsdIds": {"type": "array"},
1276 "vnfdIds": {"type": "array"},
1277 "pnfdIds": {"type": "array"},
1278 "nsInstanceIds": {"type": "array"},
1279 "nsInstanceNames": {"type": "array"},
1280 },
1281}
1282
1283nslcmsub_schema = {
1284 "title": "nslcmsubscription input schema",
1285 "$schema": "http://json-schema.org/draft-07/schema#",
1286 "type": "object",
1287 "properties": {
1288 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1289 "notificationTypes": {
1290 "type": "array",
1291 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001292 "enum": [
1293 "NsLcmOperationOccurrenceNotification",
1294 "NsChangeNotification",
1295 "NsIdentifierCreationNotification",
1296 "NsIdentifierDeletionNotification",
1297 ]
1298 },
preethika.p329b8182020-04-22 12:25:39 +05301299 },
1300 "operationTypes": {
1301 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001302 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301303 },
1304 "operationStates": {
1305 "type": "array",
1306 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001307 "enum": [
1308 "PROCESSING",
1309 "COMPLETED",
1310 "PARTIALLY_COMPLETED",
1311 "FAILED",
1312 "FAILED_TEMP",
1313 "ROLLING_BACK",
1314 "ROLLED_BACK",
1315 ]
1316 },
preethika.p329b8182020-04-22 12:25:39 +05301317 },
garciadeblas4568a372021-03-24 09:19:48 +01001318 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301319 "lcmOpNameImpactingNsComponent": {
1320 "type": "array",
1321 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001322 "enum": [
1323 "VNF_INSTANTIATE",
1324 "VNF_SCALE",
1325 "VNF_SCALE_TO_LEVEL",
1326 "VNF_CHANGE_FLAVOUR",
1327 "VNF_TERMINATE",
1328 "VNF_HEAL",
1329 "VNF_OPERATE",
1330 "VNF_CHANGE_EXT_CONN",
1331 "VNF_MODIFY_INFO",
1332 "NS_INSTANTIATE",
1333 "NS_SCALE",
1334 "NS_UPDATE",
1335 "NS_TERMINATE",
1336 "NS_HEAL",
1337 ]
1338 },
preethika.p329b8182020-04-22 12:25:39 +05301339 },
1340 "lcmOpOccStatusImpactingNsComponent": {
1341 "type": "array",
1342 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001343 "enum": [
1344 "START",
1345 "COMPLETED",
1346 "PARTIALLY_COMPLETED",
1347 "FAILED",
1348 "ROLLED_BACK",
1349 ]
1350 },
preethika.p329b8182020-04-22 12:25:39 +05301351 },
1352 },
1353 "allOf": [
1354 {
1355 "if": {
1356 "properties": {
1357 "notificationTypes": {
1358 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1359 }
1360 },
1361 },
1362 "then": {
1363 "anyOf": [
1364 {"required": ["operationTypes"]},
1365 {"required": ["operationStates"]},
1366 ]
garciadeblas4568a372021-03-24 09:19:48 +01001367 },
preethika.p329b8182020-04-22 12:25:39 +05301368 },
1369 {
1370 "if": {
1371 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001372 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301373 },
1374 },
1375 "then": {
1376 "anyOf": [
1377 {"required": ["nsComponentTypes"]},
1378 {"required": ["lcmOpNameImpactingNsComponent"]},
1379 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1380 ]
garciadeblas4568a372021-03-24 09:19:48 +01001381 },
1382 },
1383 ],
preethika.p329b8182020-04-22 12:25:39 +05301384}
1385
1386authentication_schema = {
1387 "title": "authentication schema for subscription",
1388 "$schema": "http://json-schema.org/draft-07/schema#",
1389 "type": "object",
1390 "properties": {
1391 "authType": {"enum": ["basic"]},
1392 "paramsBasic": {
1393 "type": "object",
1394 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001395 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301396 "password": passwd_schema,
1397 },
1398 },
1399 },
1400}
1401
1402subscription = {
1403 "title": "subscription input schema",
1404 "$schema": "http://json-schema.org/draft-07/schema#",
1405 "type": "object",
1406 "properties": {
1407 "filter": nslcmsub_schema,
1408 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001409 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301410 },
1411 "required": ["CallbackUri"],
1412}
1413
selvi.jf1004592022-04-29 05:42:35 +00001414vnflcmsub_schema = {
1415 "title": "vnflcmsubscription input schema",
1416 "$schema": "http://json-schema.org/draft-07/schema#",
1417 "type": "object",
1418 "properties": {
1419 "VnfInstanceSubscriptionFilter": {
1420 "type": "object",
1421 "properties": {
1422 "vnfdIds": {"type": "array"},
1423 "vnfInstanceIds": {"type": "array"},
1424 },
1425 },
1426 "notificationTypes": {
1427 "type": "array",
1428 "items": {
1429 "enum": [
1430 "VnfIdentifierCreationNotification",
1431 "VnfLcmOperationOccurrenceNotification",
garciadeblasf2af4a12023-01-24 16:56:54 +01001432 "VnfIdentifierDeletionNotification",
1433 ]
1434 },
selvi.jf1004592022-04-29 05:42:35 +00001435 },
1436 "operationTypes": {
1437 "type": "array",
1438 "items": {
1439 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001440 "INSTANTIATE",
1441 "SCALE",
1442 "SCALE_TO_LEVEL",
1443 "CHANGE_FLAVOUR",
1444 "TERMINATE",
1445 "HEAL",
1446 "OPERATE",
1447 "CHANGE_EXT_CONN",
1448 "MODIFY_INFO",
1449 "CREATE_SNAPSHOT",
1450 "REVERT_TO_SNAPSHOT",
1451 "CHANGE_VNFPKG",
1452 ]
1453 },
selvi.jf1004592022-04-29 05:42:35 +00001454 },
1455 "operationStates": {
1456 "type": "array",
1457 "items": {
1458 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001459 "STARTING",
1460 "PROCESSING",
1461 "COMPLETED",
1462 "FAILED_TEMP",
1463 "FAILED",
1464 "ROLLING_BACK",
1465 "ROLLED_BACK",
1466 ]
1467 },
1468 },
selvi.jf1004592022-04-29 05:42:35 +00001469 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001470 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1471}
selvi.jf1004592022-04-29 05:42:35 +00001472
1473vnf_subscription = {
1474 "title": "vnf subscription input schema",
1475 "$schema": "http://json-schema.org/draft-07/schema#",
1476 "type": "object",
1477 "properties": {
1478 "filter": vnflcmsub_schema,
1479 "CallbackUri": description_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +01001480 "authentication": authentication_schema,
selvi.jf1004592022-04-29 05:42:35 +00001481 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001482 "required": ["filter", "CallbackUri"],
selvi.jf1004592022-04-29 05:42:35 +00001483}
1484
tierno0f98af52018-03-19 10:28:22 +01001485
1486class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001487 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1488 self.http_code = http_code
1489 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001490
1491
tiernob24258a2018-10-04 18:39:49 +02001492def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001493 """
tiernocd54a4a2018-09-12 16:40:35 +02001494 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001495 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001496 :param schema_to_use: jsonschema to test
1497 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001498 """
1499 try:
tierno0f98af52018-03-19 10:28:22 +01001500 if schema_to_use:
1501 js_v(indata, schema_to_use)
1502 return None
1503 except js_e.ValidationError as e:
1504 if e.path:
tierno0da52252018-06-27 15:47:22 +02001505 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001506 else:
1507 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001508 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001509 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001510 raise ValidationError(
1511 "Bad json schema {}".format(schema_to_use),
1512 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1513 )
delacruzramoc061f562019-04-05 11:00:02 +02001514
1515
1516def is_valid_uuid(x):
1517 """
1518 Test for a valid UUID
1519 :param x: string to test
1520 :return: True if x is a valid uuid, False otherwise
1521 """
1522 try:
1523 if UUID(x):
1524 return True
tiernobdebce92019-07-01 15:36:49 +00001525 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001526 return False