blob: 58ecaf72a444f61d5970133ed9c20b3435af10bd [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,
140 "volume": {
141 "type": "array",
142 "minItems": 1,
143 "items": {
144 "type": "object",
145 "properties": {
146 "name": name_schema,
147 "vim-volume-id": name_schema,
148 },
149 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100150 "additionalProperties": False,
151 },
tierno441dbbf2018-07-10 12:52:48 +0200152 },
153 "interface": {
154 "type": "array",
155 "minItems": 1,
156 "items": {
157 "type": "object",
158 "properties": {
159 "name": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200160 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200161 "mac-address": mac_schema,
162 "floating-ip-required": bool_schema,
163 },
164 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100165 "additionalProperties": False,
166 },
167 },
tierno441dbbf2018-07-10 12:52:48 +0200168 },
169 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100170 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200171}
172
173ip_profile_dns_schema = {
174 "type": "array",
175 "minItems": 1,
176 "items": {
177 "type": "object",
178 "properties": {
garciadeblas9fb32712022-04-04 16:33:59 +0200179 "address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200180 },
181 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100182 "additionalProperties": False,
183 },
tierno441dbbf2018-07-10 12:52:48 +0200184}
185
186ip_profile_dhcp_schema = {
187 "type": "object",
188 "properties": {
189 "enabled": {"type": "boolean"},
190 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100191 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200192 },
193 "additionalProperties": False,
194}
195
196ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000197 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200198 "$schema": "http://json-schema.org/draft-04/schema#",
199 "type": "object",
200 "properties": {
201 "ip-version": {"enum": ["ipv4", "ipv6"]},
202 "subnet-address": ip_prefix_schema,
203 "gateway-address": ip_schema,
204 "dns-server": ip_profile_dns_schema,
205 "dhcp-params": ip_profile_dhcp_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100206 },
tierno441dbbf2018-07-10 12:52:48 +0200207}
208
209ip_profile_update_schema = {
tierno2a929042020-03-10 16:34:25 +0000210 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200211 "$schema": "http://json-schema.org/draft-04/schema#",
212 "type": "object",
213 "properties": {
214 "ip-version": {"enum": ["ipv4", "ipv6"]},
215 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
216 "gateway-address": {"oneOf": [null_schema, ip_schema]},
217 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200218 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
219 },
garciadeblas4568a372021-03-24 09:19:48 +0100220 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200221}
222
kbsub21f03f52019-10-17 16:26:56 +0000223provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000224 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000225 "$schema": "http://json-schema.org/draft-04/schema#",
226 "type": "object",
227 "properties": {
228 "physical-network": name_schema,
229 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000230 "sdn-ports": { # external ports to append to the SDN-assist network
231 "type": "array",
232 "items": {
233 "type": "object",
234 "properties": {
235 "switch_id": shortname_schema,
236 "switch_port": shortname_schema,
237 "mac_address": mac_schema,
238 "vlan": vlan_schema,
239 },
garciadeblas4568a372021-03-24 09:19:48 +0100240 "additionalProperties": True,
241 },
tierno2a929042020-03-10 16:34:25 +0000242 },
243 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000244 },
garciadeblas4568a372021-03-24 09:19:48 +0100245 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000246}
247
tierno441dbbf2018-07-10 12:52:48 +0200248ns_instantiate_internal_vld = {
garciadeblas9fb32712022-04-04 16:33:59 +0200249 "title": "ns action instantiate input schema for vld",
tierno441dbbf2018-07-10 12:52:48 +0200250 "$schema": "http://json-schema.org/draft-04/schema#",
251 "type": "object",
252 "properties": {
253 "name": name_schema,
254 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100255 "vim-network-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200256 "ip-profile": ip_profile_update_schema,
kbsub21f03f52019-10-17 16:26:56 +0000257 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200258 "internal-connection-point": {
259 "type": "array",
260 "minItems": 1,
261 "items": {
262 "type": "object",
263 "properties": {
264 "id-ref": name_schema,
265 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200266 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200267 },
tiernob7c6f2a2018-09-03 14:32:10 +0200268 "required": ["id-ref"],
269 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100270 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200271 },
garciadeblas4568a372021-03-24 09:19:48 +0100272 },
tierno441dbbf2018-07-10 12:52:48 +0200273 },
274 "required": ["name"],
275 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100276 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200277}
tierno65acb4d2018-04-06 16:42:40 +0200278
tiernofd160572019-01-21 10:41:37 +0000279additional_params_for_vnf = {
280 "type": "array",
281 "items": {
282 "type": "object",
283 "properties": {
284 "member-vnf-index": name_schema,
285 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000286 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000287 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000288 "additionalParamsForVdu": {
289 "type": "array",
290 "items": {
291 "type": "object",
292 "properties": {
293 "vdu_id": name_schema,
294 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100295 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000296 },
tiernof62ac6a2020-04-29 13:46:13 +0000297 "required": ["vdu_id"],
298 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000299 "additionalProperties": False,
300 },
301 },
302 "additionalParamsForKdu": {
303 "type": "array",
304 "items": {
305 "type": "object",
306 "properties": {
307 "kdu_name": name_schema,
308 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000309 "kdu_model": name_schema,
310 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100311 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200312 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000313 },
tierno54db2e42020-04-06 15:29:42 +0000314 "required": ["kdu_name"],
315 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000316 "additionalProperties": False,
317 },
318 },
Alexis Romeroee31f532022-04-26 19:10:21 +0200319 "affinity-or-anti-affinity-group": {
320 "type": "array",
321 "items": {
322 "type": "object",
323 "properties": {
324 "id": name_schema,
325 "vim-affinity-group-id": name_schema,
326 },
327 "required": ["id"],
328 "minProperties": 2,
329 "additionalProperties": False,
330 },
331 },
tiernofd160572019-01-21 10:41:37 +0000332 },
tierno714954e2019-11-29 13:43:26 +0000333 "required": ["member-vnf-index"],
334 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100335 "additionalProperties": False,
336 },
tiernofd160572019-01-21 10:41:37 +0000337}
338
tierno65acb4d2018-04-06 16:42:40 +0200339ns_instantiate = {
340 "title": "ns action instantiate input schema",
341 "$schema": "http://json-schema.org/draft-04/schema#",
342 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200343 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200344 "lcmOperationType": string_schema,
345 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100346 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200347 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000348 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200349 "nsdId": id_schema,
350 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000351 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100352 "placement-engine": string_schema,
353 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000354 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000355 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100356 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000357 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100358 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000359 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200360 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200361 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200362 "vnf": {
363 "type": "array",
364 "minItems": 1,
365 "items": {
366 "type": "object",
367 "properties": {
368 "member-vnf-index": name_schema,
369 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200370 "vdu": {
371 "type": "array",
372 "minItems": 1,
373 "items": ns_instantiate_vdu,
374 },
375 "internal-vld": {
376 "type": "array",
377 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100378 "items": ns_instantiate_internal_vld,
379 },
tierno0da52252018-06-27 15:47:22 +0200380 },
tierno441dbbf2018-07-10 12:52:48 +0200381 "required": ["member-vnf-index"],
382 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100383 "additionalProperties": False,
384 },
tierno0da52252018-06-27 15:47:22 +0200385 },
386 "vld": {
387 "type": "array",
388 "minItems": 1,
389 "items": {
390 "type": "object",
391 "properties": {
392 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000393 "vim-network-name": {"oneOf": [string_schema, object_schema]},
394 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100395 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000396 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200397 "ip-profile": object_schema,
kbsub21f03f52019-10-17 16:26:56 +0000398 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200399 "vnfd-connection-point-ref": {
400 "type": "array",
401 "minItems": 1,
402 "items": {
403 "type": "object",
404 "properties": {
405 "member-vnf-index-ref": name_schema,
406 "vnfd-connection-point-ref": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200407 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernob7c6f2a2018-09-03 14:32:10 +0200408 # "mac-address": mac_schema,
409 },
garciadeblas4568a372021-03-24 09:19:48 +0100410 "required": [
411 "member-vnf-index-ref",
412 "vnfd-connection-point-ref",
413 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200414 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100415 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200416 },
garciadeblas4568a372021-03-24 09:19:48 +0100417 },
tierno0da52252018-06-27 15:47:22 +0200418 },
tierno441dbbf2018-07-10 12:52:48 +0200419 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100420 "additionalProperties": False,
421 },
tierno0da52252018-06-27 15:47:22 +0200422 },
423 },
tierno441dbbf2018-07-10 12:52:48 +0200424 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100425 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200426}
tierno0da52252018-06-27 15:47:22 +0200427
tierno1c38f2f2020-03-24 11:51:39 +0000428ns_terminate = {
429 "title": "ns terminate input schema",
430 "$schema": "http://json-schema.org/draft-04/schema#",
431 "type": "object",
432 "properties": {
433 "lcmOperationType": string_schema,
434 "nsInstanceId": id_schema,
435 "autoremove": bool_schema,
436 "timeout_ns_terminate": integer1_schema,
437 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000438 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000439 },
garciadeblas4568a372021-03-24 09:19:48 +0100440 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000441}
442
aticig544a2ae2022-04-05 09:00:17 +0300443ns_update = {
444 "title": "ns update input schema",
445 "$schema": "http://json-schema.org/draft-04/schema#",
446 "type": "object",
447 "properties": {
448 "lcmOperationType": string_schema,
449 "nsInstanceId": id_schema,
garciadeblaseab15072022-05-19 10:31:52 +0200450 "timeout_ns_update": integer1_schema,
aticig544a2ae2022-04-05 09:00:17 +0300451 "updateType": {
garciadeblasf2af4a12023-01-24 16:56:54 +0100452 "enum": [
453 "CHANGE_VNFPKG",
454 "REMOVE_VNF",
455 "MODIFY_VNF_INFORMATION",
456 "OPERATE_VNF",
457 ]
aticig544a2ae2022-04-05 09:00:17 +0300458 },
459 "modifyVnfInfoData": {
460 "type": "object",
461 "properties": {
462 "vnfInstanceId": id_schema,
463 "vnfdId": id_schema,
464 },
465 "required": ["vnfInstanceId", "vnfdId"],
466 },
467 "removeVnfInstanceId": id_schema,
468 "changeVnfPackageData": {
469 "type": "object",
470 "properties": {
471 "vnfInstanceId": id_schema,
472 "vnfdId": id_schema,
473 },
474 "required": ["vnfInstanceId", "vnfdId"],
475 },
k4.rahule3dca382022-04-29 12:30:36 +0000476 "operateVnfData": {
477 "type": "object",
478 "properties": {
479 "vnfInstanceId": id_schema,
480 "changeStateTo": name_schema,
481 "additionalParam": {
482 "type": "object",
483 "properties": {
484 "run-day1": bool_schema,
485 "vdu_id": name_schema,
486 "count-index": integer0_schema,
487 },
488 "required": ["vdu_id", "count-index"],
489 "additionalProperties": False,
garciadeblasf2af4a12023-01-24 16:56:54 +0100490 },
k4.rahule3dca382022-04-29 12:30:36 +0000491 },
492 "required": ["vnfInstanceId", "changeStateTo"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100493 },
aticig544a2ae2022-04-05 09:00:17 +0300494 },
495 "required": ["updateType"],
496 "additionalProperties": False,
497}
498
garciadeblas4568a372021-03-24 09:19:48 +0100499ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200500 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200501 "$schema": "http://json-schema.org/draft-04/schema#",
502 "type": "object",
503 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200504 "lcmOperationType": string_schema,
505 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200506 "member_vnf_index": name_schema,
507 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200508 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000509 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000510 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200511 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000512 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200513 "primitive_params": {"type": "object"},
514 },
garciadeblas4568a372021-03-24 09:19:48 +0100515 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
516 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200517}
garciadeblas0964edf2022-02-11 00:43:44 +0100518
garciadeblas4568a372021-03-24 09:19:48 +0100519ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200520 "title": "ns scale input schema",
521 "$schema": "http://json-schema.org/draft-04/schema#",
522 "type": "object",
523 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200524 "lcmOperationType": string_schema,
525 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200526 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000527 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200528 "scaleVnfData": {
529 "type": "object",
530 "properties": {
531 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100532 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200533 "scaleByStepData": {
534 "type": "object",
535 "properties": {
536 "scaling-group-descriptor": name_schema,
537 "member-vnf-index": name_schema,
538 "scaling-policy": name_schema,
539 },
540 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100541 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200542 },
543 },
544 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100545 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200546 },
547 "scaleTime": time_schema,
548 },
549 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100550 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200551}
tierno65acb4d2018-04-06 16:42:40 +0200552
elumalai8e3806c2022-04-28 17:26:24 +0530553ns_migrate = {
554 "title": "ns migrate input schema",
555 "$schema": "http://json-schema.org/draft-04/schema#",
556 "type": "object",
557 "properties": {
558 "lcmOperationType": string_schema,
559 "nsInstanceId": id_schema,
560 "vnfInstanceId": id_schema,
561 "migrateToHost": string_schema,
562 "vdu": {
563 "type": "object",
garciadeblasf2af4a12023-01-24 16:56:54 +0100564 "properties": {
565 "vduId": name_schema,
566 "vduCountIndex": integer0_schema,
567 },
568 "required": ["vduId"],
569 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530570 },
571 },
572 "required": ["vnfInstanceId"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100573 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530574}
tierno65acb4d2018-04-06 16:42:40 +0200575
garciadeblas0964edf2022-02-11 00:43:44 +0100576ns_heal = {
577 "title": "ns heal input schema",
578 "$schema": "http://json-schema.org/draft-04/schema#",
579 "type": "object",
580 "properties": {
581 "lcmOperationType": string_schema,
582 "nsInstanceId": id_schema,
583 "timeout_ns_heal": integer1_schema,
584 "healVnfData": {
585 "type": "array",
586 "items": {
587 "type": "object",
588 "properties": {
589 "vnfInstanceId": id_schema,
590 "cause": description_schema,
591 "additionalParams": {
592 "type": "object",
593 "properties": {
594 "run-day1": bool_schema,
595 "vdu": {
596 "type": "array",
597 "items": {
598 "type": "object",
599 "properties": {
600 "run-day1": bool_schema,
601 "vdu-id": name_schema,
602 "count-index": integer0_schema,
603 },
604 "required": ["vdu-id"],
605 "additionalProperties": False,
606 },
607 },
608 },
609 "additionalProperties": False,
610 },
611 },
612 "required": ["vnfInstanceId"],
613 "additionalProperties": False,
614 },
615 },
616 },
617 "required": ["healVnfData"],
618 "additionalProperties": False,
619}
620
govindarajul519da482022-04-29 19:05:22 +0530621ns_verticalscale = {
622 "title": "vertial scale input schema",
623 "$schema": "http://json-schema.org/draft-04/schema#",
624 "type": "object",
625 "properties": {
626 "lcmOperationType": string_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000627 "verticalScale": string_schema,
govindarajul519da482022-04-29 19:05:22 +0530628 "nsInstanceId": id_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000629 "changeVnfFlavorData": {
govindarajul519da482022-04-29 19:05:22 +0530630 "type": "object",
govindarajul69964ec2022-07-06 10:24:38 +0000631 "properties": {
632 "vnfInstanceId": id_schema,
633 "additionalParams": {
634 "type": "object",
635 "properties": {
636 "vduid": string_schema,
637 "vduCountIndex": integer0_schema,
638 "virtualMemory": integer1_schema,
639 "sizeOfStorage": integer0_schema,
640 "numVirtualCpu": integer1_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +0100641 },
govindarajul519da482022-04-29 19:05:22 +0530642 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100643 },
govindarajul69964ec2022-07-06 10:24:38 +0000644 "required": ["vnfInstanceId", "additionalParams"],
645 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530646 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100647 },
govindarajul69964ec2022-07-06 10:24:38 +0000648 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
649 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530650}
651
tierno0f98af52018-03-19 10:28:22 +0100652schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000653schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000654vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200655
tierno09c073e2018-04-26 13:36:48 +0200656vim_account_edit_schema = {
657 "title": "vim_account edit input schema",
658 "$schema": "http://json-schema.org/draft-04/schema#",
659 "type": "object",
660 "properties": {
661 "name": name_schema,
662 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200663 "vim": name_schema,
664 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200665 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200666 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200667 # "vim_url_admin": description_schema,
668 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200669 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200670 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200671 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200672 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100673 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000674 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200675 },
garciadeblas4568a372021-03-24 09:19:48 +0100676 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200677}
tierno0f98af52018-03-19 10:28:22 +0100678
tierno09c073e2018-04-26 13:36:48 +0200679vim_account_new_schema = {
680 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100681 "$schema": "http://json-schema.org/draft-04/schema#",
682 "type": "object",
683 "properties": {
684 "schema_version": schema_version,
685 "schema_type": schema_type,
686 "name": name_schema,
687 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200688 "vim": name_schema,
689 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200690 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100691 "vim_url": description_schema,
692 # "vim_url_admin": description_schema,
693 # "vim_tenant": name_schema,
694 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200695 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200696 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200697 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100698 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000699 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100700 },
garciadeblas4568a372021-03-24 09:19:48 +0100701 "required": [
702 "name",
703 "vim_url",
704 "vim_type",
705 "vim_user",
706 "vim_password",
707 "vim_tenant_name",
708 ],
709 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100710}
tierno0f98af52018-03-19 10:28:22 +0100711
tierno85807722019-12-20 14:11:35 +0000712wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200713
tierno55ba2e62018-12-11 17:22:22 +0000714wim_account_edit_schema = {
715 "title": "wim_account edit input schema",
716 "$schema": "http://json-schema.org/draft-04/schema#",
717 "type": "object",
718 "properties": {
719 "name": name_schema,
720 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000721 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200722 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000723 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100724 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000725 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100726 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000727 },
garciadeblas4568a372021-03-24 09:19:48 +0100728 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000729}
730
731wim_account_new_schema = {
732 "title": "wim_account creation input schema",
733 "$schema": "http://json-schema.org/draft-04/schema#",
734 "type": "object",
735 "properties": {
736 "schema_version": schema_version,
737 "schema_type": schema_type,
738 "name": name_schema,
739 "description": description_schema,
740 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200741 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000742 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100743 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000744 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000745 "config": {
746 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100747 "patternProperties": {".": {"not": {"type": "null"}}},
748 },
tierno55ba2e62018-12-11 17:22:22 +0000749 },
750 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100751 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000752}
tierno0f98af52018-03-19 10:28:22 +0100753
754sdn_properties = {
755 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000756 "type": {"type": "string"},
757 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100758 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000759 "password": passwd_schema,
760 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200761 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000762 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200763 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100764 "ip": ip_schema,
765 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100766 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100767}
768sdn_new_schema = {
769 "title": "sdn controller information schema",
770 "$schema": "http://json-schema.org/draft-04/schema#",
771 "type": "object",
772 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100773 "required": ["name", "type"],
774 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100775}
776sdn_edit_schema = {
777 "title": "sdn controller update information schema",
778 "$schema": "http://json-schema.org/draft-04/schema#",
779 "type": "object",
780 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200781 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100782 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100783}
784sdn_port_mapping_schema = {
785 "$schema": "http://json-schema.org/draft-04/schema#",
786 "title": "sdn port mapping information schema",
787 "type": "array",
788 "items": {
789 "type": "object",
790 "properties": {
tiernofd160572019-01-21 10:41:37 +0000791 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100792 "ports": {
793 "type": "array",
794 "items": {
795 "type": "object",
796 "properties": {
tierno42fce592018-11-02 09:23:43 +0100797 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000798 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100799 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100800 },
garciadeblas4568a372021-03-24 09:19:48 +0100801 "required": ["pci"],
802 },
803 },
tierno0f98af52018-03-19 10:28:22 +0100804 },
garciadeblas4568a372021-03-24 09:19:48 +0100805 "required": ["compute_node", "ports"],
806 },
tierno0f98af52018-03-19 10:28:22 +0100807}
808sdn_external_port_schema = {
809 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200810 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100811 "type": "object",
812 "properties": {
813 "port": {"type": "string", "minLength": 1, "maxLength": 60},
814 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100815 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100816 },
garciadeblas4568a372021-03-24 09:19:48 +0100817 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100818}
819
delacruzramofe598fe2019-10-23 18:25:11 +0200820# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500821k8scluster_deploy_method_schema = {
822 "$schema": "http://json-schema.org/draft-04/schema#",
823 "title": "Deployment methods for K8s cluster",
824 "type": "object",
825 "properties": {
826 "helm-chart": {"type": "boolean"},
827 "juju-bundle": {"type": "boolean"},
828 "helm-chart-v3": {"type": "boolean"},
829 },
830 "additionalProperties": False,
831 "minProperties": 3,
832}
delacruzramofe598fe2019-10-23 18:25:11 +0200833k8scluster_nets_schema = {
834 "title": "k8scluster nets input schema",
835 "$schema": "http://json-schema.org/draft-04/schema#",
836 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000837 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200838 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100839 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200840}
841k8scluster_new_schema = {
842 "title": "k8scluster creation input schema",
843 "$schema": "http://json-schema.org/draft-04/schema#",
844 "type": "object",
845 "properties": {
846 "schema_version": schema_version,
847 "schema_type": schema_type,
848 "name": name_schema,
849 "description": description_schema,
850 "credentials": object_schema,
851 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200852 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200853 "k8s_version": string_schema,
854 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500855 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200856 "namespace": name_schema,
857 "cni": nameshort_list_schema,
858 },
859 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100860 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200861}
862k8scluster_edit_schema = {
863 "title": "vim_account edit input schema",
864 "$schema": "http://json-schema.org/draft-04/schema#",
865 "type": "object",
866 "properties": {
867 "name": name_schema,
868 "description": description_schema,
869 "credentials": object_schema,
870 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200871 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200872 "k8s_version": string_schema,
873 "nets": k8scluster_nets_schema,
874 "namespace": name_schema,
875 "cni": nameshort_list_schema,
876 },
garciadeblas4568a372021-03-24 09:19:48 +0100877 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200878}
879
David Garciaecb41322021-03-31 19:10:46 +0200880# VCA
881vca_new_schema = {
882 "title": "vca creation input schema",
883 "$schema": "http://json-schema.org/draft-04/schema#",
884 "type": "object",
885 "properties": {
886 "schema_version": schema_version,
887 "schema_type": schema_type,
888 "name": name_schema,
889 "description": description_schema,
890 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100891 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200892 "secret": passwd_schema,
893 "cacert": long_description_schema,
894 "lxd-cloud": shortname_schema,
895 "lxd-credentials": shortname_schema,
896 "k8s-cloud": shortname_schema,
897 "k8s-credentials": shortname_schema,
898 "model-config": object_schema,
899 },
900 "required": [
901 "name",
902 "endpoints",
903 "user",
904 "secret",
905 "cacert",
906 "lxd-cloud",
907 "lxd-credentials",
908 "k8s-cloud",
909 "k8s-credentials",
910 ],
911 "additionalProperties": False,
912}
913vca_edit_schema = {
914 "title": "vca creation input schema",
915 "$schema": "http://json-schema.org/draft-04/schema#",
916 "type": "object",
917 "properties": {
918 "name": name_schema,
919 "description": description_schema,
920 "endpoints": description_list_schema,
921 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100922 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200923 "secret": passwd_schema,
924 "cacert": long_description_schema,
925 "lxd-cloud": shortname_schema,
926 "lxd-credentials": shortname_schema,
927 "k8s-cloud": shortname_schema,
928 "k8s-credentials": shortname_schema,
929 "model-config": object_schema,
930 },
931 "additionalProperties": False,
932}
933
delacruzramofe598fe2019-10-23 18:25:11 +0200934# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000935k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200936k8srepo_properties = {
937 "name": name_schema,
938 "description": description_schema,
939 "type": k8srepo_types,
940 "url": description_schema,
941}
942k8srepo_new_schema = {
943 "title": "k8scluster creation input schema",
944 "$schema": "http://json-schema.org/draft-04/schema#",
945 "type": "object",
946 "properties": k8srepo_properties,
947 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100948 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200949}
950k8srepo_edit_schema = {
951 "title": "vim_account edit input schema",
952 "$schema": "http://json-schema.org/draft-04/schema#",
953 "type": "object",
954 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100955 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200956}
957
Felipe Vicensb66b0412020-05-06 10:11:00 +0200958# OSM Repos
959osmrepo_types = {"enum": ["osm"]}
960osmrepo_properties = {
961 "name": name_schema,
962 "description": description_schema,
963 "type": osmrepo_types,
964 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100965 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200966 # "password": passwd_schema
967}
968osmrepo_new_schema = {
969 "title": "osm repo creation input schema",
970 "$schema": "http://json-schema.org/draft-04/schema#",
971 "type": "object",
972 "properties": osmrepo_properties,
973 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100974 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200975}
976osmrepo_edit_schema = {
977 "title": "osm repo edit input schema",
978 "$schema": "http://json-schema.org/draft-04/schema#",
979 "type": "object",
980 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100981 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200982}
983
tiernocb83c942018-09-24 17:28:13 +0200984# PDUs
985pdu_interface = {
986 "type": "object",
987 "properties": {
tiernofd160572019-01-21 10:41:37 +0000988 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200989 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100990 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200991 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200992 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100993 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000994 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
995 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100996 # # provide this in case SDN assist must deal with this interface
997 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000998 # "switch-port": shortname_schema,
999 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +01001000 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +02001001 },
tierno36ec8602018-11-02 17:27:11 +01001002 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +01001003 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001004}
tiernocb83c942018-09-24 17:28:13 +02001005pdu_new_schema = {
1006 "title": "pdu creation input schema",
1007 "$schema": "http://json-schema.org/draft-04/schema#",
1008 "type": "object",
1009 "properties": {
tiernofd160572019-01-21 10:41:37 +00001010 "name": shortname_schema,
1011 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001012 "description": description_schema,
1013 "shared": bool_schema,
1014 "vims": nameshort_list_schema,
1015 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001016 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +02001017 },
1018 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +01001019 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +02001020}
tiernocb83c942018-09-24 17:28:13 +02001021pdu_edit_schema = {
1022 "title": "pdu edit input schema",
1023 "$schema": "http://json-schema.org/draft-04/schema#",
1024 "type": "object",
1025 "properties": {
tiernofd160572019-01-21 10:41:37 +00001026 "name": shortname_schema,
1027 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001028 "description": description_schema,
1029 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +01001030 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1031 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +01001032 "interfaces": {
1033 "oneOf": [
1034 array_edition_schema,
1035 {"type": "array", "items": pdu_interface, "minItems": 1},
1036 ]
1037 },
tiernocb83c942018-09-24 17:28:13 +02001038 },
1039 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001040 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001041}
1042
delacruzramo271d2002019-12-02 21:00:37 +01001043# VNF PKG OPERATIONS
1044vnfpkgop_new_schema = {
1045 "title": "VNF PKG operation creation input schema",
1046 "$schema": "http://json-schema.org/draft-04/schema#",
1047 "type": "object",
1048 "properties": {
1049 "lcmOperationType": string_schema,
1050 "vnfPkgId": id_schema,
1051 "kdu_name": name_schema,
1052 "primitive": name_schema,
1053 "primitive_params": {"type": "object"},
1054 },
garciadeblas4568a372021-03-24 09:19:48 +01001055 "required": [
1056 "lcmOperationType",
1057 "vnfPkgId",
1058 "kdu_name",
1059 "primitive",
1060 "primitive_params",
1061 ],
1062 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001063}
1064
tiernocb83c942018-09-24 17:28:13 +02001065# USERS
tiernocf042d32019-06-13 09:06:40 +00001066project_role_mappings = {
1067 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001068 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001069 "type": "array",
1070 "items": {
1071 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001072 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001073 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001074 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001075 },
garciadeblas4568a372021-03-24 09:19:48 +01001076 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001077}
1078project_role_mappings_optional = {
1079 "title": "list of projects/roles or projects only",
1080 "$schema": "http://json-schema.org/draft-04/schema#",
1081 "type": "array",
1082 "items": {
1083 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001084 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001085 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001086 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001087 },
garciadeblas4568a372021-03-24 09:19:48 +01001088 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001089}
tiernocd54a4a2018-09-12 16:40:35 +02001090user_new_schema = {
1091 "$schema": "http://json-schema.org/draft-04/schema#",
1092 "title": "New user schema",
1093 "type": "object",
1094 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001095 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001096 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001097 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001098 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001099 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001100 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001101 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001102 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001103}
1104user_edit_schema = {
1105 "$schema": "http://json-schema.org/draft-04/schema#",
1106 "title": "User edit schema for administrators",
1107 "type": "object",
1108 "properties": {
1109 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001110 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001111 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001112 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001113 "project_role_mappings": project_role_mappings,
1114 "add_project_role_mappings": project_role_mappings,
1115 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +02001116 },
1117 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001118 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001119}
1120
1121# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001122topics_with_quota = [
1123 "vnfds",
1124 "nsds",
1125 "slice_templates",
1126 "pduds",
1127 "ns_instances",
1128 "slice_instances",
1129 "vim_accounts",
1130 "wim_accounts",
1131 "sdn_controllers",
1132 "k8sclusters",
1133 "vca",
1134 "k8srepos",
1135 "osmrepos",
1136 "ns_subscriptions",
1137]
tiernocd54a4a2018-09-12 16:40:35 +02001138project_new_schema = {
1139 "$schema": "http://json-schema.org/draft-04/schema#",
1140 "title": "New project schema for administrators",
1141 "type": "object",
1142 "properties": {
tiernofd160572019-01-21 10:41:37 +00001143 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001144 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001145 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001146 "quotas": {
1147 "type": "object",
1148 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001149 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001150 },
tiernocd54a4a2018-09-12 16:40:35 +02001151 },
1152 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001153 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001154}
1155project_edit_schema = {
1156 "$schema": "http://json-schema.org/draft-04/schema#",
1157 "title": "Project edit schema for administrators",
1158 "type": "object",
1159 "properties": {
1160 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001161 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001162 "quotas": {
1163 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001164 "properties": {
1165 topic: {"oneOf": [integer0_schema, null_schema]}
1166 for topic in topics_with_quota
1167 },
1168 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001169 },
tiernocd54a4a2018-09-12 16:40:35 +02001170 },
1171 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001172 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001173}
1174
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001175# ROLES
1176roles_new_schema = {
1177 "$schema": "http://json-schema.org/draft-04/schema#",
1178 "title": "New role schema for administrators",
1179 "type": "object",
1180 "properties": {
1181 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001182 "permissions": {
1183 "type": "object",
1184 "patternProperties": {
1185 ".": bool_schema,
1186 },
1187 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001188 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001189 },
tierno1f029d82019-06-13 22:37:04 +00001190 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001191 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001192}
1193roles_edit_schema = {
1194 "$schema": "http://json-schema.org/draft-04/schema#",
1195 "title": "Roles edit schema for administrators",
1196 "type": "object",
1197 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001198 "name": shortname_schema,
1199 "permissions": {
1200 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001201 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001202 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001203 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001204 },
tierno1f029d82019-06-13 22:37:04 +00001205 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001206 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001207}
1208
tiernocd54a4a2018-09-12 16:40:35 +02001209# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001210
1211nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001212 "users": user_new_schema,
1213 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001214 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001215 "sdns": sdn_new_schema,
1216 "ns_instantiate": ns_instantiate,
1217 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001218 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001219 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001220 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001221 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001222}
1223
1224nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001225 "users": user_edit_schema,
1226 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001227 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001228 "sdns": sdn_edit_schema,
1229 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001230}
1231
Felipe Vicens07f31722018-10-29 15:16:44 +01001232# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001233nsi_subnet_instantiate = deepcopy(ns_instantiate)
1234nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1235nsi_subnet_instantiate["properties"]["id"] = name_schema
1236del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001237
1238nsi_vld_instantiate = {
1239 "title": "netslice vld instantiation params input schema",
1240 "$schema": "http://json-schema.org/draft-04/schema#",
1241 "type": "object",
1242 "properties": {
1243 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001244 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1245 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001246 "ip-profile": object_schema,
1247 },
delacruzramoc061f562019-04-05 11:00:02 +02001248 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001249 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001250}
1251
Felipe Vicens07f31722018-10-29 15:16:44 +01001252nsi_instantiate = {
1253 "title": "netslice action instantiate input schema",
1254 "$schema": "http://json-schema.org/draft-04/schema#",
1255 "type": "object",
1256 "properties": {
1257 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001258 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001259 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001260 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001261 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001262 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001263 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001264 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001265 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001266 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001267 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001268 "type": "array",
1269 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001270 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001271 },
garciadeblas4568a372021-03-24 09:19:48 +01001272 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001273 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001274 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001275 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001276}
1277
garciadeblas4568a372021-03-24 09:19:48 +01001278nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001279
garciadeblas4568a372021-03-24 09:19:48 +01001280nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001281
preethika.p329b8182020-04-22 12:25:39 +05301282nsinstancesubscriptionfilter_schema = {
1283 "title": "instance identifier schema",
1284 "$schema": "http://json-schema.org/draft-07/schema#",
1285 "type": "object",
1286 "properties": {
1287 "nsdIds": {"type": "array"},
1288 "vnfdIds": {"type": "array"},
1289 "pnfdIds": {"type": "array"},
1290 "nsInstanceIds": {"type": "array"},
1291 "nsInstanceNames": {"type": "array"},
1292 },
1293}
1294
1295nslcmsub_schema = {
1296 "title": "nslcmsubscription input schema",
1297 "$schema": "http://json-schema.org/draft-07/schema#",
1298 "type": "object",
1299 "properties": {
1300 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1301 "notificationTypes": {
1302 "type": "array",
1303 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001304 "enum": [
1305 "NsLcmOperationOccurrenceNotification",
1306 "NsChangeNotification",
1307 "NsIdentifierCreationNotification",
1308 "NsIdentifierDeletionNotification",
1309 ]
1310 },
preethika.p329b8182020-04-22 12:25:39 +05301311 },
1312 "operationTypes": {
1313 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001314 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301315 },
1316 "operationStates": {
1317 "type": "array",
1318 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001319 "enum": [
1320 "PROCESSING",
1321 "COMPLETED",
1322 "PARTIALLY_COMPLETED",
1323 "FAILED",
1324 "FAILED_TEMP",
1325 "ROLLING_BACK",
1326 "ROLLED_BACK",
1327 ]
1328 },
preethika.p329b8182020-04-22 12:25:39 +05301329 },
garciadeblas4568a372021-03-24 09:19:48 +01001330 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301331 "lcmOpNameImpactingNsComponent": {
1332 "type": "array",
1333 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001334 "enum": [
1335 "VNF_INSTANTIATE",
1336 "VNF_SCALE",
1337 "VNF_SCALE_TO_LEVEL",
1338 "VNF_CHANGE_FLAVOUR",
1339 "VNF_TERMINATE",
1340 "VNF_HEAL",
1341 "VNF_OPERATE",
1342 "VNF_CHANGE_EXT_CONN",
1343 "VNF_MODIFY_INFO",
1344 "NS_INSTANTIATE",
1345 "NS_SCALE",
1346 "NS_UPDATE",
1347 "NS_TERMINATE",
1348 "NS_HEAL",
1349 ]
1350 },
preethika.p329b8182020-04-22 12:25:39 +05301351 },
1352 "lcmOpOccStatusImpactingNsComponent": {
1353 "type": "array",
1354 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001355 "enum": [
1356 "START",
1357 "COMPLETED",
1358 "PARTIALLY_COMPLETED",
1359 "FAILED",
1360 "ROLLED_BACK",
1361 ]
1362 },
preethika.p329b8182020-04-22 12:25:39 +05301363 },
1364 },
1365 "allOf": [
1366 {
1367 "if": {
1368 "properties": {
1369 "notificationTypes": {
1370 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1371 }
1372 },
1373 },
1374 "then": {
1375 "anyOf": [
1376 {"required": ["operationTypes"]},
1377 {"required": ["operationStates"]},
1378 ]
garciadeblas4568a372021-03-24 09:19:48 +01001379 },
preethika.p329b8182020-04-22 12:25:39 +05301380 },
1381 {
1382 "if": {
1383 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001384 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301385 },
1386 },
1387 "then": {
1388 "anyOf": [
1389 {"required": ["nsComponentTypes"]},
1390 {"required": ["lcmOpNameImpactingNsComponent"]},
1391 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1392 ]
garciadeblas4568a372021-03-24 09:19:48 +01001393 },
1394 },
1395 ],
preethika.p329b8182020-04-22 12:25:39 +05301396}
1397
1398authentication_schema = {
1399 "title": "authentication schema for subscription",
1400 "$schema": "http://json-schema.org/draft-07/schema#",
1401 "type": "object",
1402 "properties": {
1403 "authType": {"enum": ["basic"]},
1404 "paramsBasic": {
1405 "type": "object",
1406 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001407 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301408 "password": passwd_schema,
1409 },
1410 },
1411 },
1412}
1413
1414subscription = {
1415 "title": "subscription input schema",
1416 "$schema": "http://json-schema.org/draft-07/schema#",
1417 "type": "object",
1418 "properties": {
1419 "filter": nslcmsub_schema,
1420 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001421 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301422 },
1423 "required": ["CallbackUri"],
1424}
1425
selvi.jf1004592022-04-29 05:42:35 +00001426vnflcmsub_schema = {
1427 "title": "vnflcmsubscription input schema",
1428 "$schema": "http://json-schema.org/draft-07/schema#",
1429 "type": "object",
1430 "properties": {
1431 "VnfInstanceSubscriptionFilter": {
1432 "type": "object",
1433 "properties": {
1434 "vnfdIds": {"type": "array"},
1435 "vnfInstanceIds": {"type": "array"},
1436 },
1437 },
1438 "notificationTypes": {
1439 "type": "array",
1440 "items": {
1441 "enum": [
1442 "VnfIdentifierCreationNotification",
1443 "VnfLcmOperationOccurrenceNotification",
garciadeblasf2af4a12023-01-24 16:56:54 +01001444 "VnfIdentifierDeletionNotification",
1445 ]
1446 },
selvi.jf1004592022-04-29 05:42:35 +00001447 },
1448 "operationTypes": {
1449 "type": "array",
1450 "items": {
1451 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001452 "INSTANTIATE",
1453 "SCALE",
1454 "SCALE_TO_LEVEL",
1455 "CHANGE_FLAVOUR",
1456 "TERMINATE",
1457 "HEAL",
1458 "OPERATE",
1459 "CHANGE_EXT_CONN",
1460 "MODIFY_INFO",
1461 "CREATE_SNAPSHOT",
1462 "REVERT_TO_SNAPSHOT",
1463 "CHANGE_VNFPKG",
1464 ]
1465 },
selvi.jf1004592022-04-29 05:42:35 +00001466 },
1467 "operationStates": {
1468 "type": "array",
1469 "items": {
1470 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001471 "STARTING",
1472 "PROCESSING",
1473 "COMPLETED",
1474 "FAILED_TEMP",
1475 "FAILED",
1476 "ROLLING_BACK",
1477 "ROLLED_BACK",
1478 ]
1479 },
1480 },
selvi.jf1004592022-04-29 05:42:35 +00001481 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001482 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1483}
selvi.jf1004592022-04-29 05:42:35 +00001484
1485vnf_subscription = {
1486 "title": "vnf subscription input schema",
1487 "$schema": "http://json-schema.org/draft-07/schema#",
1488 "type": "object",
1489 "properties": {
1490 "filter": vnflcmsub_schema,
1491 "CallbackUri": description_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +01001492 "authentication": authentication_schema,
selvi.jf1004592022-04-29 05:42:35 +00001493 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001494 "required": ["filter", "CallbackUri"],
selvi.jf1004592022-04-29 05:42:35 +00001495}
1496
tierno0f98af52018-03-19 10:28:22 +01001497
1498class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001499 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1500 self.http_code = http_code
1501 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001502
1503
tiernob24258a2018-10-04 18:39:49 +02001504def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001505 """
tiernocd54a4a2018-09-12 16:40:35 +02001506 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001507 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001508 :param schema_to_use: jsonschema to test
1509 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001510 """
1511 try:
tierno0f98af52018-03-19 10:28:22 +01001512 if schema_to_use:
1513 js_v(indata, schema_to_use)
1514 return None
1515 except js_e.ValidationError as e:
1516 if e.path:
tierno0da52252018-06-27 15:47:22 +02001517 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001518 else:
1519 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001520 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001521 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001522 raise ValidationError(
1523 "Bad json schema {}".format(schema_to_use),
1524 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1525 )
delacruzramoc061f562019-04-05 11:00:02 +02001526
1527
1528def is_valid_uuid(x):
1529 """
1530 Test for a valid UUID
1531 :param x: string to test
1532 :return: True if x is a valid uuid, False otherwise
1533 """
1534 try:
1535 if UUID(x):
1536 return True
tiernobdebce92019-07-01 15:36:49 +00001537 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001538 return False