blob: 42283461de0b03a56103aeb719d76b68c6fd1aff [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 },
tierno441dbbf2018-07-10 12:52:48 +0200143 "volume": {
144 "type": "array",
145 "minItems": 1,
146 "items": {
147 "type": "object",
148 "properties": {
149 "name": name_schema,
150 "vim-volume-id": name_schema,
151 },
152 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100153 "additionalProperties": False,
154 },
tierno441dbbf2018-07-10 12:52:48 +0200155 },
156 "interface": {
157 "type": "array",
158 "minItems": 1,
159 "items": {
160 "type": "object",
161 "properties": {
162 "name": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200163 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200164 "mac-address": mac_schema,
165 "floating-ip-required": bool_schema,
166 },
167 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100168 "additionalProperties": False,
169 },
170 },
tierno441dbbf2018-07-10 12:52:48 +0200171 },
172 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100173 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200174}
175
176ip_profile_dns_schema = {
177 "type": "array",
178 "minItems": 1,
179 "items": {
180 "type": "object",
181 "properties": {
garciadeblas9fb32712022-04-04 16:33:59 +0200182 "address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200183 },
184 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100185 "additionalProperties": False,
186 },
tierno441dbbf2018-07-10 12:52:48 +0200187}
188
189ip_profile_dhcp_schema = {
190 "type": "object",
191 "properties": {
192 "enabled": {"type": "boolean"},
193 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100194 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200195 },
196 "additionalProperties": False,
197}
198
199ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000200 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200201 "$schema": "http://json-schema.org/draft-04/schema#",
202 "type": "object",
203 "properties": {
204 "ip-version": {"enum": ["ipv4", "ipv6"]},
205 "subnet-address": ip_prefix_schema,
206 "gateway-address": ip_schema,
207 "dns-server": ip_profile_dns_schema,
208 "dhcp-params": ip_profile_dhcp_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100209 },
tierno441dbbf2018-07-10 12:52:48 +0200210}
211
212ip_profile_update_schema = {
tierno2a929042020-03-10 16:34:25 +0000213 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200214 "$schema": "http://json-schema.org/draft-04/schema#",
215 "type": "object",
216 "properties": {
217 "ip-version": {"enum": ["ipv4", "ipv6"]},
218 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
219 "gateway-address": {"oneOf": [null_schema, ip_schema]},
220 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200221 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
222 },
garciadeblas4568a372021-03-24 09:19:48 +0100223 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200224}
225
kbsub21f03f52019-10-17 16:26:56 +0000226provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000227 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000228 "$schema": "http://json-schema.org/draft-04/schema#",
229 "type": "object",
230 "properties": {
231 "physical-network": name_schema,
232 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000233 "sdn-ports": { # external ports to append to the SDN-assist network
234 "type": "array",
235 "items": {
236 "type": "object",
237 "properties": {
238 "switch_id": shortname_schema,
239 "switch_port": shortname_schema,
240 "mac_address": mac_schema,
241 "vlan": vlan_schema,
242 },
garciadeblas4568a372021-03-24 09:19:48 +0100243 "additionalProperties": True,
244 },
tierno2a929042020-03-10 16:34:25 +0000245 },
246 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000247 },
garciadeblas4568a372021-03-24 09:19:48 +0100248 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000249}
250
tierno441dbbf2018-07-10 12:52:48 +0200251ns_instantiate_internal_vld = {
garciadeblas9fb32712022-04-04 16:33:59 +0200252 "title": "ns action instantiate input schema for vld",
tierno441dbbf2018-07-10 12:52:48 +0200253 "$schema": "http://json-schema.org/draft-04/schema#",
254 "type": "object",
255 "properties": {
256 "name": name_schema,
257 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100258 "vim-network-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200259 "ip-profile": ip_profile_update_schema,
kbsub21f03f52019-10-17 16:26:56 +0000260 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200261 "internal-connection-point": {
262 "type": "array",
263 "minItems": 1,
264 "items": {
265 "type": "object",
266 "properties": {
267 "id-ref": name_schema,
268 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200269 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200270 },
tiernob7c6f2a2018-09-03 14:32:10 +0200271 "required": ["id-ref"],
272 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100273 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200274 },
garciadeblas4568a372021-03-24 09:19:48 +0100275 },
tierno441dbbf2018-07-10 12:52:48 +0200276 },
277 "required": ["name"],
278 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100279 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200280}
tierno65acb4d2018-04-06 16:42:40 +0200281
tiernofd160572019-01-21 10:41:37 +0000282additional_params_for_vnf = {
283 "type": "array",
284 "items": {
285 "type": "object",
286 "properties": {
287 "member-vnf-index": name_schema,
288 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000289 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000290 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000291 "additionalParamsForVdu": {
292 "type": "array",
293 "items": {
294 "type": "object",
295 "properties": {
296 "vdu_id": name_schema,
297 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100298 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000299 },
tiernof62ac6a2020-04-29 13:46:13 +0000300 "required": ["vdu_id"],
301 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000302 "additionalProperties": False,
303 },
304 },
305 "additionalParamsForKdu": {
306 "type": "array",
307 "items": {
308 "type": "object",
309 "properties": {
310 "kdu_name": name_schema,
311 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000312 "kdu_model": name_schema,
313 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100314 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200315 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000316 },
tierno54db2e42020-04-06 15:29:42 +0000317 "required": ["kdu_name"],
318 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000319 "additionalProperties": False,
320 },
321 },
Alexis Romeroee31f532022-04-26 19:10:21 +0200322 "affinity-or-anti-affinity-group": {
323 "type": "array",
324 "items": {
325 "type": "object",
326 "properties": {
327 "id": name_schema,
328 "vim-affinity-group-id": name_schema,
329 },
330 "required": ["id"],
331 "minProperties": 2,
332 "additionalProperties": False,
333 },
334 },
tiernofd160572019-01-21 10:41:37 +0000335 },
tierno714954e2019-11-29 13:43:26 +0000336 "required": ["member-vnf-index"],
337 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100338 "additionalProperties": False,
339 },
tiernofd160572019-01-21 10:41:37 +0000340}
341
tierno65acb4d2018-04-06 16:42:40 +0200342ns_instantiate = {
343 "title": "ns action instantiate input schema",
344 "$schema": "http://json-schema.org/draft-04/schema#",
345 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200346 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200347 "lcmOperationType": string_schema,
348 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100349 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200350 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000351 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200352 "nsdId": id_schema,
353 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000354 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100355 "placement-engine": string_schema,
356 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000357 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000358 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100359 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000360 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100361 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000362 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200363 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200364 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200365 "vnf": {
366 "type": "array",
367 "minItems": 1,
368 "items": {
369 "type": "object",
370 "properties": {
371 "member-vnf-index": name_schema,
372 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200373 "vdu": {
374 "type": "array",
375 "minItems": 1,
376 "items": ns_instantiate_vdu,
377 },
378 "internal-vld": {
379 "type": "array",
380 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100381 "items": ns_instantiate_internal_vld,
382 },
tierno0da52252018-06-27 15:47:22 +0200383 },
tierno441dbbf2018-07-10 12:52:48 +0200384 "required": ["member-vnf-index"],
385 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100386 "additionalProperties": False,
387 },
tierno0da52252018-06-27 15:47:22 +0200388 },
389 "vld": {
390 "type": "array",
391 "minItems": 1,
392 "items": {
393 "type": "object",
394 "properties": {
395 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000396 "vim-network-name": {"oneOf": [string_schema, object_schema]},
397 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100398 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000399 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200400 "ip-profile": object_schema,
kbsub21f03f52019-10-17 16:26:56 +0000401 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200402 "vnfd-connection-point-ref": {
403 "type": "array",
404 "minItems": 1,
405 "items": {
406 "type": "object",
407 "properties": {
408 "member-vnf-index-ref": name_schema,
409 "vnfd-connection-point-ref": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200410 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernob7c6f2a2018-09-03 14:32:10 +0200411 # "mac-address": mac_schema,
412 },
garciadeblas4568a372021-03-24 09:19:48 +0100413 "required": [
414 "member-vnf-index-ref",
415 "vnfd-connection-point-ref",
416 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200417 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100418 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200419 },
garciadeblas4568a372021-03-24 09:19:48 +0100420 },
tierno0da52252018-06-27 15:47:22 +0200421 },
tierno441dbbf2018-07-10 12:52:48 +0200422 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100423 "additionalProperties": False,
424 },
tierno0da52252018-06-27 15:47:22 +0200425 },
426 },
tierno441dbbf2018-07-10 12:52:48 +0200427 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100428 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200429}
tierno0da52252018-06-27 15:47:22 +0200430
tierno1c38f2f2020-03-24 11:51:39 +0000431ns_terminate = {
432 "title": "ns terminate input schema",
433 "$schema": "http://json-schema.org/draft-04/schema#",
434 "type": "object",
435 "properties": {
436 "lcmOperationType": string_schema,
437 "nsInstanceId": id_schema,
438 "autoremove": bool_schema,
439 "timeout_ns_terminate": integer1_schema,
440 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000441 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000442 },
garciadeblas4568a372021-03-24 09:19:48 +0100443 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000444}
445
aticig544a2ae2022-04-05 09:00:17 +0300446ns_update = {
447 "title": "ns update input schema",
448 "$schema": "http://json-schema.org/draft-04/schema#",
449 "type": "object",
450 "properties": {
451 "lcmOperationType": string_schema,
452 "nsInstanceId": id_schema,
garciadeblaseab15072022-05-19 10:31:52 +0200453 "timeout_ns_update": integer1_schema,
aticig544a2ae2022-04-05 09:00:17 +0300454 "updateType": {
garciadeblasf2af4a12023-01-24 16:56:54 +0100455 "enum": [
456 "CHANGE_VNFPKG",
457 "REMOVE_VNF",
458 "MODIFY_VNF_INFORMATION",
459 "OPERATE_VNF",
460 ]
aticig544a2ae2022-04-05 09:00:17 +0300461 },
462 "modifyVnfInfoData": {
463 "type": "object",
464 "properties": {
465 "vnfInstanceId": id_schema,
466 "vnfdId": id_schema,
467 },
468 "required": ["vnfInstanceId", "vnfdId"],
469 },
470 "removeVnfInstanceId": id_schema,
471 "changeVnfPackageData": {
472 "type": "object",
473 "properties": {
474 "vnfInstanceId": id_schema,
475 "vnfdId": id_schema,
476 },
477 "required": ["vnfInstanceId", "vnfdId"],
478 },
k4.rahule3dca382022-04-29 12:30:36 +0000479 "operateVnfData": {
480 "type": "object",
481 "properties": {
482 "vnfInstanceId": id_schema,
483 "changeStateTo": name_schema,
484 "additionalParam": {
485 "type": "object",
486 "properties": {
487 "run-day1": bool_schema,
488 "vdu_id": name_schema,
489 "count-index": integer0_schema,
490 },
491 "required": ["vdu_id", "count-index"],
492 "additionalProperties": False,
garciadeblasf2af4a12023-01-24 16:56:54 +0100493 },
k4.rahule3dca382022-04-29 12:30:36 +0000494 },
495 "required": ["vnfInstanceId", "changeStateTo"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100496 },
aticig544a2ae2022-04-05 09:00:17 +0300497 },
498 "required": ["updateType"],
499 "additionalProperties": False,
500}
501
garciadeblas4568a372021-03-24 09:19:48 +0100502ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200503 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200504 "$schema": "http://json-schema.org/draft-04/schema#",
505 "type": "object",
506 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200507 "lcmOperationType": string_schema,
508 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200509 "member_vnf_index": name_schema,
510 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200511 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000512 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000513 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200514 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000515 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200516 "primitive_params": {"type": "object"},
517 },
garciadeblas4568a372021-03-24 09:19:48 +0100518 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
519 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200520}
garciadeblas0964edf2022-02-11 00:43:44 +0100521
garciadeblas4568a372021-03-24 09:19:48 +0100522ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200523 "title": "ns scale input schema",
524 "$schema": "http://json-schema.org/draft-04/schema#",
525 "type": "object",
526 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200527 "lcmOperationType": string_schema,
528 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200529 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000530 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200531 "scaleVnfData": {
532 "type": "object",
533 "properties": {
534 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100535 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200536 "scaleByStepData": {
537 "type": "object",
538 "properties": {
539 "scaling-group-descriptor": name_schema,
540 "member-vnf-index": name_schema,
541 "scaling-policy": name_schema,
542 },
543 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100544 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200545 },
546 },
547 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100548 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200549 },
550 "scaleTime": time_schema,
551 },
552 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100553 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200554}
tierno65acb4d2018-04-06 16:42:40 +0200555
elumalai8e3806c2022-04-28 17:26:24 +0530556ns_migrate = {
557 "title": "ns migrate input schema",
558 "$schema": "http://json-schema.org/draft-04/schema#",
559 "type": "object",
560 "properties": {
561 "lcmOperationType": string_schema,
562 "nsInstanceId": id_schema,
563 "vnfInstanceId": id_schema,
564 "migrateToHost": string_schema,
565 "vdu": {
566 "type": "object",
garciadeblasf2af4a12023-01-24 16:56:54 +0100567 "properties": {
568 "vduId": name_schema,
569 "vduCountIndex": integer0_schema,
570 },
571 "required": ["vduId"],
572 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530573 },
574 },
575 "required": ["vnfInstanceId"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100576 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530577}
tierno65acb4d2018-04-06 16:42:40 +0200578
garciadeblas0964edf2022-02-11 00:43:44 +0100579ns_heal = {
580 "title": "ns heal input schema",
581 "$schema": "http://json-schema.org/draft-04/schema#",
582 "type": "object",
583 "properties": {
584 "lcmOperationType": string_schema,
585 "nsInstanceId": id_schema,
586 "timeout_ns_heal": integer1_schema,
587 "healVnfData": {
588 "type": "array",
589 "items": {
590 "type": "object",
591 "properties": {
592 "vnfInstanceId": id_schema,
593 "cause": description_schema,
594 "additionalParams": {
595 "type": "object",
596 "properties": {
597 "run-day1": bool_schema,
598 "vdu": {
599 "type": "array",
600 "items": {
601 "type": "object",
602 "properties": {
603 "run-day1": bool_schema,
604 "vdu-id": name_schema,
605 "count-index": integer0_schema,
606 },
607 "required": ["vdu-id"],
608 "additionalProperties": False,
609 },
610 },
611 },
612 "additionalProperties": False,
613 },
614 },
615 "required": ["vnfInstanceId"],
616 "additionalProperties": False,
617 },
618 },
619 },
620 "required": ["healVnfData"],
621 "additionalProperties": False,
622}
623
govindarajul519da482022-04-29 19:05:22 +0530624ns_verticalscale = {
625 "title": "vertial scale input schema",
626 "$schema": "http://json-schema.org/draft-04/schema#",
627 "type": "object",
628 "properties": {
629 "lcmOperationType": string_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000630 "verticalScale": string_schema,
govindarajul519da482022-04-29 19:05:22 +0530631 "nsInstanceId": id_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000632 "changeVnfFlavorData": {
govindarajul519da482022-04-29 19:05:22 +0530633 "type": "object",
govindarajul69964ec2022-07-06 10:24:38 +0000634 "properties": {
635 "vnfInstanceId": id_schema,
636 "additionalParams": {
637 "type": "object",
638 "properties": {
639 "vduid": string_schema,
640 "vduCountIndex": integer0_schema,
641 "virtualMemory": integer1_schema,
642 "sizeOfStorage": integer0_schema,
643 "numVirtualCpu": integer1_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +0100644 },
govindarajul519da482022-04-29 19:05:22 +0530645 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100646 },
govindarajul69964ec2022-07-06 10:24:38 +0000647 "required": ["vnfInstanceId", "additionalParams"],
648 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530649 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100650 },
govindarajul69964ec2022-07-06 10:24:38 +0000651 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
652 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530653}
654
tierno0f98af52018-03-19 10:28:22 +0100655schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000656schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000657vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200658
tierno09c073e2018-04-26 13:36:48 +0200659vim_account_edit_schema = {
660 "title": "vim_account edit input schema",
661 "$schema": "http://json-schema.org/draft-04/schema#",
662 "type": "object",
663 "properties": {
664 "name": name_schema,
665 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200666 "vim": name_schema,
667 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200668 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200669 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200670 # "vim_url_admin": description_schema,
671 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200672 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200673 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200674 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200675 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100676 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000677 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200678 },
garciadeblas4568a372021-03-24 09:19:48 +0100679 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200680}
tierno0f98af52018-03-19 10:28:22 +0100681
tierno09c073e2018-04-26 13:36:48 +0200682vim_account_new_schema = {
683 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100684 "$schema": "http://json-schema.org/draft-04/schema#",
685 "type": "object",
686 "properties": {
687 "schema_version": schema_version,
688 "schema_type": schema_type,
689 "name": name_schema,
690 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200691 "vim": name_schema,
692 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200693 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100694 "vim_url": description_schema,
695 # "vim_url_admin": description_schema,
696 # "vim_tenant": name_schema,
697 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200698 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200699 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200700 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100701 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000702 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100703 },
garciadeblas4568a372021-03-24 09:19:48 +0100704 "required": [
705 "name",
706 "vim_url",
707 "vim_type",
708 "vim_user",
709 "vim_password",
710 "vim_tenant_name",
711 ],
712 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100713}
tierno0f98af52018-03-19 10:28:22 +0100714
tierno85807722019-12-20 14:11:35 +0000715wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200716
tierno55ba2e62018-12-11 17:22:22 +0000717wim_account_edit_schema = {
718 "title": "wim_account edit input schema",
719 "$schema": "http://json-schema.org/draft-04/schema#",
720 "type": "object",
721 "properties": {
722 "name": name_schema,
723 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000724 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200725 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000726 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100727 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000728 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100729 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000730 },
garciadeblas4568a372021-03-24 09:19:48 +0100731 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000732}
733
734wim_account_new_schema = {
735 "title": "wim_account creation input schema",
736 "$schema": "http://json-schema.org/draft-04/schema#",
737 "type": "object",
738 "properties": {
739 "schema_version": schema_version,
740 "schema_type": schema_type,
741 "name": name_schema,
742 "description": description_schema,
743 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200744 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000745 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100746 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000747 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000748 "config": {
749 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100750 "patternProperties": {".": {"not": {"type": "null"}}},
751 },
tierno55ba2e62018-12-11 17:22:22 +0000752 },
753 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100754 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000755}
tierno0f98af52018-03-19 10:28:22 +0100756
757sdn_properties = {
758 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000759 "type": {"type": "string"},
760 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100761 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000762 "password": passwd_schema,
763 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200764 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000765 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200766 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100767 "ip": ip_schema,
768 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100769 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100770}
771sdn_new_schema = {
772 "title": "sdn controller information schema",
773 "$schema": "http://json-schema.org/draft-04/schema#",
774 "type": "object",
775 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100776 "required": ["name", "type"],
777 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100778}
779sdn_edit_schema = {
780 "title": "sdn controller update information schema",
781 "$schema": "http://json-schema.org/draft-04/schema#",
782 "type": "object",
783 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200784 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100785 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100786}
787sdn_port_mapping_schema = {
788 "$schema": "http://json-schema.org/draft-04/schema#",
789 "title": "sdn port mapping information schema",
790 "type": "array",
791 "items": {
792 "type": "object",
793 "properties": {
tiernofd160572019-01-21 10:41:37 +0000794 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100795 "ports": {
796 "type": "array",
797 "items": {
798 "type": "object",
799 "properties": {
tierno42fce592018-11-02 09:23:43 +0100800 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000801 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100802 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100803 },
garciadeblas4568a372021-03-24 09:19:48 +0100804 "required": ["pci"],
805 },
806 },
tierno0f98af52018-03-19 10:28:22 +0100807 },
garciadeblas4568a372021-03-24 09:19:48 +0100808 "required": ["compute_node", "ports"],
809 },
tierno0f98af52018-03-19 10:28:22 +0100810}
811sdn_external_port_schema = {
812 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200813 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100814 "type": "object",
815 "properties": {
816 "port": {"type": "string", "minLength": 1, "maxLength": 60},
817 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100818 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100819 },
garciadeblas4568a372021-03-24 09:19:48 +0100820 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100821}
822
delacruzramofe598fe2019-10-23 18:25:11 +0200823# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500824k8scluster_deploy_method_schema = {
825 "$schema": "http://json-schema.org/draft-04/schema#",
826 "title": "Deployment methods for K8s cluster",
827 "type": "object",
828 "properties": {
829 "helm-chart": {"type": "boolean"},
830 "juju-bundle": {"type": "boolean"},
831 "helm-chart-v3": {"type": "boolean"},
832 },
833 "additionalProperties": False,
834 "minProperties": 3,
835}
delacruzramofe598fe2019-10-23 18:25:11 +0200836k8scluster_nets_schema = {
837 "title": "k8scluster nets input schema",
838 "$schema": "http://json-schema.org/draft-04/schema#",
839 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000840 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200841 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100842 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200843}
844k8scluster_new_schema = {
845 "title": "k8scluster creation input schema",
846 "$schema": "http://json-schema.org/draft-04/schema#",
847 "type": "object",
848 "properties": {
849 "schema_version": schema_version,
850 "schema_type": schema_type,
851 "name": name_schema,
852 "description": description_schema,
853 "credentials": object_schema,
854 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200855 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200856 "k8s_version": string_schema,
857 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500858 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200859 "namespace": name_schema,
860 "cni": nameshort_list_schema,
861 },
862 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100863 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200864}
865k8scluster_edit_schema = {
866 "title": "vim_account edit input schema",
867 "$schema": "http://json-schema.org/draft-04/schema#",
868 "type": "object",
869 "properties": {
870 "name": name_schema,
871 "description": description_schema,
872 "credentials": object_schema,
873 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200874 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200875 "k8s_version": string_schema,
876 "nets": k8scluster_nets_schema,
877 "namespace": name_schema,
878 "cni": nameshort_list_schema,
879 },
garciadeblas4568a372021-03-24 09:19:48 +0100880 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200881}
882
David Garciaecb41322021-03-31 19:10:46 +0200883# VCA
884vca_new_schema = {
885 "title": "vca creation input schema",
886 "$schema": "http://json-schema.org/draft-04/schema#",
887 "type": "object",
888 "properties": {
889 "schema_version": schema_version,
890 "schema_type": schema_type,
891 "name": name_schema,
892 "description": description_schema,
893 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100894 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200895 "secret": passwd_schema,
896 "cacert": long_description_schema,
897 "lxd-cloud": shortname_schema,
898 "lxd-credentials": shortname_schema,
899 "k8s-cloud": shortname_schema,
900 "k8s-credentials": shortname_schema,
901 "model-config": object_schema,
902 },
903 "required": [
904 "name",
905 "endpoints",
906 "user",
907 "secret",
908 "cacert",
909 "lxd-cloud",
910 "lxd-credentials",
911 "k8s-cloud",
912 "k8s-credentials",
913 ],
914 "additionalProperties": False,
915}
916vca_edit_schema = {
917 "title": "vca creation input schema",
918 "$schema": "http://json-schema.org/draft-04/schema#",
919 "type": "object",
920 "properties": {
921 "name": name_schema,
922 "description": description_schema,
923 "endpoints": description_list_schema,
924 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100925 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200926 "secret": passwd_schema,
927 "cacert": long_description_schema,
928 "lxd-cloud": shortname_schema,
929 "lxd-credentials": shortname_schema,
930 "k8s-cloud": shortname_schema,
931 "k8s-credentials": shortname_schema,
932 "model-config": object_schema,
933 },
934 "additionalProperties": False,
935}
936
delacruzramofe598fe2019-10-23 18:25:11 +0200937# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000938k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200939k8srepo_properties = {
940 "name": name_schema,
941 "description": description_schema,
942 "type": k8srepo_types,
943 "url": description_schema,
944}
945k8srepo_new_schema = {
946 "title": "k8scluster creation input schema",
947 "$schema": "http://json-schema.org/draft-04/schema#",
948 "type": "object",
949 "properties": k8srepo_properties,
950 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100951 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200952}
953k8srepo_edit_schema = {
954 "title": "vim_account edit input schema",
955 "$schema": "http://json-schema.org/draft-04/schema#",
956 "type": "object",
957 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100958 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200959}
960
Felipe Vicensb66b0412020-05-06 10:11:00 +0200961# OSM Repos
962osmrepo_types = {"enum": ["osm"]}
963osmrepo_properties = {
964 "name": name_schema,
965 "description": description_schema,
966 "type": osmrepo_types,
967 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100968 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200969 # "password": passwd_schema
970}
971osmrepo_new_schema = {
972 "title": "osm repo creation input schema",
973 "$schema": "http://json-schema.org/draft-04/schema#",
974 "type": "object",
975 "properties": osmrepo_properties,
976 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100977 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200978}
979osmrepo_edit_schema = {
980 "title": "osm repo edit input schema",
981 "$schema": "http://json-schema.org/draft-04/schema#",
982 "type": "object",
983 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100984 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200985}
986
tiernocb83c942018-09-24 17:28:13 +0200987# PDUs
988pdu_interface = {
989 "type": "object",
990 "properties": {
tiernofd160572019-01-21 10:41:37 +0000991 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200992 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100993 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200994 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200995 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100996 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000997 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
998 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100999 # # provide this in case SDN assist must deal with this interface
1000 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +00001001 # "switch-port": shortname_schema,
1002 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +01001003 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +02001004 },
tierno36ec8602018-11-02 17:27:11 +01001005 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +01001006 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001007}
tiernocb83c942018-09-24 17:28:13 +02001008pdu_new_schema = {
1009 "title": "pdu creation input schema",
1010 "$schema": "http://json-schema.org/draft-04/schema#",
1011 "type": "object",
1012 "properties": {
tiernofd160572019-01-21 10:41:37 +00001013 "name": shortname_schema,
1014 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001015 "description": description_schema,
1016 "shared": bool_schema,
1017 "vims": nameshort_list_schema,
1018 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001019 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +02001020 },
1021 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +01001022 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +02001023}
tiernocb83c942018-09-24 17:28:13 +02001024pdu_edit_schema = {
1025 "title": "pdu edit input schema",
1026 "$schema": "http://json-schema.org/draft-04/schema#",
1027 "type": "object",
1028 "properties": {
tiernofd160572019-01-21 10:41:37 +00001029 "name": shortname_schema,
1030 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001031 "description": description_schema,
1032 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +01001033 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1034 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +01001035 "interfaces": {
1036 "oneOf": [
1037 array_edition_schema,
1038 {"type": "array", "items": pdu_interface, "minItems": 1},
1039 ]
1040 },
tiernocb83c942018-09-24 17:28:13 +02001041 },
1042 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001043 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001044}
1045
delacruzramo271d2002019-12-02 21:00:37 +01001046# VNF PKG OPERATIONS
1047vnfpkgop_new_schema = {
1048 "title": "VNF PKG operation creation input schema",
1049 "$schema": "http://json-schema.org/draft-04/schema#",
1050 "type": "object",
1051 "properties": {
1052 "lcmOperationType": string_schema,
1053 "vnfPkgId": id_schema,
1054 "kdu_name": name_schema,
1055 "primitive": name_schema,
1056 "primitive_params": {"type": "object"},
1057 },
garciadeblas4568a372021-03-24 09:19:48 +01001058 "required": [
1059 "lcmOperationType",
1060 "vnfPkgId",
1061 "kdu_name",
1062 "primitive",
1063 "primitive_params",
1064 ],
1065 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001066}
1067
tiernocb83c942018-09-24 17:28:13 +02001068# USERS
tiernocf042d32019-06-13 09:06:40 +00001069project_role_mappings = {
1070 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001071 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001072 "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", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001077 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001078 },
garciadeblas4568a372021-03-24 09:19:48 +01001079 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001080}
1081project_role_mappings_optional = {
1082 "title": "list of projects/roles or projects only",
1083 "$schema": "http://json-schema.org/draft-04/schema#",
1084 "type": "array",
1085 "items": {
1086 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001087 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001088 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001089 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001090 },
garciadeblas4568a372021-03-24 09:19:48 +01001091 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001092}
tiernocd54a4a2018-09-12 16:40:35 +02001093user_new_schema = {
1094 "$schema": "http://json-schema.org/draft-04/schema#",
1095 "title": "New user schema",
1096 "type": "object",
1097 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001098 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001099 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001100 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001101 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001102 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001103 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001104 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001105 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001106}
1107user_edit_schema = {
1108 "$schema": "http://json-schema.org/draft-04/schema#",
1109 "title": "User edit schema for administrators",
1110 "type": "object",
1111 "properties": {
1112 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001113 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001114 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001115 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001116 "project_role_mappings": project_role_mappings,
1117 "add_project_role_mappings": project_role_mappings,
1118 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +02001119 },
1120 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001121 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001122}
1123
1124# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001125topics_with_quota = [
1126 "vnfds",
1127 "nsds",
1128 "slice_templates",
1129 "pduds",
1130 "ns_instances",
1131 "slice_instances",
1132 "vim_accounts",
1133 "wim_accounts",
1134 "sdn_controllers",
1135 "k8sclusters",
1136 "vca",
1137 "k8srepos",
1138 "osmrepos",
1139 "ns_subscriptions",
1140]
tiernocd54a4a2018-09-12 16:40:35 +02001141project_new_schema = {
1142 "$schema": "http://json-schema.org/draft-04/schema#",
1143 "title": "New project schema for administrators",
1144 "type": "object",
1145 "properties": {
tiernofd160572019-01-21 10:41:37 +00001146 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001147 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001148 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001149 "quotas": {
1150 "type": "object",
1151 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001152 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001153 },
tiernocd54a4a2018-09-12 16:40:35 +02001154 },
1155 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001156 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001157}
1158project_edit_schema = {
1159 "$schema": "http://json-schema.org/draft-04/schema#",
1160 "title": "Project edit schema for administrators",
1161 "type": "object",
1162 "properties": {
1163 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001164 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001165 "quotas": {
1166 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001167 "properties": {
1168 topic: {"oneOf": [integer0_schema, null_schema]}
1169 for topic in topics_with_quota
1170 },
1171 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001172 },
tiernocd54a4a2018-09-12 16:40:35 +02001173 },
1174 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001175 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001176}
1177
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001178# ROLES
1179roles_new_schema = {
1180 "$schema": "http://json-schema.org/draft-04/schema#",
1181 "title": "New role schema for administrators",
1182 "type": "object",
1183 "properties": {
1184 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001185 "permissions": {
1186 "type": "object",
1187 "patternProperties": {
1188 ".": bool_schema,
1189 },
1190 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001191 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001192 },
tierno1f029d82019-06-13 22:37:04 +00001193 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001194 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001195}
1196roles_edit_schema = {
1197 "$schema": "http://json-schema.org/draft-04/schema#",
1198 "title": "Roles edit schema for administrators",
1199 "type": "object",
1200 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001201 "name": shortname_schema,
1202 "permissions": {
1203 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001204 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001205 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001206 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001207 },
tierno1f029d82019-06-13 22:37:04 +00001208 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001209 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001210}
1211
tiernocd54a4a2018-09-12 16:40:35 +02001212# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001213
1214nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001215 "users": user_new_schema,
1216 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001217 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001218 "sdns": sdn_new_schema,
1219 "ns_instantiate": ns_instantiate,
1220 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001221 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001222 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001223 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001224 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001225}
1226
1227nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001228 "users": user_edit_schema,
1229 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001230 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001231 "sdns": sdn_edit_schema,
1232 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001233}
1234
Felipe Vicens07f31722018-10-29 15:16:44 +01001235# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001236nsi_subnet_instantiate = deepcopy(ns_instantiate)
1237nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1238nsi_subnet_instantiate["properties"]["id"] = name_schema
1239del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001240
1241nsi_vld_instantiate = {
1242 "title": "netslice vld instantiation params input schema",
1243 "$schema": "http://json-schema.org/draft-04/schema#",
1244 "type": "object",
1245 "properties": {
1246 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001247 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1248 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001249 "ip-profile": object_schema,
1250 },
delacruzramoc061f562019-04-05 11:00:02 +02001251 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001252 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001253}
1254
Felipe Vicens07f31722018-10-29 15:16:44 +01001255nsi_instantiate = {
1256 "title": "netslice action instantiate input schema",
1257 "$schema": "http://json-schema.org/draft-04/schema#",
1258 "type": "object",
1259 "properties": {
1260 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001261 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001262 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001263 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001264 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001265 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001266 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001267 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001268 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001269 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001270 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001271 "type": "array",
1272 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001273 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001274 },
garciadeblas4568a372021-03-24 09:19:48 +01001275 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001276 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001277 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001278 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001279}
1280
garciadeblas4568a372021-03-24 09:19:48 +01001281nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001282
garciadeblas4568a372021-03-24 09:19:48 +01001283nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001284
preethika.p329b8182020-04-22 12:25:39 +05301285nsinstancesubscriptionfilter_schema = {
1286 "title": "instance identifier schema",
1287 "$schema": "http://json-schema.org/draft-07/schema#",
1288 "type": "object",
1289 "properties": {
1290 "nsdIds": {"type": "array"},
1291 "vnfdIds": {"type": "array"},
1292 "pnfdIds": {"type": "array"},
1293 "nsInstanceIds": {"type": "array"},
1294 "nsInstanceNames": {"type": "array"},
1295 },
1296}
1297
1298nslcmsub_schema = {
1299 "title": "nslcmsubscription input schema",
1300 "$schema": "http://json-schema.org/draft-07/schema#",
1301 "type": "object",
1302 "properties": {
1303 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1304 "notificationTypes": {
1305 "type": "array",
1306 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001307 "enum": [
1308 "NsLcmOperationOccurrenceNotification",
1309 "NsChangeNotification",
1310 "NsIdentifierCreationNotification",
1311 "NsIdentifierDeletionNotification",
1312 ]
1313 },
preethika.p329b8182020-04-22 12:25:39 +05301314 },
1315 "operationTypes": {
1316 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001317 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301318 },
1319 "operationStates": {
1320 "type": "array",
1321 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001322 "enum": [
1323 "PROCESSING",
1324 "COMPLETED",
1325 "PARTIALLY_COMPLETED",
1326 "FAILED",
1327 "FAILED_TEMP",
1328 "ROLLING_BACK",
1329 "ROLLED_BACK",
1330 ]
1331 },
preethika.p329b8182020-04-22 12:25:39 +05301332 },
garciadeblas4568a372021-03-24 09:19:48 +01001333 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301334 "lcmOpNameImpactingNsComponent": {
1335 "type": "array",
1336 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001337 "enum": [
1338 "VNF_INSTANTIATE",
1339 "VNF_SCALE",
1340 "VNF_SCALE_TO_LEVEL",
1341 "VNF_CHANGE_FLAVOUR",
1342 "VNF_TERMINATE",
1343 "VNF_HEAL",
1344 "VNF_OPERATE",
1345 "VNF_CHANGE_EXT_CONN",
1346 "VNF_MODIFY_INFO",
1347 "NS_INSTANTIATE",
1348 "NS_SCALE",
1349 "NS_UPDATE",
1350 "NS_TERMINATE",
1351 "NS_HEAL",
1352 ]
1353 },
preethika.p329b8182020-04-22 12:25:39 +05301354 },
1355 "lcmOpOccStatusImpactingNsComponent": {
1356 "type": "array",
1357 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001358 "enum": [
1359 "START",
1360 "COMPLETED",
1361 "PARTIALLY_COMPLETED",
1362 "FAILED",
1363 "ROLLED_BACK",
1364 ]
1365 },
preethika.p329b8182020-04-22 12:25:39 +05301366 },
1367 },
1368 "allOf": [
1369 {
1370 "if": {
1371 "properties": {
1372 "notificationTypes": {
1373 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1374 }
1375 },
1376 },
1377 "then": {
1378 "anyOf": [
1379 {"required": ["operationTypes"]},
1380 {"required": ["operationStates"]},
1381 ]
garciadeblas4568a372021-03-24 09:19:48 +01001382 },
preethika.p329b8182020-04-22 12:25:39 +05301383 },
1384 {
1385 "if": {
1386 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001387 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301388 },
1389 },
1390 "then": {
1391 "anyOf": [
1392 {"required": ["nsComponentTypes"]},
1393 {"required": ["lcmOpNameImpactingNsComponent"]},
1394 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1395 ]
garciadeblas4568a372021-03-24 09:19:48 +01001396 },
1397 },
1398 ],
preethika.p329b8182020-04-22 12:25:39 +05301399}
1400
1401authentication_schema = {
1402 "title": "authentication schema for subscription",
1403 "$schema": "http://json-schema.org/draft-07/schema#",
1404 "type": "object",
1405 "properties": {
1406 "authType": {"enum": ["basic"]},
1407 "paramsBasic": {
1408 "type": "object",
1409 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001410 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301411 "password": passwd_schema,
1412 },
1413 },
1414 },
1415}
1416
1417subscription = {
1418 "title": "subscription input schema",
1419 "$schema": "http://json-schema.org/draft-07/schema#",
1420 "type": "object",
1421 "properties": {
1422 "filter": nslcmsub_schema,
1423 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001424 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301425 },
1426 "required": ["CallbackUri"],
1427}
1428
selvi.jf1004592022-04-29 05:42:35 +00001429vnflcmsub_schema = {
1430 "title": "vnflcmsubscription input schema",
1431 "$schema": "http://json-schema.org/draft-07/schema#",
1432 "type": "object",
1433 "properties": {
1434 "VnfInstanceSubscriptionFilter": {
1435 "type": "object",
1436 "properties": {
1437 "vnfdIds": {"type": "array"},
1438 "vnfInstanceIds": {"type": "array"},
1439 },
1440 },
1441 "notificationTypes": {
1442 "type": "array",
1443 "items": {
1444 "enum": [
1445 "VnfIdentifierCreationNotification",
1446 "VnfLcmOperationOccurrenceNotification",
garciadeblasf2af4a12023-01-24 16:56:54 +01001447 "VnfIdentifierDeletionNotification",
1448 ]
1449 },
selvi.jf1004592022-04-29 05:42:35 +00001450 },
1451 "operationTypes": {
1452 "type": "array",
1453 "items": {
1454 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001455 "INSTANTIATE",
1456 "SCALE",
1457 "SCALE_TO_LEVEL",
1458 "CHANGE_FLAVOUR",
1459 "TERMINATE",
1460 "HEAL",
1461 "OPERATE",
1462 "CHANGE_EXT_CONN",
1463 "MODIFY_INFO",
1464 "CREATE_SNAPSHOT",
1465 "REVERT_TO_SNAPSHOT",
1466 "CHANGE_VNFPKG",
1467 ]
1468 },
selvi.jf1004592022-04-29 05:42:35 +00001469 },
1470 "operationStates": {
1471 "type": "array",
1472 "items": {
1473 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001474 "STARTING",
1475 "PROCESSING",
1476 "COMPLETED",
1477 "FAILED_TEMP",
1478 "FAILED",
1479 "ROLLING_BACK",
1480 "ROLLED_BACK",
1481 ]
1482 },
1483 },
selvi.jf1004592022-04-29 05:42:35 +00001484 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001485 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1486}
selvi.jf1004592022-04-29 05:42:35 +00001487
1488vnf_subscription = {
1489 "title": "vnf subscription input schema",
1490 "$schema": "http://json-schema.org/draft-07/schema#",
1491 "type": "object",
1492 "properties": {
1493 "filter": vnflcmsub_schema,
1494 "CallbackUri": description_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +01001495 "authentication": authentication_schema,
selvi.jf1004592022-04-29 05:42:35 +00001496 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001497 "required": ["filter", "CallbackUri"],
selvi.jf1004592022-04-29 05:42:35 +00001498}
1499
tierno0f98af52018-03-19 10:28:22 +01001500
1501class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001502 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1503 self.http_code = http_code
1504 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001505
1506
tiernob24258a2018-10-04 18:39:49 +02001507def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001508 """
tiernocd54a4a2018-09-12 16:40:35 +02001509 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001510 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001511 :param schema_to_use: jsonschema to test
1512 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001513 """
1514 try:
tierno0f98af52018-03-19 10:28:22 +01001515 if schema_to_use:
1516 js_v(indata, schema_to_use)
1517 return None
1518 except js_e.ValidationError as e:
1519 if e.path:
tierno0da52252018-06-27 15:47:22 +02001520 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001521 else:
1522 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001523 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001524 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001525 raise ValidationError(
1526 "Bad json schema {}".format(schema_to_use),
1527 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1528 )
delacruzramoc061f562019-04-05 11:00:02 +02001529
1530
1531def is_valid_uuid(x):
1532 """
1533 Test for a valid UUID
1534 :param x: string to test
1535 :return: True if x is a valid uuid, False otherwise
1536 """
1537 try:
1538 if UUID(x):
1539 return True
tiernobdebce92019-07-01 15:36:49 +00001540 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001541 return False