blob: d282bdede6dea9e251a68255da10c4ea7c4381f6 [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}
garciadeblas6d83f8f2023-06-19 22:34:49 +020038user_passwd_schema = {
39 "type": "string",
40 "pattern": "^.*(?=.{8,})((?=.*[!@#$%^&*()\\-_=+{};:,<.>]){1})(?=.*\\d)((?=.*[a-z]){1})((?=.*[A-Z]){1}).*$",
41}
garciadeblas4568a372021-03-24 09:19:48 +010042name_schema = {
43 "type": "string",
44 "minLength": 1,
45 "maxLength": 255,
46 "pattern": "^[^,;()'\"]+$",
47}
tierno0da52252018-06-27 15:47:22 +020048string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
garciadeblas4568a372021-03-24 09:19:48 +010049xml_text_schema = {
50 "type": "string",
51 "minLength": 1,
52 "maxLength": 1000,
53 "pattern": "^[^']+$",
54}
55description_schema = {
56 "type": ["string", "null"],
57 "maxLength": 255,
58 "pattern": "^[^'\"]+$",
59}
60long_description_schema = {
61 "type": ["string", "null"],
62 "maxLength": 3000,
63 "pattern": "^[^'\"]+$",
64}
tierno441dbbf2018-07-10 12:52:48 +020065id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
66bool_schema = {"type": "boolean"}
67null_schema = {"type": "null"}
tierno2236d202018-05-16 19:05:16 +020068# "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 +010069id_schema = {
70 "type": "string",
71 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
72}
73time_schema = {
74 "type": "string",
75 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}",
76}
77pci_schema = {
78 "type": "string",
79 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$",
80}
tierno42fce592018-11-02 09:23:43 +010081# allows [] for wildcards. For that reason huge length limit is set
82pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
K Sai Kiran990ac462020-05-20 12:25:12 +053083http_schema = {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
tierno0f98af52018-03-19 10:28:22 +010084bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
85memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
86integer0_schema = {"type": "integer", "minimum": 0}
87integer1_schema = {"type": "integer", "minimum": 1}
tierno87006042018-10-24 12:50:20 +020088path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
tierno0f98af52018-03-19 10:28:22 +010089vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
90vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
garciadeblas4568a372021-03-24 09:19:48 +010091mac_schema = {
92 "type": "string",
93 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$",
94} # must be unicast: LSB bit of MSB byte ==0
tiernocb83c942018-09-24 17:28:13 +020095dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
tierno0f98af52018-03-19 10:28:22 +010096# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
garciadeblas4568a372021-03-24 09:19:48 +010097ip_schema = {
98 "type": "string",
99 "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]?)$",
100}
garciadeblas1a01e1f2021-10-26 17:27:35 +0200101ipv6_schema = {
102 "type": "string",
garciadeblasf2af4a12023-01-24 16:56:54 +0100103 "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 +0200104}
garciadeblas4568a372021-03-24 09:19:48 +0100105ip_prefix_schema = {
106 "type": "string",
107 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
108 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
109}
tierno0f98af52018-03-19 10:28:22 +0100110port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
111object_schema = {"type": "object"}
112schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
113# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
garciadeblas4568a372021-03-24 09:19:48 +0100114log_level_schema = {
115 "type": "string",
116 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
117}
tierno0f98af52018-03-19 10:28:22 +0100118checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
119size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +0200120array_edition_schema = {
121 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100122 "patternProperties": {"^\\$": {}},
tiernocd54a4a2018-09-12 16:40:35 +0200123 "additionalProperties": False,
124 "minProperties": 1,
125}
tiernocb83c942018-09-24 17:28:13 +0200126nameshort_list_schema = {
127 "type": "array",
128 "minItems": 1,
tiernofd160572019-01-21 10:41:37 +0000129 "items": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200130}
tiernocd54a4a2018-09-12 16:40:35 +0200131
David Garciaecb41322021-03-31 19:10:46 +0200132description_list_schema = {
133 "type": "array",
134 "minItems": 1,
135 "items": description_schema,
136}
tierno0f98af52018-03-19 10:28:22 +0100137
tierno441dbbf2018-07-10 12:52:48 +0200138ns_instantiate_vdu = {
139 "title": "ns action instantiate input schema for vdu",
140 "$schema": "http://json-schema.org/draft-04/schema#",
141 "type": "object",
142 "properties": {
143 "id": name_schema,
Gabriel Cubae88401b2023-04-05 15:24:52 -0500144 "vim-flavor-id": name_schema,
kayal20016a3bce72024-06-27 11:14:59 +0530145 "instance_name": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200146 "volume": {
147 "type": "array",
148 "minItems": 1,
149 "items": {
150 "type": "object",
151 "properties": {
152 "name": name_schema,
153 "vim-volume-id": name_schema,
154 },
155 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100156 "additionalProperties": False,
157 },
tierno441dbbf2018-07-10 12:52:48 +0200158 },
159 "interface": {
160 "type": "array",
161 "minItems": 1,
162 "items": {
163 "type": "object",
164 "properties": {
165 "name": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200166 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200167 "mac-address": mac_schema,
168 "floating-ip-required": bool_schema,
169 },
170 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100171 "additionalProperties": False,
172 },
173 },
tierno441dbbf2018-07-10 12:52:48 +0200174 },
175 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100176 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200177}
178
179ip_profile_dns_schema = {
180 "type": "array",
181 "minItems": 1,
182 "items": {
183 "type": "object",
184 "properties": {
garciadeblas9fb32712022-04-04 16:33:59 +0200185 "address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200186 },
187 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100188 "additionalProperties": False,
189 },
tierno441dbbf2018-07-10 12:52:48 +0200190}
191
192ip_profile_dhcp_schema = {
193 "type": "object",
194 "properties": {
195 "enabled": {"type": "boolean"},
196 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100197 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200198 },
199 "additionalProperties": False,
200}
201
202ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000203 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200204 "$schema": "http://json-schema.org/draft-04/schema#",
205 "type": "object",
206 "properties": {
207 "ip-version": {"enum": ["ipv4", "ipv6"]},
tierno441dbbf2018-07-10 12:52:48 +0200208 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
209 "gateway-address": {"oneOf": [null_schema, ip_schema]},
210 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200211 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
212 },
garciadeblas4568a372021-03-24 09:19:48 +0100213 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200214}
215
kbsub21f03f52019-10-17 16:26:56 +0000216provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000217 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000218 "$schema": "http://json-schema.org/draft-04/schema#",
219 "type": "object",
220 "properties": {
221 "physical-network": name_schema,
222 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000223 "sdn-ports": { # external ports to append to the SDN-assist network
224 "type": "array",
225 "items": {
226 "type": "object",
227 "properties": {
228 "switch_id": shortname_schema,
229 "switch_port": shortname_schema,
230 "mac_address": mac_schema,
231 "vlan": vlan_schema,
232 },
garciadeblas4568a372021-03-24 09:19:48 +0100233 "additionalProperties": True,
234 },
tierno2a929042020-03-10 16:34:25 +0000235 },
236 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000237 },
garciadeblas4568a372021-03-24 09:19:48 +0100238 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000239}
240
tierno441dbbf2018-07-10 12:52:48 +0200241ns_instantiate_internal_vld = {
garciadeblas9fb32712022-04-04 16:33:59 +0200242 "title": "ns action instantiate input schema for vld",
tierno441dbbf2018-07-10 12:52:48 +0200243 "$schema": "http://json-schema.org/draft-04/schema#",
244 "type": "object",
245 "properties": {
246 "name": name_schema,
247 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100248 "vim-network-id": name_schema,
garciadeblas120105b2023-02-22 16:52:24 +0100249 "ip-profile": ip_profile_schema,
kbsub21f03f52019-10-17 16:26:56 +0000250 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200251 "internal-connection-point": {
252 "type": "array",
253 "minItems": 1,
254 "items": {
255 "type": "object",
256 "properties": {
257 "id-ref": name_schema,
258 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200259 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200260 },
tiernob7c6f2a2018-09-03 14:32:10 +0200261 "required": ["id-ref"],
262 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100263 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200264 },
garciadeblas4568a372021-03-24 09:19:48 +0100265 },
tierno441dbbf2018-07-10 12:52:48 +0200266 },
267 "required": ["name"],
268 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100269 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200270}
tierno65acb4d2018-04-06 16:42:40 +0200271
tiernofd160572019-01-21 10:41:37 +0000272additional_params_for_vnf = {
273 "type": "array",
274 "items": {
275 "type": "object",
276 "properties": {
277 "member-vnf-index": name_schema,
278 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000279 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000280 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000281 "additionalParamsForVdu": {
282 "type": "array",
283 "items": {
284 "type": "object",
285 "properties": {
286 "vdu_id": name_schema,
287 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100288 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000289 },
tiernof62ac6a2020-04-29 13:46:13 +0000290 "required": ["vdu_id"],
291 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000292 "additionalProperties": False,
293 },
294 },
295 "additionalParamsForKdu": {
296 "type": "array",
297 "items": {
298 "type": "object",
299 "properties": {
300 "kdu_name": name_schema,
301 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000302 "kdu_model": name_schema,
303 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100304 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200305 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000306 },
tierno54db2e42020-04-06 15:29:42 +0000307 "required": ["kdu_name"],
308 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000309 "additionalProperties": False,
310 },
311 },
Alexis Romeroee31f532022-04-26 19:10:21 +0200312 "affinity-or-anti-affinity-group": {
313 "type": "array",
314 "items": {
315 "type": "object",
316 "properties": {
317 "id": name_schema,
318 "vim-affinity-group-id": name_schema,
319 },
320 "required": ["id"],
321 "minProperties": 2,
322 "additionalProperties": False,
323 },
324 },
tiernofd160572019-01-21 10:41:37 +0000325 },
tierno714954e2019-11-29 13:43:26 +0000326 "required": ["member-vnf-index"],
327 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100328 "additionalProperties": False,
329 },
tiernofd160572019-01-21 10:41:37 +0000330}
331
kayal2001f71c2e82024-06-25 15:26:24 +0530332vnf_schema = {
333 "type": "array",
334 "minItems": 1,
335 "items": {
336 "type": "object",
337 "properties": {
338 "member-vnf-index": name_schema,
339 "vimAccountId": id_schema,
340 "vdu": {
341 "type": "array",
342 "minItems": 1,
343 "items": ns_instantiate_vdu,
344 },
345 "internal-vld": {
346 "type": "array",
347 "minItems": 1,
348 "items": ns_instantiate_internal_vld,
349 },
350 },
351 "required": ["member-vnf-index"],
352 "minProperties": 2,
353 "additionalProperties": False,
354 },
355}
356
357vld_schema = {
358 "type": "array",
359 "minItems": 1,
360 "items": {
361 "type": "object",
362 "properties": {
363 "name": string_schema,
364 "vim-network-name": {"oneOf": [string_schema, object_schema]},
365 "vim-network-id": {"oneOf": [string_schema, object_schema]},
366 "ns-net": object_schema,
367 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
368 "ip-profile": ip_profile_schema,
369 "provider-network": provider_network_schema,
370 "vnfd-connection-point-ref": {
371 "type": "array",
372 "minItems": 1,
373 "items": {
374 "type": "object",
375 "properties": {
376 "member-vnf-index-ref": name_schema,
377 "vnfd-connection-point-ref": name_schema,
378 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
379 # "mac-address": mac_schema,
380 },
381 "required": [
382 "member-vnf-index-ref",
383 "vnfd-connection-point-ref",
384 ],
385 "minProperties": 3,
386 "additionalProperties": False,
387 },
388 },
389 },
390 "required": ["name"],
391 "additionalProperties": False,
392 },
393}
394
395ns_config_template = {
396 "title": " ns config template input schema",
397 "$schema": "http://json-schema.org/draft-04/schema#",
398 "type": "object",
399 "properties": {
400 "name": string_schema,
401 "nsdId": id_schema,
402 "config": object_schema,
403 },
404 "required": ["name", "nsdId", "config"],
405 "additionalProperties": False,
406}
407
tierno65acb4d2018-04-06 16:42:40 +0200408ns_instantiate = {
409 "title": "ns action instantiate input schema",
410 "$schema": "http://json-schema.org/draft-04/schema#",
411 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200412 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200413 "lcmOperationType": string_schema,
414 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100415 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200416 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000417 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200418 "nsdId": id_schema,
419 "vimAccountId": id_schema,
kayal2001f71c2e82024-06-25 15:26:24 +0530420 "nsConfigTemplateId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000421 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100422 "placement-engine": string_schema,
423 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000424 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000425 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100426 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000427 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100428 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000429 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200430 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200431 "vduImage": name_schema,
kayal2001f71c2e82024-06-25 15:26:24 +0530432 "vnf": vnf_schema,
433 "vld": vld_schema,
tierno0da52252018-06-27 15:47:22 +0200434 },
tierno441dbbf2018-07-10 12:52:48 +0200435 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100436 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200437}
tierno0da52252018-06-27 15:47:22 +0200438
tierno1c38f2f2020-03-24 11:51:39 +0000439ns_terminate = {
440 "title": "ns terminate input schema",
441 "$schema": "http://json-schema.org/draft-04/schema#",
442 "type": "object",
443 "properties": {
444 "lcmOperationType": string_schema,
445 "nsInstanceId": id_schema,
446 "autoremove": bool_schema,
447 "timeout_ns_terminate": integer1_schema,
448 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000449 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000450 },
garciadeblas4568a372021-03-24 09:19:48 +0100451 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000452}
453
aticig544a2ae2022-04-05 09:00:17 +0300454ns_update = {
455 "title": "ns update input schema",
456 "$schema": "http://json-schema.org/draft-04/schema#",
457 "type": "object",
458 "properties": {
459 "lcmOperationType": string_schema,
460 "nsInstanceId": id_schema,
garciadeblaseab15072022-05-19 10:31:52 +0200461 "timeout_ns_update": integer1_schema,
aticig544a2ae2022-04-05 09:00:17 +0300462 "updateType": {
garciadeblasf2af4a12023-01-24 16:56:54 +0100463 "enum": [
464 "CHANGE_VNFPKG",
465 "REMOVE_VNF",
466 "MODIFY_VNF_INFORMATION",
467 "OPERATE_VNF",
Rahul Kumara30391b2024-05-24 14:40:23 +0530468 "VERTICAL_SCALE",
garciadeblasf2af4a12023-01-24 16:56:54 +0100469 ]
aticig544a2ae2022-04-05 09:00:17 +0300470 },
471 "modifyVnfInfoData": {
472 "type": "object",
473 "properties": {
474 "vnfInstanceId": id_schema,
475 "vnfdId": id_schema,
476 },
477 "required": ["vnfInstanceId", "vnfdId"],
478 },
479 "removeVnfInstanceId": id_schema,
480 "changeVnfPackageData": {
481 "type": "object",
482 "properties": {
483 "vnfInstanceId": id_schema,
484 "vnfdId": id_schema,
485 },
486 "required": ["vnfInstanceId", "vnfdId"],
487 },
k4.rahule3dca382022-04-29 12:30:36 +0000488 "operateVnfData": {
489 "type": "object",
490 "properties": {
491 "vnfInstanceId": id_schema,
492 "changeStateTo": name_schema,
493 "additionalParam": {
494 "type": "object",
495 "properties": {
496 "run-day1": bool_schema,
497 "vdu_id": name_schema,
498 "count-index": integer0_schema,
499 },
500 "required": ["vdu_id", "count-index"],
501 "additionalProperties": False,
garciadeblasf2af4a12023-01-24 16:56:54 +0100502 },
k4.rahule3dca382022-04-29 12:30:36 +0000503 },
504 "required": ["vnfInstanceId", "changeStateTo"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100505 },
Rahul Kumara30391b2024-05-24 14:40:23 +0530506 "verticalScaleVnf": {
507 "type": "object",
508 "properties": {
509 "vnfInstanceId": id_schema,
510 "vnfdId": id_schema,
511 "vduId": name_schema,
512 "countIndex": integer0_schema,
513 },
514 "required": ["vnfInstanceId", "vnfdId", "vduId"],
515 },
aticig544a2ae2022-04-05 09:00:17 +0300516 },
517 "required": ["updateType"],
518 "additionalProperties": False,
519}
520
garciadeblas4568a372021-03-24 09:19:48 +0100521ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200522 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200523 "$schema": "http://json-schema.org/draft-04/schema#",
524 "type": "object",
525 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200526 "lcmOperationType": string_schema,
527 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200528 "member_vnf_index": name_schema,
529 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200530 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000531 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000532 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200533 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000534 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200535 "primitive_params": {"type": "object"},
536 },
garciadeblas4568a372021-03-24 09:19:48 +0100537 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
538 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200539}
garciadeblas0964edf2022-02-11 00:43:44 +0100540
garciadeblas4568a372021-03-24 09:19:48 +0100541ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200542 "title": "ns scale input schema",
543 "$schema": "http://json-schema.org/draft-04/schema#",
544 "type": "object",
545 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200546 "lcmOperationType": string_schema,
547 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200548 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000549 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200550 "scaleVnfData": {
551 "type": "object",
552 "properties": {
553 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100554 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200555 "scaleByStepData": {
556 "type": "object",
557 "properties": {
558 "scaling-group-descriptor": name_schema,
559 "member-vnf-index": name_schema,
560 "scaling-policy": name_schema,
561 },
562 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100563 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200564 },
565 },
566 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100567 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200568 },
569 "scaleTime": time_schema,
570 },
571 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100572 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200573}
tierno65acb4d2018-04-06 16:42:40 +0200574
elumalai8e3806c2022-04-28 17:26:24 +0530575ns_migrate = {
576 "title": "ns migrate input schema",
577 "$schema": "http://json-schema.org/draft-04/schema#",
578 "type": "object",
579 "properties": {
580 "lcmOperationType": string_schema,
581 "nsInstanceId": id_schema,
582 "vnfInstanceId": id_schema,
583 "migrateToHost": string_schema,
584 "vdu": {
585 "type": "object",
garciadeblasf2af4a12023-01-24 16:56:54 +0100586 "properties": {
587 "vduId": name_schema,
588 "vduCountIndex": integer0_schema,
589 },
590 "required": ["vduId"],
591 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530592 },
593 },
594 "required": ["vnfInstanceId"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100595 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530596}
tierno65acb4d2018-04-06 16:42:40 +0200597
garciadeblas0964edf2022-02-11 00:43:44 +0100598ns_heal = {
599 "title": "ns heal input schema",
600 "$schema": "http://json-schema.org/draft-04/schema#",
601 "type": "object",
602 "properties": {
603 "lcmOperationType": string_schema,
604 "nsInstanceId": id_schema,
605 "timeout_ns_heal": integer1_schema,
606 "healVnfData": {
607 "type": "array",
608 "items": {
609 "type": "object",
610 "properties": {
611 "vnfInstanceId": id_schema,
612 "cause": description_schema,
613 "additionalParams": {
614 "type": "object",
615 "properties": {
616 "run-day1": bool_schema,
617 "vdu": {
618 "type": "array",
619 "items": {
620 "type": "object",
621 "properties": {
622 "run-day1": bool_schema,
623 "vdu-id": name_schema,
624 "count-index": integer0_schema,
625 },
626 "required": ["vdu-id"],
627 "additionalProperties": False,
628 },
629 },
630 },
631 "additionalProperties": False,
632 },
633 },
634 "required": ["vnfInstanceId"],
635 "additionalProperties": False,
636 },
637 },
638 },
639 "required": ["healVnfData"],
640 "additionalProperties": False,
641}
642
Gabriel Cuba84a60df2023-10-30 14:01:54 -0500643nslcmop_cancel = {
644 "title": "Cancel nslcmop input schema",
645 "$schema": "http://json-schema.org/draft-04/schema#",
646 "type": "object",
647 "properties": {
648 "nsLcmOpOccId": id_schema,
649 "cancelMode": {
650 "enum": [
651 "GRACEFUL",
652 "FORCEFUL",
653 ]
654 },
655 },
656 "required": ["cancelMode"],
657 "additionalProperties": False,
658}
659
tierno0f98af52018-03-19 10:28:22 +0100660schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000661schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000662vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200663
tierno09c073e2018-04-26 13:36:48 +0200664vim_account_edit_schema = {
665 "title": "vim_account edit input schema",
666 "$schema": "http://json-schema.org/draft-04/schema#",
667 "type": "object",
668 "properties": {
669 "name": name_schema,
670 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200671 "vim": name_schema,
672 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200673 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200674 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200675 # "vim_url_admin": description_schema,
676 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200677 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200678 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200679 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200680 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100681 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000682 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200683 },
garciadeblas4568a372021-03-24 09:19:48 +0100684 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200685}
tierno0f98af52018-03-19 10:28:22 +0100686
tierno09c073e2018-04-26 13:36:48 +0200687vim_account_new_schema = {
688 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100689 "$schema": "http://json-schema.org/draft-04/schema#",
690 "type": "object",
691 "properties": {
692 "schema_version": schema_version,
693 "schema_type": schema_type,
694 "name": name_schema,
695 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200696 "vim": name_schema,
697 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200698 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100699 "vim_url": description_schema,
700 # "vim_url_admin": description_schema,
701 # "vim_tenant": name_schema,
702 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200703 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200704 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200705 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100706 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000707 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100708 },
garciadeblas4568a372021-03-24 09:19:48 +0100709 "required": [
710 "name",
711 "vim_url",
712 "vim_type",
713 "vim_user",
714 "vim_password",
715 "vim_tenant_name",
716 ],
717 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100718}
tierno0f98af52018-03-19 10:28:22 +0100719
tierno85807722019-12-20 14:11:35 +0000720wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200721
tierno55ba2e62018-12-11 17:22:22 +0000722wim_account_edit_schema = {
723 "title": "wim_account edit input schema",
724 "$schema": "http://json-schema.org/draft-04/schema#",
725 "type": "object",
726 "properties": {
727 "name": name_schema,
728 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000729 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200730 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000731 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100732 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000733 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100734 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000735 },
garciadeblas4568a372021-03-24 09:19:48 +0100736 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000737}
738
739wim_account_new_schema = {
740 "title": "wim_account creation input schema",
741 "$schema": "http://json-schema.org/draft-04/schema#",
742 "type": "object",
743 "properties": {
744 "schema_version": schema_version,
745 "schema_type": schema_type,
746 "name": name_schema,
747 "description": description_schema,
748 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200749 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000750 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100751 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000752 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000753 "config": {
754 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100755 "patternProperties": {".": {"not": {"type": "null"}}},
756 },
tierno55ba2e62018-12-11 17:22:22 +0000757 },
758 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100759 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000760}
tierno0f98af52018-03-19 10:28:22 +0100761
762sdn_properties = {
763 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000764 "type": {"type": "string"},
765 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100766 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000767 "password": passwd_schema,
768 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200769 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000770 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200771 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100772 "ip": ip_schema,
773 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100774 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100775}
776sdn_new_schema = {
777 "title": "sdn controller information schema",
778 "$schema": "http://json-schema.org/draft-04/schema#",
779 "type": "object",
780 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100781 "required": ["name", "type"],
782 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100783}
784sdn_edit_schema = {
785 "title": "sdn controller update information schema",
786 "$schema": "http://json-schema.org/draft-04/schema#",
787 "type": "object",
788 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200789 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100790 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100791}
792sdn_port_mapping_schema = {
793 "$schema": "http://json-schema.org/draft-04/schema#",
794 "title": "sdn port mapping information schema",
795 "type": "array",
796 "items": {
797 "type": "object",
798 "properties": {
tiernofd160572019-01-21 10:41:37 +0000799 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100800 "ports": {
801 "type": "array",
802 "items": {
803 "type": "object",
804 "properties": {
tierno42fce592018-11-02 09:23:43 +0100805 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000806 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100807 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100808 },
garciadeblas4568a372021-03-24 09:19:48 +0100809 "required": ["pci"],
810 },
811 },
tierno0f98af52018-03-19 10:28:22 +0100812 },
garciadeblas4568a372021-03-24 09:19:48 +0100813 "required": ["compute_node", "ports"],
814 },
tierno0f98af52018-03-19 10:28:22 +0100815}
816sdn_external_port_schema = {
817 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200818 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100819 "type": "object",
820 "properties": {
821 "port": {"type": "string", "minLength": 1, "maxLength": 60},
822 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100823 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100824 },
garciadeblas4568a372021-03-24 09:19:48 +0100825 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100826}
827
delacruzramofe598fe2019-10-23 18:25:11 +0200828# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500829k8scluster_deploy_method_schema = {
830 "$schema": "http://json-schema.org/draft-04/schema#",
831 "title": "Deployment methods for K8s cluster",
832 "type": "object",
833 "properties": {
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500834 "juju-bundle": {"type": "boolean"},
835 "helm-chart-v3": {"type": "boolean"},
836 },
837 "additionalProperties": False,
Luis Vega0a1efed2023-11-28 16:44:30 +0000838 "minProperties": 2,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500839}
delacruzramofe598fe2019-10-23 18:25:11 +0200840k8scluster_nets_schema = {
841 "title": "k8scluster nets input schema",
842 "$schema": "http://json-schema.org/draft-04/schema#",
843 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000844 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200845 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100846 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200847}
848k8scluster_new_schema = {
849 "title": "k8scluster creation input schema",
850 "$schema": "http://json-schema.org/draft-04/schema#",
851 "type": "object",
852 "properties": {
853 "schema_version": schema_version,
854 "schema_type": schema_type,
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,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500862 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200863 "namespace": name_schema,
864 "cni": nameshort_list_schema,
865 },
866 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100867 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200868}
869k8scluster_edit_schema = {
870 "title": "vim_account edit input schema",
871 "$schema": "http://json-schema.org/draft-04/schema#",
872 "type": "object",
873 "properties": {
874 "name": name_schema,
875 "description": description_schema,
876 "credentials": object_schema,
877 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200878 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200879 "k8s_version": string_schema,
880 "nets": k8scluster_nets_schema,
881 "namespace": name_schema,
882 "cni": nameshort_list_schema,
883 },
garciadeblas4568a372021-03-24 09:19:48 +0100884 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200885}
886
David Garciaecb41322021-03-31 19:10:46 +0200887# VCA
888vca_new_schema = {
889 "title": "vca creation input schema",
890 "$schema": "http://json-schema.org/draft-04/schema#",
891 "type": "object",
892 "properties": {
893 "schema_version": schema_version,
894 "schema_type": schema_type,
895 "name": name_schema,
896 "description": description_schema,
897 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100898 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200899 "secret": passwd_schema,
900 "cacert": long_description_schema,
901 "lxd-cloud": shortname_schema,
902 "lxd-credentials": shortname_schema,
903 "k8s-cloud": shortname_schema,
904 "k8s-credentials": shortname_schema,
905 "model-config": object_schema,
906 },
907 "required": [
908 "name",
909 "endpoints",
910 "user",
911 "secret",
912 "cacert",
913 "lxd-cloud",
914 "lxd-credentials",
915 "k8s-cloud",
916 "k8s-credentials",
917 ],
918 "additionalProperties": False,
919}
920vca_edit_schema = {
921 "title": "vca creation input schema",
922 "$schema": "http://json-schema.org/draft-04/schema#",
923 "type": "object",
924 "properties": {
925 "name": name_schema,
926 "description": description_schema,
927 "endpoints": description_list_schema,
928 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100929 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200930 "secret": passwd_schema,
931 "cacert": long_description_schema,
932 "lxd-cloud": shortname_schema,
933 "lxd-credentials": shortname_schema,
934 "k8s-cloud": shortname_schema,
935 "k8s-credentials": shortname_schema,
936 "model-config": object_schema,
937 },
938 "additionalProperties": False,
939}
940
delacruzramofe598fe2019-10-23 18:25:11 +0200941# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000942k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200943k8srepo_properties = {
944 "name": name_schema,
945 "description": description_schema,
946 "type": k8srepo_types,
947 "url": description_schema,
Luis Vegaf6574e32023-07-11 18:47:22 +0000948 "cacert": long_description_schema,
949 "user": string_schema,
950 "password": passwd_schema,
garciadeblasf3543892023-10-20 11:53:51 +0200951 "oci": bool_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200952}
953k8srepo_new_schema = {
954 "title": "k8scluster creation input schema",
955 "$schema": "http://json-schema.org/draft-04/schema#",
956 "type": "object",
957 "properties": k8srepo_properties,
958 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100959 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200960}
961k8srepo_edit_schema = {
962 "title": "vim_account edit input schema",
963 "$schema": "http://json-schema.org/draft-04/schema#",
964 "type": "object",
965 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100966 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200967}
968
Felipe Vicensb66b0412020-05-06 10:11:00 +0200969# OSM Repos
970osmrepo_types = {"enum": ["osm"]}
971osmrepo_properties = {
972 "name": name_schema,
973 "description": description_schema,
974 "type": osmrepo_types,
975 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100976 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200977 # "password": passwd_schema
978}
979osmrepo_new_schema = {
980 "title": "osm repo creation input schema",
981 "$schema": "http://json-schema.org/draft-04/schema#",
982 "type": "object",
983 "properties": osmrepo_properties,
984 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100985 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200986}
987osmrepo_edit_schema = {
988 "title": "osm repo edit input schema",
989 "$schema": "http://json-schema.org/draft-04/schema#",
990 "type": "object",
991 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100992 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200993}
994
tiernocb83c942018-09-24 17:28:13 +0200995# PDUs
996pdu_interface = {
997 "type": "object",
998 "properties": {
tiernofd160572019-01-21 10:41:37 +0000999 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001000 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001001 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +02001002 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +02001003 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +01001004 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +00001005 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
1006 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +01001007 # # provide this in case SDN assist must deal with this interface
1008 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +00001009 # "switch-port": shortname_schema,
1010 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +01001011 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +02001012 },
tierno36ec8602018-11-02 17:27:11 +01001013 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +01001014 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001015}
tiernocb83c942018-09-24 17:28:13 +02001016pdu_new_schema = {
1017 "title": "pdu creation input schema",
1018 "$schema": "http://json-schema.org/draft-04/schema#",
1019 "type": "object",
1020 "properties": {
tiernofd160572019-01-21 10:41:37 +00001021 "name": shortname_schema,
1022 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001023 "description": description_schema,
1024 "shared": bool_schema,
1025 "vims": nameshort_list_schema,
1026 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001027 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +02001028 },
1029 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +01001030 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +02001031}
tiernocb83c942018-09-24 17:28:13 +02001032pdu_edit_schema = {
1033 "title": "pdu edit input schema",
1034 "$schema": "http://json-schema.org/draft-04/schema#",
1035 "type": "object",
1036 "properties": {
tiernofd160572019-01-21 10:41:37 +00001037 "name": shortname_schema,
1038 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001039 "description": description_schema,
1040 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +01001041 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1042 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +01001043 "interfaces": {
1044 "oneOf": [
1045 array_edition_schema,
1046 {"type": "array", "items": pdu_interface, "minItems": 1},
1047 ]
1048 },
tiernocb83c942018-09-24 17:28:13 +02001049 },
1050 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001051 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001052}
1053
delacruzramo271d2002019-12-02 21:00:37 +01001054# VNF PKG OPERATIONS
1055vnfpkgop_new_schema = {
1056 "title": "VNF PKG operation creation input schema",
1057 "$schema": "http://json-schema.org/draft-04/schema#",
1058 "type": "object",
1059 "properties": {
1060 "lcmOperationType": string_schema,
1061 "vnfPkgId": id_schema,
1062 "kdu_name": name_schema,
1063 "primitive": name_schema,
1064 "primitive_params": {"type": "object"},
1065 },
garciadeblas4568a372021-03-24 09:19:48 +01001066 "required": [
1067 "lcmOperationType",
1068 "vnfPkgId",
1069 "kdu_name",
1070 "primitive",
1071 "primitive_params",
1072 ],
1073 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001074}
1075
tiernocb83c942018-09-24 17:28:13 +02001076# USERS
tiernocf042d32019-06-13 09:06:40 +00001077project_role_mappings = {
1078 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001079 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001080 "type": "array",
1081 "items": {
1082 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001083 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001084 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001085 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001086 },
garciadeblas4568a372021-03-24 09:19:48 +01001087 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001088}
1089project_role_mappings_optional = {
1090 "title": "list of projects/roles or projects only",
1091 "$schema": "http://json-schema.org/draft-04/schema#",
1092 "type": "array",
1093 "items": {
1094 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001095 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001096 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001097 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001098 },
garciadeblas4568a372021-03-24 09:19:48 +01001099 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001100}
tiernocd54a4a2018-09-12 16:40:35 +02001101user_new_schema = {
1102 "$schema": "http://json-schema.org/draft-04/schema#",
1103 "title": "New user schema",
1104 "type": "object",
1105 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001106 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001107 "domain_name": shortname_schema,
garciadeblas6d83f8f2023-06-19 22:34:49 +02001108 "password": user_passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001109 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001110 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001111 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001112 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001113 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001114}
1115user_edit_schema = {
1116 "$schema": "http://json-schema.org/draft-04/schema#",
1117 "title": "User edit schema for administrators",
1118 "type": "object",
1119 "properties": {
garciadeblas6d83f8f2023-06-19 22:34:49 +02001120 "password": user_passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001121 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001122 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001123 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001124 "project_role_mappings": project_role_mappings,
1125 "add_project_role_mappings": project_role_mappings,
1126 "remove_project_role_mappings": project_role_mappings_optional,
garciadeblas6d83f8f2023-06-19 22:34:49 +02001127 "system_admin_id": id_schema,
1128 "unlock": bool_schema,
1129 "renew": bool_schema,
tiernocb83c942018-09-24 17:28:13 +02001130 },
1131 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001132 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001133}
1134
1135# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001136topics_with_quota = [
1137 "vnfds",
1138 "nsds",
1139 "slice_templates",
1140 "pduds",
1141 "ns_instances",
1142 "slice_instances",
1143 "vim_accounts",
1144 "wim_accounts",
1145 "sdn_controllers",
1146 "k8sclusters",
1147 "vca",
1148 "k8srepos",
1149 "osmrepos",
1150 "ns_subscriptions",
1151]
tiernocd54a4a2018-09-12 16:40:35 +02001152project_new_schema = {
1153 "$schema": "http://json-schema.org/draft-04/schema#",
1154 "title": "New project schema for administrators",
1155 "type": "object",
1156 "properties": {
tiernofd160572019-01-21 10:41:37 +00001157 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001158 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001159 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001160 "quotas": {
1161 "type": "object",
1162 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001163 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001164 },
tiernocd54a4a2018-09-12 16:40:35 +02001165 },
1166 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001167 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001168}
1169project_edit_schema = {
1170 "$schema": "http://json-schema.org/draft-04/schema#",
1171 "title": "Project edit schema for administrators",
1172 "type": "object",
1173 "properties": {
1174 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001175 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001176 "quotas": {
1177 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001178 "properties": {
1179 topic: {"oneOf": [integer0_schema, null_schema]}
1180 for topic in topics_with_quota
1181 },
1182 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001183 },
tiernocd54a4a2018-09-12 16:40:35 +02001184 },
1185 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001186 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001187}
1188
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001189# ROLES
1190roles_new_schema = {
1191 "$schema": "http://json-schema.org/draft-04/schema#",
1192 "title": "New role schema for administrators",
1193 "type": "object",
1194 "properties": {
1195 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001196 "permissions": {
1197 "type": "object",
1198 "patternProperties": {
1199 ".": bool_schema,
1200 },
1201 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001202 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001203 },
tierno1f029d82019-06-13 22:37:04 +00001204 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001205 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001206}
1207roles_edit_schema = {
1208 "$schema": "http://json-schema.org/draft-04/schema#",
1209 "title": "Roles edit schema for administrators",
1210 "type": "object",
1211 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001212 "name": shortname_schema,
1213 "permissions": {
1214 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001215 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001216 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001217 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001218 },
tierno1f029d82019-06-13 22:37:04 +00001219 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001220 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001221}
1222
tiernocd54a4a2018-09-12 16:40:35 +02001223# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001224
1225nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001226 "users": user_new_schema,
1227 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001228 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001229 "sdns": sdn_new_schema,
1230 "ns_instantiate": ns_instantiate,
1231 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001232 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001233 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001234 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001235 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001236}
1237
1238nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001239 "users": user_edit_schema,
1240 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001241 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001242 "sdns": sdn_edit_schema,
1243 "pdus": pdu_edit_schema,
kayal2001f71c2e82024-06-25 15:26:24 +05301244 "vnf": vnf_schema,
1245 "vld": vld_schema,
1246 "additionalParamsForVnf": additional_params_for_vnf,
tierno0f98af52018-03-19 10:28:22 +01001247}
1248
Felipe Vicens07f31722018-10-29 15:16:44 +01001249# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001250nsi_subnet_instantiate = deepcopy(ns_instantiate)
1251nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1252nsi_subnet_instantiate["properties"]["id"] = name_schema
1253del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001254
1255nsi_vld_instantiate = {
1256 "title": "netslice vld instantiation params input schema",
1257 "$schema": "http://json-schema.org/draft-04/schema#",
1258 "type": "object",
1259 "properties": {
1260 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001261 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1262 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001263 "ip-profile": object_schema,
1264 },
delacruzramoc061f562019-04-05 11:00:02 +02001265 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001266 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001267}
1268
Felipe Vicens07f31722018-10-29 15:16:44 +01001269nsi_instantiate = {
1270 "title": "netslice action instantiate input schema",
1271 "$schema": "http://json-schema.org/draft-04/schema#",
1272 "type": "object",
1273 "properties": {
1274 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001275 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001276 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001277 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001278 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001279 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001280 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001281 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001282 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001283 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001284 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001285 "type": "array",
1286 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001287 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001288 },
garciadeblas4568a372021-03-24 09:19:48 +01001289 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001290 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001291 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001292 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001293}
1294
garciadeblas4568a372021-03-24 09:19:48 +01001295nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001296
garciadeblas4568a372021-03-24 09:19:48 +01001297nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001298
preethika.p329b8182020-04-22 12:25:39 +05301299nsinstancesubscriptionfilter_schema = {
1300 "title": "instance identifier schema",
1301 "$schema": "http://json-schema.org/draft-07/schema#",
1302 "type": "object",
1303 "properties": {
1304 "nsdIds": {"type": "array"},
1305 "vnfdIds": {"type": "array"},
1306 "pnfdIds": {"type": "array"},
1307 "nsInstanceIds": {"type": "array"},
1308 "nsInstanceNames": {"type": "array"},
1309 },
1310}
1311
1312nslcmsub_schema = {
1313 "title": "nslcmsubscription input schema",
1314 "$schema": "http://json-schema.org/draft-07/schema#",
1315 "type": "object",
1316 "properties": {
1317 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1318 "notificationTypes": {
1319 "type": "array",
1320 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001321 "enum": [
1322 "NsLcmOperationOccurrenceNotification",
1323 "NsChangeNotification",
1324 "NsIdentifierCreationNotification",
1325 "NsIdentifierDeletionNotification",
1326 ]
1327 },
preethika.p329b8182020-04-22 12:25:39 +05301328 },
1329 "operationTypes": {
1330 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001331 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301332 },
1333 "operationStates": {
1334 "type": "array",
1335 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001336 "enum": [
1337 "PROCESSING",
1338 "COMPLETED",
1339 "PARTIALLY_COMPLETED",
1340 "FAILED",
1341 "FAILED_TEMP",
1342 "ROLLING_BACK",
1343 "ROLLED_BACK",
1344 ]
1345 },
preethika.p329b8182020-04-22 12:25:39 +05301346 },
garciadeblas4568a372021-03-24 09:19:48 +01001347 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301348 "lcmOpNameImpactingNsComponent": {
1349 "type": "array",
1350 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001351 "enum": [
1352 "VNF_INSTANTIATE",
1353 "VNF_SCALE",
1354 "VNF_SCALE_TO_LEVEL",
1355 "VNF_CHANGE_FLAVOUR",
1356 "VNF_TERMINATE",
1357 "VNF_HEAL",
1358 "VNF_OPERATE",
1359 "VNF_CHANGE_EXT_CONN",
1360 "VNF_MODIFY_INFO",
1361 "NS_INSTANTIATE",
1362 "NS_SCALE",
1363 "NS_UPDATE",
1364 "NS_TERMINATE",
1365 "NS_HEAL",
1366 ]
1367 },
preethika.p329b8182020-04-22 12:25:39 +05301368 },
1369 "lcmOpOccStatusImpactingNsComponent": {
1370 "type": "array",
1371 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001372 "enum": [
1373 "START",
1374 "COMPLETED",
1375 "PARTIALLY_COMPLETED",
1376 "FAILED",
1377 "ROLLED_BACK",
1378 ]
1379 },
preethika.p329b8182020-04-22 12:25:39 +05301380 },
1381 },
1382 "allOf": [
1383 {
1384 "if": {
1385 "properties": {
1386 "notificationTypes": {
1387 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1388 }
1389 },
1390 },
1391 "then": {
1392 "anyOf": [
1393 {"required": ["operationTypes"]},
1394 {"required": ["operationStates"]},
1395 ]
garciadeblas4568a372021-03-24 09:19:48 +01001396 },
preethika.p329b8182020-04-22 12:25:39 +05301397 },
1398 {
1399 "if": {
1400 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001401 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301402 },
1403 },
1404 "then": {
1405 "anyOf": [
1406 {"required": ["nsComponentTypes"]},
1407 {"required": ["lcmOpNameImpactingNsComponent"]},
1408 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1409 ]
garciadeblas4568a372021-03-24 09:19:48 +01001410 },
1411 },
1412 ],
preethika.p329b8182020-04-22 12:25:39 +05301413}
1414
1415authentication_schema = {
1416 "title": "authentication schema for subscription",
1417 "$schema": "http://json-schema.org/draft-07/schema#",
1418 "type": "object",
1419 "properties": {
1420 "authType": {"enum": ["basic"]},
1421 "paramsBasic": {
1422 "type": "object",
1423 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001424 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301425 "password": passwd_schema,
1426 },
1427 },
1428 },
1429}
1430
1431subscription = {
1432 "title": "subscription input schema",
1433 "$schema": "http://json-schema.org/draft-07/schema#",
1434 "type": "object",
1435 "properties": {
1436 "filter": nslcmsub_schema,
1437 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001438 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301439 },
1440 "required": ["CallbackUri"],
1441}
1442
selvi.jf1004592022-04-29 05:42:35 +00001443vnflcmsub_schema = {
1444 "title": "vnflcmsubscription input schema",
1445 "$schema": "http://json-schema.org/draft-07/schema#",
1446 "type": "object",
1447 "properties": {
1448 "VnfInstanceSubscriptionFilter": {
1449 "type": "object",
1450 "properties": {
1451 "vnfdIds": {"type": "array"},
1452 "vnfInstanceIds": {"type": "array"},
1453 },
1454 },
1455 "notificationTypes": {
1456 "type": "array",
1457 "items": {
1458 "enum": [
1459 "VnfIdentifierCreationNotification",
1460 "VnfLcmOperationOccurrenceNotification",
garciadeblasf2af4a12023-01-24 16:56:54 +01001461 "VnfIdentifierDeletionNotification",
1462 ]
1463 },
selvi.jf1004592022-04-29 05:42:35 +00001464 },
1465 "operationTypes": {
1466 "type": "array",
1467 "items": {
1468 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001469 "INSTANTIATE",
1470 "SCALE",
1471 "SCALE_TO_LEVEL",
1472 "CHANGE_FLAVOUR",
1473 "TERMINATE",
1474 "HEAL",
1475 "OPERATE",
1476 "CHANGE_EXT_CONN",
1477 "MODIFY_INFO",
1478 "CREATE_SNAPSHOT",
1479 "REVERT_TO_SNAPSHOT",
1480 "CHANGE_VNFPKG",
1481 ]
1482 },
selvi.jf1004592022-04-29 05:42:35 +00001483 },
1484 "operationStates": {
1485 "type": "array",
1486 "items": {
1487 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001488 "STARTING",
1489 "PROCESSING",
1490 "COMPLETED",
1491 "FAILED_TEMP",
1492 "FAILED",
1493 "ROLLING_BACK",
1494 "ROLLED_BACK",
1495 ]
1496 },
1497 },
selvi.jf1004592022-04-29 05:42:35 +00001498 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001499 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1500}
selvi.jf1004592022-04-29 05:42:35 +00001501
1502vnf_subscription = {
1503 "title": "vnf subscription input schema",
1504 "$schema": "http://json-schema.org/draft-07/schema#",
1505 "type": "object",
1506 "properties": {
1507 "filter": vnflcmsub_schema,
1508 "CallbackUri": description_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +01001509 "authentication": authentication_schema,
selvi.jf1004592022-04-29 05:42:35 +00001510 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001511 "required": ["filter", "CallbackUri"],
selvi.jf1004592022-04-29 05:42:35 +00001512}
1513
tierno0f98af52018-03-19 10:28:22 +01001514
1515class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001516 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1517 self.http_code = http_code
1518 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001519
1520
tiernob24258a2018-10-04 18:39:49 +02001521def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001522 """
tiernocd54a4a2018-09-12 16:40:35 +02001523 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001524 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001525 :param schema_to_use: jsonschema to test
1526 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001527 """
1528 try:
tierno0f98af52018-03-19 10:28:22 +01001529 if schema_to_use:
1530 js_v(indata, schema_to_use)
1531 return None
1532 except js_e.ValidationError as e:
1533 if e.path:
tierno0da52252018-06-27 15:47:22 +02001534 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001535 else:
1536 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001537 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001538 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001539 raise ValidationError(
1540 "Bad json schema {}".format(schema_to_use),
1541 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1542 )
delacruzramoc061f562019-04-05 11:00:02 +02001543
1544
1545def is_valid_uuid(x):
1546 """
1547 Test for a valid UUID
1548 :param x: string to test
1549 :return: True if x is a valid uuid, False otherwise
1550 """
1551 try:
1552 if UUID(x):
1553 return True
tiernobdebce92019-07-01 15:36:49 +00001554 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001555 return False