blob: 8b9356654d1df5f094dd2982d5a53a018aa7a5c6 [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,
Gulsum Aticia744b752023-04-28 10:47:36 +0300140 "configurable-properties": {
141 "type": "object",
142 },
Dario Faccin5584b642023-05-24 10:21:37 +0200143 "vim-flavor-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200144 "volume": {
145 "type": "array",
146 "minItems": 1,
147 "items": {
148 "type": "object",
149 "properties": {
150 "name": name_schema,
151 "vim-volume-id": name_schema,
152 },
153 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100154 "additionalProperties": False,
155 },
tierno441dbbf2018-07-10 12:52:48 +0200156 },
157 "interface": {
158 "type": "array",
159 "minItems": 1,
160 "items": {
161 "type": "object",
162 "properties": {
163 "name": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200164 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200165 "mac-address": mac_schema,
166 "floating-ip-required": bool_schema,
167 },
168 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100169 "additionalProperties": False,
170 },
171 },
tierno441dbbf2018-07-10 12:52:48 +0200172 },
173 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100174 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200175}
176
177ip_profile_dns_schema = {
178 "type": "array",
179 "minItems": 1,
180 "items": {
181 "type": "object",
182 "properties": {
garciadeblas9fb32712022-04-04 16:33:59 +0200183 "address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200184 },
185 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100186 "additionalProperties": False,
187 },
tierno441dbbf2018-07-10 12:52:48 +0200188}
189
190ip_profile_dhcp_schema = {
191 "type": "object",
192 "properties": {
193 "enabled": {"type": "boolean"},
194 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100195 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200196 },
197 "additionalProperties": False,
198}
199
200ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000201 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200202 "$schema": "http://json-schema.org/draft-04/schema#",
203 "type": "object",
204 "properties": {
205 "ip-version": {"enum": ["ipv4", "ipv6"]},
tierno441dbbf2018-07-10 12:52:48 +0200206 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
207 "gateway-address": {"oneOf": [null_schema, ip_schema]},
208 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200209 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
210 },
garciadeblas4568a372021-03-24 09:19:48 +0100211 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200212}
213
kbsub21f03f52019-10-17 16:26:56 +0000214provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000215 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000216 "$schema": "http://json-schema.org/draft-04/schema#",
217 "type": "object",
218 "properties": {
219 "physical-network": name_schema,
220 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000221 "sdn-ports": { # external ports to append to the SDN-assist network
222 "type": "array",
223 "items": {
224 "type": "object",
225 "properties": {
226 "switch_id": shortname_schema,
227 "switch_port": shortname_schema,
228 "mac_address": mac_schema,
229 "vlan": vlan_schema,
230 },
garciadeblas4568a372021-03-24 09:19:48 +0100231 "additionalProperties": True,
232 },
tierno2a929042020-03-10 16:34:25 +0000233 },
234 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000235 },
garciadeblas4568a372021-03-24 09:19:48 +0100236 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000237}
238
tierno441dbbf2018-07-10 12:52:48 +0200239ns_instantiate_internal_vld = {
garciadeblas9fb32712022-04-04 16:33:59 +0200240 "title": "ns action instantiate input schema for vld",
tierno441dbbf2018-07-10 12:52:48 +0200241 "$schema": "http://json-schema.org/draft-04/schema#",
242 "type": "object",
243 "properties": {
244 "name": name_schema,
245 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100246 "vim-network-id": name_schema,
Dario Faccin5584b642023-05-24 10:21:37 +0200247 "ip-profile": ip_profile_schema,
kbsub21f03f52019-10-17 16:26:56 +0000248 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200249 "internal-connection-point": {
250 "type": "array",
251 "minItems": 1,
252 "items": {
253 "type": "object",
254 "properties": {
255 "id-ref": name_schema,
256 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200257 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200258 },
tiernob7c6f2a2018-09-03 14:32:10 +0200259 "required": ["id-ref"],
260 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100261 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200262 },
garciadeblas4568a372021-03-24 09:19:48 +0100263 },
tierno441dbbf2018-07-10 12:52:48 +0200264 },
265 "required": ["name"],
266 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100267 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200268}
tierno65acb4d2018-04-06 16:42:40 +0200269
tiernofd160572019-01-21 10:41:37 +0000270additional_params_for_vnf = {
271 "type": "array",
272 "items": {
273 "type": "object",
274 "properties": {
275 "member-vnf-index": name_schema,
276 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000277 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000278 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000279 "additionalParamsForVdu": {
280 "type": "array",
281 "items": {
282 "type": "object",
283 "properties": {
284 "vdu_id": name_schema,
285 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100286 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000287 },
tiernof62ac6a2020-04-29 13:46:13 +0000288 "required": ["vdu_id"],
289 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000290 "additionalProperties": False,
291 },
292 },
293 "additionalParamsForKdu": {
294 "type": "array",
295 "items": {
296 "type": "object",
297 "properties": {
298 "kdu_name": name_schema,
299 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000300 "kdu_model": name_schema,
301 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100302 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200303 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000304 },
tierno54db2e42020-04-06 15:29:42 +0000305 "required": ["kdu_name"],
306 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000307 "additionalProperties": False,
308 },
309 },
Alexis Romeroee31f532022-04-26 19:10:21 +0200310 "affinity-or-anti-affinity-group": {
311 "type": "array",
312 "items": {
313 "type": "object",
314 "properties": {
315 "id": name_schema,
316 "vim-affinity-group-id": name_schema,
317 },
318 "required": ["id"],
319 "minProperties": 2,
320 "additionalProperties": False,
321 },
322 },
tiernofd160572019-01-21 10:41:37 +0000323 },
tierno714954e2019-11-29 13:43:26 +0000324 "required": ["member-vnf-index"],
325 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100326 "additionalProperties": False,
327 },
tiernofd160572019-01-21 10:41:37 +0000328}
329
tierno65acb4d2018-04-06 16:42:40 +0200330ns_instantiate = {
331 "title": "ns action instantiate input schema",
332 "$schema": "http://json-schema.org/draft-04/schema#",
333 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200334 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200335 "lcmOperationType": string_schema,
336 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100337 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200338 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000339 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200340 "nsdId": id_schema,
341 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000342 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100343 "placement-engine": string_schema,
344 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000345 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000346 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100347 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000348 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100349 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000350 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200351 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200352 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200353 "vnf": {
354 "type": "array",
355 "minItems": 1,
356 "items": {
357 "type": "object",
358 "properties": {
359 "member-vnf-index": name_schema,
360 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200361 "vdu": {
362 "type": "array",
363 "minItems": 1,
364 "items": ns_instantiate_vdu,
365 },
366 "internal-vld": {
367 "type": "array",
368 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100369 "items": ns_instantiate_internal_vld,
370 },
tierno0da52252018-06-27 15:47:22 +0200371 },
tierno441dbbf2018-07-10 12:52:48 +0200372 "required": ["member-vnf-index"],
373 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100374 "additionalProperties": False,
375 },
tierno0da52252018-06-27 15:47:22 +0200376 },
377 "vld": {
378 "type": "array",
379 "minItems": 1,
380 "items": {
381 "type": "object",
382 "properties": {
383 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000384 "vim-network-name": {"oneOf": [string_schema, object_schema]},
385 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100386 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000387 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
Dario Faccin5584b642023-05-24 10:21:37 +0200388 "ip-profile": ip_profile_schema,
kbsub21f03f52019-10-17 16:26:56 +0000389 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200390 "vnfd-connection-point-ref": {
391 "type": "array",
392 "minItems": 1,
393 "items": {
394 "type": "object",
395 "properties": {
396 "member-vnf-index-ref": name_schema,
397 "vnfd-connection-point-ref": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200398 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernob7c6f2a2018-09-03 14:32:10 +0200399 # "mac-address": mac_schema,
400 },
garciadeblas4568a372021-03-24 09:19:48 +0100401 "required": [
402 "member-vnf-index-ref",
403 "vnfd-connection-point-ref",
404 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200405 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100406 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200407 },
garciadeblas4568a372021-03-24 09:19:48 +0100408 },
tierno0da52252018-06-27 15:47:22 +0200409 },
tierno441dbbf2018-07-10 12:52:48 +0200410 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100411 "additionalProperties": False,
412 },
tierno0da52252018-06-27 15:47:22 +0200413 },
414 },
tierno441dbbf2018-07-10 12:52:48 +0200415 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100416 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200417}
tierno0da52252018-06-27 15:47:22 +0200418
tierno1c38f2f2020-03-24 11:51:39 +0000419ns_terminate = {
420 "title": "ns terminate input schema",
421 "$schema": "http://json-schema.org/draft-04/schema#",
422 "type": "object",
423 "properties": {
424 "lcmOperationType": string_schema,
425 "nsInstanceId": id_schema,
426 "autoremove": bool_schema,
427 "timeout_ns_terminate": integer1_schema,
428 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000429 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000430 },
garciadeblas4568a372021-03-24 09:19:48 +0100431 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000432}
433
aticig544a2ae2022-04-05 09:00:17 +0300434ns_update = {
435 "title": "ns update input schema",
436 "$schema": "http://json-schema.org/draft-04/schema#",
437 "type": "object",
438 "properties": {
439 "lcmOperationType": string_schema,
440 "nsInstanceId": id_schema,
garciadeblaseab15072022-05-19 10:31:52 +0200441 "timeout_ns_update": integer1_schema,
aticig544a2ae2022-04-05 09:00:17 +0300442 "updateType": {
garciadeblasf2af4a12023-01-24 16:56:54 +0100443 "enum": [
444 "CHANGE_VNFPKG",
445 "REMOVE_VNF",
446 "MODIFY_VNF_INFORMATION",
447 "OPERATE_VNF",
448 ]
aticig544a2ae2022-04-05 09:00:17 +0300449 },
450 "modifyVnfInfoData": {
451 "type": "object",
452 "properties": {
453 "vnfInstanceId": id_schema,
454 "vnfdId": id_schema,
455 },
456 "required": ["vnfInstanceId", "vnfdId"],
457 },
458 "removeVnfInstanceId": id_schema,
459 "changeVnfPackageData": {
460 "type": "object",
461 "properties": {
462 "vnfInstanceId": id_schema,
463 "vnfdId": id_schema,
464 },
465 "required": ["vnfInstanceId", "vnfdId"],
466 },
k4.rahule3dca382022-04-29 12:30:36 +0000467 "operateVnfData": {
468 "type": "object",
469 "properties": {
470 "vnfInstanceId": id_schema,
471 "changeStateTo": name_schema,
472 "additionalParam": {
473 "type": "object",
474 "properties": {
475 "run-day1": bool_schema,
476 "vdu_id": name_schema,
477 "count-index": integer0_schema,
478 },
479 "required": ["vdu_id", "count-index"],
480 "additionalProperties": False,
garciadeblasf2af4a12023-01-24 16:56:54 +0100481 },
k4.rahule3dca382022-04-29 12:30:36 +0000482 },
483 "required": ["vnfInstanceId", "changeStateTo"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100484 },
aticig544a2ae2022-04-05 09:00:17 +0300485 },
486 "required": ["updateType"],
487 "additionalProperties": False,
488}
489
garciadeblas4568a372021-03-24 09:19:48 +0100490ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200491 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200492 "$schema": "http://json-schema.org/draft-04/schema#",
493 "type": "object",
494 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200495 "lcmOperationType": string_schema,
496 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200497 "member_vnf_index": name_schema,
498 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200499 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000500 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000501 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200502 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000503 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200504 "primitive_params": {"type": "object"},
505 },
garciadeblas4568a372021-03-24 09:19:48 +0100506 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
507 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200508}
garciadeblas0964edf2022-02-11 00:43:44 +0100509
garciadeblas4568a372021-03-24 09:19:48 +0100510ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200511 "title": "ns scale input schema",
512 "$schema": "http://json-schema.org/draft-04/schema#",
513 "type": "object",
514 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200515 "lcmOperationType": string_schema,
516 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200517 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000518 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200519 "scaleVnfData": {
520 "type": "object",
521 "properties": {
522 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100523 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200524 "scaleByStepData": {
525 "type": "object",
526 "properties": {
527 "scaling-group-descriptor": name_schema,
528 "member-vnf-index": name_schema,
529 "scaling-policy": name_schema,
530 },
531 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100532 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200533 },
534 },
535 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100536 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200537 },
538 "scaleTime": time_schema,
539 },
540 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100541 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200542}
tierno65acb4d2018-04-06 16:42:40 +0200543
elumalai8e3806c2022-04-28 17:26:24 +0530544ns_migrate = {
545 "title": "ns migrate input schema",
546 "$schema": "http://json-schema.org/draft-04/schema#",
547 "type": "object",
548 "properties": {
549 "lcmOperationType": string_schema,
550 "nsInstanceId": id_schema,
551 "vnfInstanceId": id_schema,
552 "migrateToHost": string_schema,
553 "vdu": {
554 "type": "object",
garciadeblasf2af4a12023-01-24 16:56:54 +0100555 "properties": {
556 "vduId": name_schema,
557 "vduCountIndex": integer0_schema,
558 },
559 "required": ["vduId"],
560 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530561 },
562 },
563 "required": ["vnfInstanceId"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100564 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530565}
tierno65acb4d2018-04-06 16:42:40 +0200566
garciadeblas0964edf2022-02-11 00:43:44 +0100567ns_heal = {
568 "title": "ns heal input schema",
569 "$schema": "http://json-schema.org/draft-04/schema#",
570 "type": "object",
571 "properties": {
572 "lcmOperationType": string_schema,
573 "nsInstanceId": id_schema,
574 "timeout_ns_heal": integer1_schema,
575 "healVnfData": {
576 "type": "array",
577 "items": {
578 "type": "object",
579 "properties": {
580 "vnfInstanceId": id_schema,
581 "cause": description_schema,
582 "additionalParams": {
583 "type": "object",
584 "properties": {
585 "run-day1": bool_schema,
586 "vdu": {
587 "type": "array",
588 "items": {
589 "type": "object",
590 "properties": {
591 "run-day1": bool_schema,
592 "vdu-id": name_schema,
593 "count-index": integer0_schema,
594 },
595 "required": ["vdu-id"],
596 "additionalProperties": False,
597 },
598 },
599 },
600 "additionalProperties": False,
601 },
602 },
603 "required": ["vnfInstanceId"],
604 "additionalProperties": False,
605 },
606 },
607 },
608 "required": ["healVnfData"],
609 "additionalProperties": False,
610}
611
govindarajul519da482022-04-29 19:05:22 +0530612ns_verticalscale = {
613 "title": "vertial scale input schema",
614 "$schema": "http://json-schema.org/draft-04/schema#",
615 "type": "object",
616 "properties": {
617 "lcmOperationType": string_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000618 "verticalScale": string_schema,
govindarajul519da482022-04-29 19:05:22 +0530619 "nsInstanceId": id_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000620 "changeVnfFlavorData": {
govindarajul519da482022-04-29 19:05:22 +0530621 "type": "object",
govindarajul69964ec2022-07-06 10:24:38 +0000622 "properties": {
623 "vnfInstanceId": id_schema,
624 "additionalParams": {
625 "type": "object",
626 "properties": {
627 "vduid": string_schema,
628 "vduCountIndex": integer0_schema,
629 "virtualMemory": integer1_schema,
630 "sizeOfStorage": integer0_schema,
631 "numVirtualCpu": integer1_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +0100632 },
govindarajul519da482022-04-29 19:05:22 +0530633 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100634 },
govindarajul69964ec2022-07-06 10:24:38 +0000635 "required": ["vnfInstanceId", "additionalParams"],
636 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530637 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100638 },
govindarajul69964ec2022-07-06 10:24:38 +0000639 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
640 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530641}
642
tierno0f98af52018-03-19 10:28:22 +0100643schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000644schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000645vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200646
tierno09c073e2018-04-26 13:36:48 +0200647vim_account_edit_schema = {
648 "title": "vim_account edit input schema",
649 "$schema": "http://json-schema.org/draft-04/schema#",
650 "type": "object",
651 "properties": {
652 "name": name_schema,
653 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200654 "vim": name_schema,
655 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200656 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200657 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200658 # "vim_url_admin": description_schema,
659 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200660 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200661 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200662 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200663 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100664 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000665 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200666 },
garciadeblas4568a372021-03-24 09:19:48 +0100667 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200668}
tierno0f98af52018-03-19 10:28:22 +0100669
tierno09c073e2018-04-26 13:36:48 +0200670vim_account_new_schema = {
671 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100672 "$schema": "http://json-schema.org/draft-04/schema#",
673 "type": "object",
674 "properties": {
675 "schema_version": schema_version,
676 "schema_type": schema_type,
677 "name": name_schema,
678 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200679 "vim": name_schema,
680 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200681 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100682 "vim_url": description_schema,
683 # "vim_url_admin": description_schema,
684 # "vim_tenant": name_schema,
685 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200686 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200687 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200688 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100689 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000690 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100691 },
garciadeblas4568a372021-03-24 09:19:48 +0100692 "required": [
693 "name",
694 "vim_url",
695 "vim_type",
696 "vim_user",
697 "vim_password",
698 "vim_tenant_name",
699 ],
700 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100701}
tierno0f98af52018-03-19 10:28:22 +0100702
tierno85807722019-12-20 14:11:35 +0000703wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200704
tierno55ba2e62018-12-11 17:22:22 +0000705wim_account_edit_schema = {
706 "title": "wim_account edit input schema",
707 "$schema": "http://json-schema.org/draft-04/schema#",
708 "type": "object",
709 "properties": {
710 "name": name_schema,
711 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000712 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200713 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000714 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100715 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000716 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100717 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000718 },
garciadeblas4568a372021-03-24 09:19:48 +0100719 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000720}
721
722wim_account_new_schema = {
723 "title": "wim_account creation input schema",
724 "$schema": "http://json-schema.org/draft-04/schema#",
725 "type": "object",
726 "properties": {
727 "schema_version": schema_version,
728 "schema_type": schema_type,
729 "name": name_schema,
730 "description": description_schema,
731 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200732 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000733 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100734 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000735 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000736 "config": {
737 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100738 "patternProperties": {".": {"not": {"type": "null"}}},
739 },
tierno55ba2e62018-12-11 17:22:22 +0000740 },
741 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100742 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000743}
tierno0f98af52018-03-19 10:28:22 +0100744
745sdn_properties = {
746 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000747 "type": {"type": "string"},
748 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100749 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000750 "password": passwd_schema,
751 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200752 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000753 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200754 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100755 "ip": ip_schema,
756 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100757 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100758}
759sdn_new_schema = {
760 "title": "sdn controller information schema",
761 "$schema": "http://json-schema.org/draft-04/schema#",
762 "type": "object",
763 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100764 "required": ["name", "type"],
765 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100766}
767sdn_edit_schema = {
768 "title": "sdn controller update information schema",
769 "$schema": "http://json-schema.org/draft-04/schema#",
770 "type": "object",
771 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200772 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100773 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100774}
775sdn_port_mapping_schema = {
776 "$schema": "http://json-schema.org/draft-04/schema#",
777 "title": "sdn port mapping information schema",
778 "type": "array",
779 "items": {
780 "type": "object",
781 "properties": {
tiernofd160572019-01-21 10:41:37 +0000782 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100783 "ports": {
784 "type": "array",
785 "items": {
786 "type": "object",
787 "properties": {
tierno42fce592018-11-02 09:23:43 +0100788 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000789 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100790 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100791 },
garciadeblas4568a372021-03-24 09:19:48 +0100792 "required": ["pci"],
793 },
794 },
tierno0f98af52018-03-19 10:28:22 +0100795 },
garciadeblas4568a372021-03-24 09:19:48 +0100796 "required": ["compute_node", "ports"],
797 },
tierno0f98af52018-03-19 10:28:22 +0100798}
799sdn_external_port_schema = {
800 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200801 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100802 "type": "object",
803 "properties": {
804 "port": {"type": "string", "minLength": 1, "maxLength": 60},
805 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100806 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100807 },
garciadeblas4568a372021-03-24 09:19:48 +0100808 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100809}
810
delacruzramofe598fe2019-10-23 18:25:11 +0200811# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500812k8scluster_deploy_method_schema = {
813 "$schema": "http://json-schema.org/draft-04/schema#",
814 "title": "Deployment methods for K8s cluster",
815 "type": "object",
816 "properties": {
817 "helm-chart": {"type": "boolean"},
818 "juju-bundle": {"type": "boolean"},
819 "helm-chart-v3": {"type": "boolean"},
820 },
821 "additionalProperties": False,
822 "minProperties": 3,
823}
delacruzramofe598fe2019-10-23 18:25:11 +0200824k8scluster_nets_schema = {
825 "title": "k8scluster nets input schema",
826 "$schema": "http://json-schema.org/draft-04/schema#",
827 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000828 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200829 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100830 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200831}
832k8scluster_new_schema = {
833 "title": "k8scluster creation input schema",
834 "$schema": "http://json-schema.org/draft-04/schema#",
835 "type": "object",
836 "properties": {
837 "schema_version": schema_version,
838 "schema_type": schema_type,
839 "name": name_schema,
840 "description": description_schema,
841 "credentials": object_schema,
842 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200843 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200844 "k8s_version": string_schema,
845 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500846 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200847 "namespace": name_schema,
848 "cni": nameshort_list_schema,
849 },
850 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100851 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200852}
853k8scluster_edit_schema = {
854 "title": "vim_account edit input schema",
855 "$schema": "http://json-schema.org/draft-04/schema#",
856 "type": "object",
857 "properties": {
858 "name": name_schema,
859 "description": description_schema,
860 "credentials": object_schema,
861 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200862 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200863 "k8s_version": string_schema,
864 "nets": k8scluster_nets_schema,
865 "namespace": name_schema,
866 "cni": nameshort_list_schema,
867 },
garciadeblas4568a372021-03-24 09:19:48 +0100868 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200869}
870
David Garciaecb41322021-03-31 19:10:46 +0200871# VCA
872vca_new_schema = {
873 "title": "vca creation input schema",
874 "$schema": "http://json-schema.org/draft-04/schema#",
875 "type": "object",
876 "properties": {
877 "schema_version": schema_version,
878 "schema_type": schema_type,
879 "name": name_schema,
880 "description": description_schema,
881 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100882 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200883 "secret": passwd_schema,
884 "cacert": long_description_schema,
885 "lxd-cloud": shortname_schema,
886 "lxd-credentials": shortname_schema,
887 "k8s-cloud": shortname_schema,
888 "k8s-credentials": shortname_schema,
889 "model-config": object_schema,
890 },
891 "required": [
892 "name",
893 "endpoints",
894 "user",
895 "secret",
896 "cacert",
897 "lxd-cloud",
898 "lxd-credentials",
899 "k8s-cloud",
900 "k8s-credentials",
901 ],
902 "additionalProperties": False,
903}
904vca_edit_schema = {
905 "title": "vca creation input schema",
906 "$schema": "http://json-schema.org/draft-04/schema#",
907 "type": "object",
908 "properties": {
909 "name": name_schema,
910 "description": description_schema,
911 "endpoints": description_list_schema,
912 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100913 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200914 "secret": passwd_schema,
915 "cacert": long_description_schema,
916 "lxd-cloud": shortname_schema,
917 "lxd-credentials": shortname_schema,
918 "k8s-cloud": shortname_schema,
919 "k8s-credentials": shortname_schema,
920 "model-config": object_schema,
921 },
922 "additionalProperties": False,
923}
924
delacruzramofe598fe2019-10-23 18:25:11 +0200925# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000926k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200927k8srepo_properties = {
928 "name": name_schema,
929 "description": description_schema,
930 "type": k8srepo_types,
931 "url": description_schema,
932}
933k8srepo_new_schema = {
934 "title": "k8scluster creation input schema",
935 "$schema": "http://json-schema.org/draft-04/schema#",
936 "type": "object",
937 "properties": k8srepo_properties,
938 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100939 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200940}
941k8srepo_edit_schema = {
942 "title": "vim_account edit input schema",
943 "$schema": "http://json-schema.org/draft-04/schema#",
944 "type": "object",
945 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100946 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200947}
948
Felipe Vicensb66b0412020-05-06 10:11:00 +0200949# OSM Repos
950osmrepo_types = {"enum": ["osm"]}
951osmrepo_properties = {
952 "name": name_schema,
953 "description": description_schema,
954 "type": osmrepo_types,
955 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100956 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200957 # "password": passwd_schema
958}
959osmrepo_new_schema = {
960 "title": "osm repo creation input schema",
961 "$schema": "http://json-schema.org/draft-04/schema#",
962 "type": "object",
963 "properties": osmrepo_properties,
964 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100965 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200966}
967osmrepo_edit_schema = {
968 "title": "osm repo edit input schema",
969 "$schema": "http://json-schema.org/draft-04/schema#",
970 "type": "object",
971 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100972 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200973}
974
tiernocb83c942018-09-24 17:28:13 +0200975# PDUs
976pdu_interface = {
977 "type": "object",
978 "properties": {
tiernofd160572019-01-21 10:41:37 +0000979 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200980 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100981 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200982 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200983 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100984 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000985 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
986 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100987 # # provide this in case SDN assist must deal with this interface
988 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000989 # "switch-port": shortname_schema,
990 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100991 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200992 },
tierno36ec8602018-11-02 17:27:11 +0100993 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100994 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200995}
tiernocb83c942018-09-24 17:28:13 +0200996pdu_new_schema = {
997 "title": "pdu creation input schema",
998 "$schema": "http://json-schema.org/draft-04/schema#",
999 "type": "object",
1000 "properties": {
tiernofd160572019-01-21 10:41:37 +00001001 "name": shortname_schema,
1002 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001003 "description": description_schema,
1004 "shared": bool_schema,
1005 "vims": nameshort_list_schema,
1006 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001007 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +02001008 },
1009 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +01001010 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +02001011}
tiernocb83c942018-09-24 17:28:13 +02001012pdu_edit_schema = {
1013 "title": "pdu edit input schema",
1014 "$schema": "http://json-schema.org/draft-04/schema#",
1015 "type": "object",
1016 "properties": {
tiernofd160572019-01-21 10:41:37 +00001017 "name": shortname_schema,
1018 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001019 "description": description_schema,
1020 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +01001021 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1022 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +01001023 "interfaces": {
1024 "oneOf": [
1025 array_edition_schema,
1026 {"type": "array", "items": pdu_interface, "minItems": 1},
1027 ]
1028 },
tiernocb83c942018-09-24 17:28:13 +02001029 },
1030 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001031 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001032}
1033
delacruzramo271d2002019-12-02 21:00:37 +01001034# VNF PKG OPERATIONS
1035vnfpkgop_new_schema = {
1036 "title": "VNF PKG operation creation input schema",
1037 "$schema": "http://json-schema.org/draft-04/schema#",
1038 "type": "object",
1039 "properties": {
1040 "lcmOperationType": string_schema,
1041 "vnfPkgId": id_schema,
1042 "kdu_name": name_schema,
1043 "primitive": name_schema,
1044 "primitive_params": {"type": "object"},
1045 },
garciadeblas4568a372021-03-24 09:19:48 +01001046 "required": [
1047 "lcmOperationType",
1048 "vnfPkgId",
1049 "kdu_name",
1050 "primitive",
1051 "primitive_params",
1052 ],
1053 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001054}
1055
tiernocb83c942018-09-24 17:28:13 +02001056# USERS
tiernocf042d32019-06-13 09:06:40 +00001057project_role_mappings = {
1058 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001059 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001060 "type": "array",
1061 "items": {
1062 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001063 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001064 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001065 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001066 },
garciadeblas4568a372021-03-24 09:19:48 +01001067 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001068}
1069project_role_mappings_optional = {
1070 "title": "list of projects/roles or projects only",
1071 "$schema": "http://json-schema.org/draft-04/schema#",
1072 "type": "array",
1073 "items": {
1074 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001075 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001076 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001077 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001078 },
garciadeblas4568a372021-03-24 09:19:48 +01001079 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001080}
tiernocd54a4a2018-09-12 16:40:35 +02001081user_new_schema = {
1082 "$schema": "http://json-schema.org/draft-04/schema#",
1083 "title": "New user schema",
1084 "type": "object",
1085 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001086 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001087 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001088 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001089 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001090 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001091 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001092 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001093 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001094}
1095user_edit_schema = {
1096 "$schema": "http://json-schema.org/draft-04/schema#",
1097 "title": "User edit schema for administrators",
1098 "type": "object",
1099 "properties": {
1100 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001101 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001102 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001103 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001104 "project_role_mappings": project_role_mappings,
1105 "add_project_role_mappings": project_role_mappings,
1106 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +02001107 },
1108 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001109 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001110}
1111
1112# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001113topics_with_quota = [
1114 "vnfds",
1115 "nsds",
1116 "slice_templates",
1117 "pduds",
1118 "ns_instances",
1119 "slice_instances",
1120 "vim_accounts",
1121 "wim_accounts",
1122 "sdn_controllers",
1123 "k8sclusters",
1124 "vca",
1125 "k8srepos",
1126 "osmrepos",
1127 "ns_subscriptions",
1128]
tiernocd54a4a2018-09-12 16:40:35 +02001129project_new_schema = {
1130 "$schema": "http://json-schema.org/draft-04/schema#",
1131 "title": "New project schema for administrators",
1132 "type": "object",
1133 "properties": {
tiernofd160572019-01-21 10:41:37 +00001134 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001135 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001136 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001137 "quotas": {
1138 "type": "object",
1139 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001140 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001141 },
tiernocd54a4a2018-09-12 16:40:35 +02001142 },
1143 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001144 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001145}
1146project_edit_schema = {
1147 "$schema": "http://json-schema.org/draft-04/schema#",
1148 "title": "Project edit schema for administrators",
1149 "type": "object",
1150 "properties": {
1151 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001152 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001153 "quotas": {
1154 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001155 "properties": {
1156 topic: {"oneOf": [integer0_schema, null_schema]}
1157 for topic in topics_with_quota
1158 },
1159 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001160 },
tiernocd54a4a2018-09-12 16:40:35 +02001161 },
1162 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001163 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001164}
1165
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001166# ROLES
1167roles_new_schema = {
1168 "$schema": "http://json-schema.org/draft-04/schema#",
1169 "title": "New role schema for administrators",
1170 "type": "object",
1171 "properties": {
1172 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001173 "permissions": {
1174 "type": "object",
1175 "patternProperties": {
1176 ".": bool_schema,
1177 },
1178 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001179 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001180 },
tierno1f029d82019-06-13 22:37:04 +00001181 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001182 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001183}
1184roles_edit_schema = {
1185 "$schema": "http://json-schema.org/draft-04/schema#",
1186 "title": "Roles edit schema for administrators",
1187 "type": "object",
1188 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001189 "name": shortname_schema,
1190 "permissions": {
1191 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001192 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001193 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001194 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001195 },
tierno1f029d82019-06-13 22:37:04 +00001196 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001197 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001198}
1199
tiernocd54a4a2018-09-12 16:40:35 +02001200# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001201
1202nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001203 "users": user_new_schema,
1204 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001205 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001206 "sdns": sdn_new_schema,
1207 "ns_instantiate": ns_instantiate,
1208 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001209 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001210 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001211 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001212 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001213}
1214
1215nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001216 "users": user_edit_schema,
1217 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001218 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001219 "sdns": sdn_edit_schema,
1220 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001221}
1222
Felipe Vicens07f31722018-10-29 15:16:44 +01001223# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001224nsi_subnet_instantiate = deepcopy(ns_instantiate)
1225nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1226nsi_subnet_instantiate["properties"]["id"] = name_schema
1227del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001228
1229nsi_vld_instantiate = {
1230 "title": "netslice vld instantiation params input schema",
1231 "$schema": "http://json-schema.org/draft-04/schema#",
1232 "type": "object",
1233 "properties": {
1234 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001235 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1236 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001237 "ip-profile": object_schema,
1238 },
delacruzramoc061f562019-04-05 11:00:02 +02001239 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001240 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001241}
1242
Felipe Vicens07f31722018-10-29 15:16:44 +01001243nsi_instantiate = {
1244 "title": "netslice action instantiate input schema",
1245 "$schema": "http://json-schema.org/draft-04/schema#",
1246 "type": "object",
1247 "properties": {
1248 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001249 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001250 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001251 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001252 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001253 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001254 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001255 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001256 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001257 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001258 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001259 "type": "array",
1260 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001261 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001262 },
garciadeblas4568a372021-03-24 09:19:48 +01001263 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001264 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001265 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001266 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001267}
1268
garciadeblas4568a372021-03-24 09:19:48 +01001269nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001270
garciadeblas4568a372021-03-24 09:19:48 +01001271nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001272
preethika.p329b8182020-04-22 12:25:39 +05301273nsinstancesubscriptionfilter_schema = {
1274 "title": "instance identifier schema",
1275 "$schema": "http://json-schema.org/draft-07/schema#",
1276 "type": "object",
1277 "properties": {
1278 "nsdIds": {"type": "array"},
1279 "vnfdIds": {"type": "array"},
1280 "pnfdIds": {"type": "array"},
1281 "nsInstanceIds": {"type": "array"},
1282 "nsInstanceNames": {"type": "array"},
1283 },
1284}
1285
1286nslcmsub_schema = {
1287 "title": "nslcmsubscription input schema",
1288 "$schema": "http://json-schema.org/draft-07/schema#",
1289 "type": "object",
1290 "properties": {
1291 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1292 "notificationTypes": {
1293 "type": "array",
1294 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001295 "enum": [
1296 "NsLcmOperationOccurrenceNotification",
1297 "NsChangeNotification",
1298 "NsIdentifierCreationNotification",
1299 "NsIdentifierDeletionNotification",
1300 ]
1301 },
preethika.p329b8182020-04-22 12:25:39 +05301302 },
1303 "operationTypes": {
1304 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001305 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301306 },
1307 "operationStates": {
1308 "type": "array",
1309 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001310 "enum": [
1311 "PROCESSING",
1312 "COMPLETED",
1313 "PARTIALLY_COMPLETED",
1314 "FAILED",
1315 "FAILED_TEMP",
1316 "ROLLING_BACK",
1317 "ROLLED_BACK",
1318 ]
1319 },
preethika.p329b8182020-04-22 12:25:39 +05301320 },
garciadeblas4568a372021-03-24 09:19:48 +01001321 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301322 "lcmOpNameImpactingNsComponent": {
1323 "type": "array",
1324 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001325 "enum": [
1326 "VNF_INSTANTIATE",
1327 "VNF_SCALE",
1328 "VNF_SCALE_TO_LEVEL",
1329 "VNF_CHANGE_FLAVOUR",
1330 "VNF_TERMINATE",
1331 "VNF_HEAL",
1332 "VNF_OPERATE",
1333 "VNF_CHANGE_EXT_CONN",
1334 "VNF_MODIFY_INFO",
1335 "NS_INSTANTIATE",
1336 "NS_SCALE",
1337 "NS_UPDATE",
1338 "NS_TERMINATE",
1339 "NS_HEAL",
1340 ]
1341 },
preethika.p329b8182020-04-22 12:25:39 +05301342 },
1343 "lcmOpOccStatusImpactingNsComponent": {
1344 "type": "array",
1345 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001346 "enum": [
1347 "START",
1348 "COMPLETED",
1349 "PARTIALLY_COMPLETED",
1350 "FAILED",
1351 "ROLLED_BACK",
1352 ]
1353 },
preethika.p329b8182020-04-22 12:25:39 +05301354 },
1355 },
1356 "allOf": [
1357 {
1358 "if": {
1359 "properties": {
1360 "notificationTypes": {
1361 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1362 }
1363 },
1364 },
1365 "then": {
1366 "anyOf": [
1367 {"required": ["operationTypes"]},
1368 {"required": ["operationStates"]},
1369 ]
garciadeblas4568a372021-03-24 09:19:48 +01001370 },
preethika.p329b8182020-04-22 12:25:39 +05301371 },
1372 {
1373 "if": {
1374 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001375 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301376 },
1377 },
1378 "then": {
1379 "anyOf": [
1380 {"required": ["nsComponentTypes"]},
1381 {"required": ["lcmOpNameImpactingNsComponent"]},
1382 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1383 ]
garciadeblas4568a372021-03-24 09:19:48 +01001384 },
1385 },
1386 ],
preethika.p329b8182020-04-22 12:25:39 +05301387}
1388
1389authentication_schema = {
1390 "title": "authentication schema for subscription",
1391 "$schema": "http://json-schema.org/draft-07/schema#",
1392 "type": "object",
1393 "properties": {
1394 "authType": {"enum": ["basic"]},
1395 "paramsBasic": {
1396 "type": "object",
1397 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001398 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301399 "password": passwd_schema,
1400 },
1401 },
1402 },
1403}
1404
1405subscription = {
1406 "title": "subscription input schema",
1407 "$schema": "http://json-schema.org/draft-07/schema#",
1408 "type": "object",
1409 "properties": {
1410 "filter": nslcmsub_schema,
1411 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001412 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301413 },
1414 "required": ["CallbackUri"],
1415}
1416
selvi.jf1004592022-04-29 05:42:35 +00001417vnflcmsub_schema = {
1418 "title": "vnflcmsubscription input schema",
1419 "$schema": "http://json-schema.org/draft-07/schema#",
1420 "type": "object",
1421 "properties": {
1422 "VnfInstanceSubscriptionFilter": {
1423 "type": "object",
1424 "properties": {
1425 "vnfdIds": {"type": "array"},
1426 "vnfInstanceIds": {"type": "array"},
1427 },
1428 },
1429 "notificationTypes": {
1430 "type": "array",
1431 "items": {
1432 "enum": [
1433 "VnfIdentifierCreationNotification",
1434 "VnfLcmOperationOccurrenceNotification",
garciadeblasf2af4a12023-01-24 16:56:54 +01001435 "VnfIdentifierDeletionNotification",
1436 ]
1437 },
selvi.jf1004592022-04-29 05:42:35 +00001438 },
1439 "operationTypes": {
1440 "type": "array",
1441 "items": {
1442 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001443 "INSTANTIATE",
1444 "SCALE",
1445 "SCALE_TO_LEVEL",
1446 "CHANGE_FLAVOUR",
1447 "TERMINATE",
1448 "HEAL",
1449 "OPERATE",
1450 "CHANGE_EXT_CONN",
1451 "MODIFY_INFO",
1452 "CREATE_SNAPSHOT",
1453 "REVERT_TO_SNAPSHOT",
1454 "CHANGE_VNFPKG",
1455 ]
1456 },
selvi.jf1004592022-04-29 05:42:35 +00001457 },
1458 "operationStates": {
1459 "type": "array",
1460 "items": {
1461 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001462 "STARTING",
1463 "PROCESSING",
1464 "COMPLETED",
1465 "FAILED_TEMP",
1466 "FAILED",
1467 "ROLLING_BACK",
1468 "ROLLED_BACK",
1469 ]
1470 },
1471 },
selvi.jf1004592022-04-29 05:42:35 +00001472 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001473 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1474}
selvi.jf1004592022-04-29 05:42:35 +00001475
1476vnf_subscription = {
1477 "title": "vnf subscription input schema",
1478 "$schema": "http://json-schema.org/draft-07/schema#",
1479 "type": "object",
1480 "properties": {
1481 "filter": vnflcmsub_schema,
1482 "CallbackUri": description_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +01001483 "authentication": authentication_schema,
selvi.jf1004592022-04-29 05:42:35 +00001484 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001485 "required": ["filter", "CallbackUri"],
selvi.jf1004592022-04-29 05:42:35 +00001486}
1487
tierno0f98af52018-03-19 10:28:22 +01001488
1489class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001490 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1491 self.http_code = http_code
1492 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001493
1494
tiernob24258a2018-10-04 18:39:49 +02001495def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001496 """
tiernocd54a4a2018-09-12 16:40:35 +02001497 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001498 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001499 :param schema_to_use: jsonschema to test
1500 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001501 """
1502 try:
tierno0f98af52018-03-19 10:28:22 +01001503 if schema_to_use:
1504 js_v(indata, schema_to_use)
1505 return None
1506 except js_e.ValidationError as e:
1507 if e.path:
tierno0da52252018-06-27 15:47:22 +02001508 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001509 else:
1510 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001511 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001512 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001513 raise ValidationError(
1514 "Bad json schema {}".format(schema_to_use),
1515 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1516 )
delacruzramoc061f562019-04-05 11:00:02 +02001517
1518
1519def is_valid_uuid(x):
1520 """
1521 Test for a valid UUID
1522 :param x: string to test
1523 :return: True if x is a valid uuid, False otherwise
1524 """
1525 try:
1526 if UUID(x):
1527 return True
tiernobdebce92019-07-01 15:36:49 +00001528 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001529 return False