blob: 620272f5ec3eeed4dddc9754490452d22ae68888 [file] [log] [blame]
tierno0f98af52018-03-19 10:28:22 +01001# -*- coding: utf-8 -*-
2
tiernod125caf2018-11-22 16:05:54 +00003# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
tierno0f98af52018-03-19 10:28:22 +010016from jsonschema import validate as js_v, exceptions as js_e
tierno36ec8602018-11-02 17:27:11 +010017from http import HTTPStatus
garciadeblasdaf8cc52018-11-30 14:17:20 +010018from copy import deepcopy
garciadeblas4568a372021-03-24 09:19:48 +010019from uuid import UUID # To test for valid UUID
tierno0f98af52018-03-19 10:28:22 +010020
21__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
22__version__ = "0.1"
23version_date = "Mar 2018"
24
25"""
26Validator of input data using JSON schemas for those items that not contains an OSM yang information model
27"""
28
29# Basis schemas
30patern_name = "^[ -~]+$"
garciadeblas4568a372021-03-24 09:19:48 +010031shortname_schema = {
32 "type": "string",
33 "minLength": 1,
34 "maxLength": 60,
35 "pattern": "^[^,;()\\.\\$'\"]+$",
36}
tierno0f98af52018-03-19 10:28:22 +010037passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
garciadeblas6d83f8f2023-06-19 22:34:49 +020038user_passwd_schema = {
39 "type": "string",
40 "pattern": "^.*(?=.{8,})((?=.*[!@#$%^&*()\\-_=+{};:,<.>]){1})(?=.*\\d)((?=.*[a-z]){1})((?=.*[A-Z]){1}).*$",
41}
garciadeblas4568a372021-03-24 09:19:48 +010042name_schema = {
43 "type": "string",
44 "minLength": 1,
45 "maxLength": 255,
46 "pattern": "^[^,;()'\"]+$",
47}
tierno0da52252018-06-27 15:47:22 +020048string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
garciadeblas4568a372021-03-24 09:19:48 +010049xml_text_schema = {
50 "type": "string",
51 "minLength": 1,
52 "maxLength": 1000,
53 "pattern": "^[^']+$",
54}
55description_schema = {
56 "type": ["string", "null"],
57 "maxLength": 255,
58 "pattern": "^[^'\"]+$",
59}
60long_description_schema = {
61 "type": ["string", "null"],
62 "maxLength": 3000,
63 "pattern": "^[^'\"]+$",
64}
tierno441dbbf2018-07-10 12:52:48 +020065id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
66bool_schema = {"type": "boolean"}
67null_schema = {"type": "null"}
tierno2236d202018-05-16 19:05:16 +020068# "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
garciadeblas4568a372021-03-24 09:19:48 +010069id_schema = {
70 "type": "string",
71 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
72}
73time_schema = {
74 "type": "string",
75 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}",
76}
77pci_schema = {
78 "type": "string",
79 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$",
80}
tierno42fce592018-11-02 09:23:43 +010081# allows [] for wildcards. For that reason huge length limit is set
82pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
K Sai Kiran990ac462020-05-20 12:25:12 +053083http_schema = {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
tierno0f98af52018-03-19 10:28:22 +010084bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
85memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
86integer0_schema = {"type": "integer", "minimum": 0}
87integer1_schema = {"type": "integer", "minimum": 1}
tierno87006042018-10-24 12:50:20 +020088path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
tierno0f98af52018-03-19 10:28:22 +010089vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
90vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
garciadeblas4568a372021-03-24 09:19:48 +010091mac_schema = {
92 "type": "string",
93 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$",
94} # must be unicast: LSB bit of MSB byte ==0
tiernocb83c942018-09-24 17:28:13 +020095dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
tierno0f98af52018-03-19 10:28:22 +010096# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
garciadeblas4568a372021-03-24 09:19:48 +010097ip_schema = {
98 "type": "string",
99 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$",
100}
garciadeblas1a01e1f2021-10-26 17:27:35 +0200101ipv6_schema = {
102 "type": "string",
garciadeblasf2af4a12023-01-24 16:56:54 +0100103 "pattern": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))", # noqa: W605
garciadeblas1a01e1f2021-10-26 17:27:35 +0200104}
garciadeblas4568a372021-03-24 09:19:48 +0100105ip_prefix_schema = {
106 "type": "string",
107 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
108 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$",
109}
tierno0f98af52018-03-19 10:28:22 +0100110port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
111object_schema = {"type": "object"}
112schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
113# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
garciadeblas4568a372021-03-24 09:19:48 +0100114log_level_schema = {
115 "type": "string",
116 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
117}
tierno0f98af52018-03-19 10:28:22 +0100118checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
119size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +0200120array_edition_schema = {
121 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100122 "patternProperties": {"^\\$": {}},
tiernocd54a4a2018-09-12 16:40:35 +0200123 "additionalProperties": False,
124 "minProperties": 1,
125}
tiernocb83c942018-09-24 17:28:13 +0200126nameshort_list_schema = {
127 "type": "array",
128 "minItems": 1,
tiernofd160572019-01-21 10:41:37 +0000129 "items": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200130}
tiernocd54a4a2018-09-12 16:40:35 +0200131
David Garciaecb41322021-03-31 19:10:46 +0200132description_list_schema = {
133 "type": "array",
134 "minItems": 1,
135 "items": description_schema,
136}
tierno0f98af52018-03-19 10:28:22 +0100137
tierno441dbbf2018-07-10 12:52:48 +0200138ns_instantiate_vdu = {
139 "title": "ns action instantiate input schema for vdu",
140 "$schema": "http://json-schema.org/draft-04/schema#",
141 "type": "object",
142 "properties": {
143 "id": name_schema,
Gabriel Cubae88401b2023-04-05 15:24:52 -0500144 "vim-flavor-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200145 "volume": {
146 "type": "array",
147 "minItems": 1,
148 "items": {
149 "type": "object",
150 "properties": {
151 "name": name_schema,
152 "vim-volume-id": name_schema,
153 },
154 "required": ["name", "vim-volume-id"],
garciadeblas4568a372021-03-24 09:19:48 +0100155 "additionalProperties": False,
156 },
tierno441dbbf2018-07-10 12:52:48 +0200157 },
158 "interface": {
159 "type": "array",
160 "minItems": 1,
161 "items": {
162 "type": "object",
163 "properties": {
164 "name": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200165 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200166 "mac-address": mac_schema,
167 "floating-ip-required": bool_schema,
168 },
169 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100170 "additionalProperties": False,
171 },
172 },
tierno441dbbf2018-07-10 12:52:48 +0200173 },
174 "required": ["id"],
garciadeblas4568a372021-03-24 09:19:48 +0100175 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200176}
177
178ip_profile_dns_schema = {
179 "type": "array",
180 "minItems": 1,
181 "items": {
182 "type": "object",
183 "properties": {
garciadeblas9fb32712022-04-04 16:33:59 +0200184 "address": {"oneOf": [ip_schema, ipv6_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200185 },
186 "required": ["address"],
garciadeblas4568a372021-03-24 09:19:48 +0100187 "additionalProperties": False,
188 },
tierno441dbbf2018-07-10 12:52:48 +0200189}
190
191ip_profile_dhcp_schema = {
192 "type": "object",
193 "properties": {
194 "enabled": {"type": "boolean"},
195 "count": integer1_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100196 "start-address": ip_schema,
tierno441dbbf2018-07-10 12:52:48 +0200197 },
198 "additionalProperties": False,
199}
200
201ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000202 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200203 "$schema": "http://json-schema.org/draft-04/schema#",
204 "type": "object",
205 "properties": {
206 "ip-version": {"enum": ["ipv4", "ipv6"]},
tierno441dbbf2018-07-10 12:52:48 +0200207 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
208 "gateway-address": {"oneOf": [null_schema, ip_schema]},
209 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
tierno441dbbf2018-07-10 12:52:48 +0200210 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
211 },
garciadeblas4568a372021-03-24 09:19:48 +0100212 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200213}
214
kbsub21f03f52019-10-17 16:26:56 +0000215provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000216 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000217 "$schema": "http://json-schema.org/draft-04/schema#",
218 "type": "object",
219 "properties": {
220 "physical-network": name_schema,
221 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000222 "sdn-ports": { # external ports to append to the SDN-assist network
223 "type": "array",
224 "items": {
225 "type": "object",
226 "properties": {
227 "switch_id": shortname_schema,
228 "switch_port": shortname_schema,
229 "mac_address": mac_schema,
230 "vlan": vlan_schema,
231 },
garciadeblas4568a372021-03-24 09:19:48 +0100232 "additionalProperties": True,
233 },
tierno2a929042020-03-10 16:34:25 +0000234 },
235 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000236 },
garciadeblas4568a372021-03-24 09:19:48 +0100237 "additionalProperties": True,
kbsub21f03f52019-10-17 16:26:56 +0000238}
239
tierno441dbbf2018-07-10 12:52:48 +0200240ns_instantiate_internal_vld = {
garciadeblas9fb32712022-04-04 16:33:59 +0200241 "title": "ns action instantiate input schema for vld",
tierno441dbbf2018-07-10 12:52:48 +0200242 "$schema": "http://json-schema.org/draft-04/schema#",
243 "type": "object",
244 "properties": {
245 "name": name_schema,
246 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100247 "vim-network-id": name_schema,
garciadeblas120105b2023-02-22 16:52:24 +0100248 "ip-profile": ip_profile_schema,
kbsub21f03f52019-10-17 16:26:56 +0000249 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200250 "internal-connection-point": {
251 "type": "array",
252 "minItems": 1,
253 "items": {
254 "type": "object",
255 "properties": {
256 "id-ref": name_schema,
257 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200258 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200259 },
tiernob7c6f2a2018-09-03 14:32:10 +0200260 "required": ["id-ref"],
261 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100262 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200263 },
garciadeblas4568a372021-03-24 09:19:48 +0100264 },
tierno441dbbf2018-07-10 12:52:48 +0200265 },
266 "required": ["name"],
267 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100268 "additionalProperties": False,
tierno441dbbf2018-07-10 12:52:48 +0200269}
tierno65acb4d2018-04-06 16:42:40 +0200270
tiernofd160572019-01-21 10:41:37 +0000271additional_params_for_vnf = {
272 "type": "array",
273 "items": {
274 "type": "object",
275 "properties": {
276 "member-vnf-index": name_schema,
277 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000278 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000279 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000280 "additionalParamsForVdu": {
281 "type": "array",
282 "items": {
283 "type": "object",
284 "properties": {
285 "vdu_id": name_schema,
286 "additionalParams": object_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100287 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000288 },
tiernof62ac6a2020-04-29 13:46:13 +0000289 "required": ["vdu_id"],
290 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000291 "additionalProperties": False,
292 },
293 },
294 "additionalParamsForKdu": {
295 "type": "array",
296 "items": {
297 "type": "object",
298 "properties": {
299 "kdu_name": name_schema,
300 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000301 "kdu_model": name_schema,
302 "k8s-namespace": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100303 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
romeromonserbfebfc02021-05-28 10:51:35 +0200304 "kdu-deployment-name": name_schema,
tierno714954e2019-11-29 13:43:26 +0000305 },
tierno54db2e42020-04-06 15:29:42 +0000306 "required": ["kdu_name"],
307 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000308 "additionalProperties": False,
309 },
310 },
Alexis Romeroee31f532022-04-26 19:10:21 +0200311 "affinity-or-anti-affinity-group": {
312 "type": "array",
313 "items": {
314 "type": "object",
315 "properties": {
316 "id": name_schema,
317 "vim-affinity-group-id": name_schema,
318 },
319 "required": ["id"],
320 "minProperties": 2,
321 "additionalProperties": False,
322 },
323 },
tiernofd160572019-01-21 10:41:37 +0000324 },
tierno714954e2019-11-29 13:43:26 +0000325 "required": ["member-vnf-index"],
326 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100327 "additionalProperties": False,
328 },
tiernofd160572019-01-21 10:41:37 +0000329}
330
tierno65acb4d2018-04-06 16:42:40 +0200331ns_instantiate = {
332 "title": "ns action instantiate input schema",
333 "$schema": "http://json-schema.org/draft-04/schema#",
334 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200335 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200336 "lcmOperationType": string_schema,
337 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100338 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200339 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000340 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200341 "nsdId": id_schema,
342 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000343 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100344 "placement-engine": string_schema,
345 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000346 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000347 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100348 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000349 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100350 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000351 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200352 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200353 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200354 "vnf": {
355 "type": "array",
356 "minItems": 1,
357 "items": {
358 "type": "object",
359 "properties": {
360 "member-vnf-index": name_schema,
361 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200362 "vdu": {
363 "type": "array",
364 "minItems": 1,
365 "items": ns_instantiate_vdu,
366 },
367 "internal-vld": {
368 "type": "array",
369 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100370 "items": ns_instantiate_internal_vld,
371 },
tierno0da52252018-06-27 15:47:22 +0200372 },
tierno441dbbf2018-07-10 12:52:48 +0200373 "required": ["member-vnf-index"],
374 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100375 "additionalProperties": False,
376 },
tierno0da52252018-06-27 15:47:22 +0200377 },
378 "vld": {
379 "type": "array",
380 "minItems": 1,
381 "items": {
382 "type": "object",
383 "properties": {
384 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000385 "vim-network-name": {"oneOf": [string_schema, object_schema]},
386 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100387 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000388 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
garciadeblas120105b2023-02-22 16:52:24 +0100389 "ip-profile": ip_profile_schema,
kbsub21f03f52019-10-17 16:26:56 +0000390 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200391 "vnfd-connection-point-ref": {
392 "type": "array",
393 "minItems": 1,
394 "items": {
395 "type": "object",
396 "properties": {
397 "member-vnf-index-ref": name_schema,
398 "vnfd-connection-point-ref": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200399 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernob7c6f2a2018-09-03 14:32:10 +0200400 # "mac-address": mac_schema,
401 },
garciadeblas4568a372021-03-24 09:19:48 +0100402 "required": [
403 "member-vnf-index-ref",
404 "vnfd-connection-point-ref",
405 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200406 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100407 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200408 },
garciadeblas4568a372021-03-24 09:19:48 +0100409 },
tierno0da52252018-06-27 15:47:22 +0200410 },
tierno441dbbf2018-07-10 12:52:48 +0200411 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100412 "additionalProperties": False,
413 },
tierno0da52252018-06-27 15:47:22 +0200414 },
415 },
tierno441dbbf2018-07-10 12:52:48 +0200416 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100417 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200418}
tierno0da52252018-06-27 15:47:22 +0200419
tierno1c38f2f2020-03-24 11:51:39 +0000420ns_terminate = {
421 "title": "ns terminate input schema",
422 "$schema": "http://json-schema.org/draft-04/schema#",
423 "type": "object",
424 "properties": {
425 "lcmOperationType": string_schema,
426 "nsInstanceId": id_schema,
427 "autoremove": bool_schema,
428 "timeout_ns_terminate": integer1_schema,
429 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000430 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000431 },
garciadeblas4568a372021-03-24 09:19:48 +0100432 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000433}
434
aticig544a2ae2022-04-05 09:00:17 +0300435ns_update = {
436 "title": "ns update input schema",
437 "$schema": "http://json-schema.org/draft-04/schema#",
438 "type": "object",
439 "properties": {
440 "lcmOperationType": string_schema,
441 "nsInstanceId": id_schema,
garciadeblaseab15072022-05-19 10:31:52 +0200442 "timeout_ns_update": integer1_schema,
aticig544a2ae2022-04-05 09:00:17 +0300443 "updateType": {
garciadeblasf2af4a12023-01-24 16:56:54 +0100444 "enum": [
445 "CHANGE_VNFPKG",
446 "REMOVE_VNF",
447 "MODIFY_VNF_INFORMATION",
448 "OPERATE_VNF",
449 ]
aticig544a2ae2022-04-05 09:00:17 +0300450 },
451 "modifyVnfInfoData": {
452 "type": "object",
453 "properties": {
454 "vnfInstanceId": id_schema,
455 "vnfdId": id_schema,
456 },
457 "required": ["vnfInstanceId", "vnfdId"],
458 },
459 "removeVnfInstanceId": id_schema,
460 "changeVnfPackageData": {
461 "type": "object",
462 "properties": {
463 "vnfInstanceId": id_schema,
464 "vnfdId": id_schema,
465 },
466 "required": ["vnfInstanceId", "vnfdId"],
467 },
k4.rahule3dca382022-04-29 12:30:36 +0000468 "operateVnfData": {
469 "type": "object",
470 "properties": {
471 "vnfInstanceId": id_schema,
472 "changeStateTo": name_schema,
473 "additionalParam": {
474 "type": "object",
475 "properties": {
476 "run-day1": bool_schema,
477 "vdu_id": name_schema,
478 "count-index": integer0_schema,
479 },
480 "required": ["vdu_id", "count-index"],
481 "additionalProperties": False,
garciadeblasf2af4a12023-01-24 16:56:54 +0100482 },
k4.rahule3dca382022-04-29 12:30:36 +0000483 },
484 "required": ["vnfInstanceId", "changeStateTo"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100485 },
aticig544a2ae2022-04-05 09:00:17 +0300486 },
487 "required": ["updateType"],
488 "additionalProperties": False,
489}
490
garciadeblas4568a372021-03-24 09:19:48 +0100491ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200492 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200493 "$schema": "http://json-schema.org/draft-04/schema#",
494 "type": "object",
495 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200496 "lcmOperationType": string_schema,
497 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200498 "member_vnf_index": name_schema,
499 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200500 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000501 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000502 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200503 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000504 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200505 "primitive_params": {"type": "object"},
506 },
garciadeblas4568a372021-03-24 09:19:48 +0100507 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
508 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200509}
garciadeblas0964edf2022-02-11 00:43:44 +0100510
garciadeblas4568a372021-03-24 09:19:48 +0100511ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200512 "title": "ns scale input schema",
513 "$schema": "http://json-schema.org/draft-04/schema#",
514 "type": "object",
515 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200516 "lcmOperationType": string_schema,
517 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200518 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000519 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200520 "scaleVnfData": {
521 "type": "object",
522 "properties": {
523 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100524 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200525 "scaleByStepData": {
526 "type": "object",
527 "properties": {
528 "scaling-group-descriptor": name_schema,
529 "member-vnf-index": name_schema,
530 "scaling-policy": name_schema,
531 },
532 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100533 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200534 },
535 },
536 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100537 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200538 },
539 "scaleTime": time_schema,
540 },
541 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100542 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200543}
tierno65acb4d2018-04-06 16:42:40 +0200544
elumalai8e3806c2022-04-28 17:26:24 +0530545ns_migrate = {
546 "title": "ns migrate input schema",
547 "$schema": "http://json-schema.org/draft-04/schema#",
548 "type": "object",
549 "properties": {
550 "lcmOperationType": string_schema,
551 "nsInstanceId": id_schema,
552 "vnfInstanceId": id_schema,
553 "migrateToHost": string_schema,
554 "vdu": {
555 "type": "object",
garciadeblasf2af4a12023-01-24 16:56:54 +0100556 "properties": {
557 "vduId": name_schema,
558 "vduCountIndex": integer0_schema,
559 },
560 "required": ["vduId"],
561 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530562 },
563 },
564 "required": ["vnfInstanceId"],
garciadeblasf2af4a12023-01-24 16:56:54 +0100565 "additionalProperties": False,
elumalai8e3806c2022-04-28 17:26:24 +0530566}
tierno65acb4d2018-04-06 16:42:40 +0200567
garciadeblas0964edf2022-02-11 00:43:44 +0100568ns_heal = {
569 "title": "ns heal input schema",
570 "$schema": "http://json-schema.org/draft-04/schema#",
571 "type": "object",
572 "properties": {
573 "lcmOperationType": string_schema,
574 "nsInstanceId": id_schema,
575 "timeout_ns_heal": integer1_schema,
576 "healVnfData": {
577 "type": "array",
578 "items": {
579 "type": "object",
580 "properties": {
581 "vnfInstanceId": id_schema,
582 "cause": description_schema,
583 "additionalParams": {
584 "type": "object",
585 "properties": {
586 "run-day1": bool_schema,
587 "vdu": {
588 "type": "array",
589 "items": {
590 "type": "object",
591 "properties": {
592 "run-day1": bool_schema,
593 "vdu-id": name_schema,
594 "count-index": integer0_schema,
595 },
596 "required": ["vdu-id"],
597 "additionalProperties": False,
598 },
599 },
600 },
601 "additionalProperties": False,
602 },
603 },
604 "required": ["vnfInstanceId"],
605 "additionalProperties": False,
606 },
607 },
608 },
609 "required": ["healVnfData"],
610 "additionalProperties": False,
611}
612
govindarajul519da482022-04-29 19:05:22 +0530613ns_verticalscale = {
614 "title": "vertial scale input schema",
615 "$schema": "http://json-schema.org/draft-04/schema#",
616 "type": "object",
617 "properties": {
618 "lcmOperationType": string_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000619 "verticalScale": string_schema,
govindarajul519da482022-04-29 19:05:22 +0530620 "nsInstanceId": id_schema,
govindarajul69964ec2022-07-06 10:24:38 +0000621 "changeVnfFlavorData": {
govindarajul519da482022-04-29 19:05:22 +0530622 "type": "object",
govindarajul69964ec2022-07-06 10:24:38 +0000623 "properties": {
624 "vnfInstanceId": id_schema,
625 "additionalParams": {
626 "type": "object",
627 "properties": {
628 "vduid": string_schema,
629 "vduCountIndex": integer0_schema,
630 "virtualMemory": integer1_schema,
631 "sizeOfStorage": integer0_schema,
632 "numVirtualCpu": integer1_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +0100633 },
govindarajul519da482022-04-29 19:05:22 +0530634 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100635 },
govindarajul69964ec2022-07-06 10:24:38 +0000636 "required": ["vnfInstanceId", "additionalParams"],
637 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530638 },
garciadeblasf2af4a12023-01-24 16:56:54 +0100639 },
govindarajul69964ec2022-07-06 10:24:38 +0000640 "required": ["lcmOperationType", "verticalScale", "nsInstanceId"],
641 "additionalProperties": False,
govindarajul519da482022-04-29 19:05:22 +0530642}
643
Gabriel Cuba84a60df2023-10-30 14:01:54 -0500644nslcmop_cancel = {
645 "title": "Cancel nslcmop input schema",
646 "$schema": "http://json-schema.org/draft-04/schema#",
647 "type": "object",
648 "properties": {
649 "nsLcmOpOccId": id_schema,
650 "cancelMode": {
651 "enum": [
652 "GRACEFUL",
653 "FORCEFUL",
654 ]
655 },
656 },
657 "required": ["cancelMode"],
658 "additionalProperties": False,
659}
660
tierno0f98af52018-03-19 10:28:22 +0100661schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000662schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000663vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200664
tierno09c073e2018-04-26 13:36:48 +0200665vim_account_edit_schema = {
666 "title": "vim_account edit input schema",
667 "$schema": "http://json-schema.org/draft-04/schema#",
668 "type": "object",
669 "properties": {
670 "name": name_schema,
671 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200672 "vim": name_schema,
673 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200674 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200675 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200676 # "vim_url_admin": description_schema,
677 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200678 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200679 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200680 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200681 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100682 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000683 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200684 },
garciadeblas4568a372021-03-24 09:19:48 +0100685 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200686}
tierno0f98af52018-03-19 10:28:22 +0100687
tierno09c073e2018-04-26 13:36:48 +0200688vim_account_new_schema = {
689 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100690 "$schema": "http://json-schema.org/draft-04/schema#",
691 "type": "object",
692 "properties": {
693 "schema_version": schema_version,
694 "schema_type": schema_type,
695 "name": name_schema,
696 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200697 "vim": name_schema,
698 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200699 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100700 "vim_url": description_schema,
701 # "vim_url_admin": description_schema,
702 # "vim_tenant": name_schema,
703 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200704 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200705 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200706 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100707 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000708 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100709 },
garciadeblas4568a372021-03-24 09:19:48 +0100710 "required": [
711 "name",
712 "vim_url",
713 "vim_type",
714 "vim_user",
715 "vim_password",
716 "vim_tenant_name",
717 ],
718 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100719}
tierno0f98af52018-03-19 10:28:22 +0100720
tierno85807722019-12-20 14:11:35 +0000721wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200722
tierno55ba2e62018-12-11 17:22:22 +0000723wim_account_edit_schema = {
724 "title": "wim_account edit input schema",
725 "$schema": "http://json-schema.org/draft-04/schema#",
726 "type": "object",
727 "properties": {
728 "name": name_schema,
729 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000730 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200731 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000732 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100733 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000734 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100735 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000736 },
garciadeblas4568a372021-03-24 09:19:48 +0100737 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000738}
739
740wim_account_new_schema = {
741 "title": "wim_account creation input schema",
742 "$schema": "http://json-schema.org/draft-04/schema#",
743 "type": "object",
744 "properties": {
745 "schema_version": schema_version,
746 "schema_type": schema_type,
747 "name": name_schema,
748 "description": description_schema,
749 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200750 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000751 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100752 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000753 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000754 "config": {
755 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100756 "patternProperties": {".": {"not": {"type": "null"}}},
757 },
tierno55ba2e62018-12-11 17:22:22 +0000758 },
759 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100760 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000761}
tierno0f98af52018-03-19 10:28:22 +0100762
763sdn_properties = {
764 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000765 "type": {"type": "string"},
766 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100767 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000768 "password": passwd_schema,
769 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200770 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000771 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200772 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100773 "ip": ip_schema,
774 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100775 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100776}
777sdn_new_schema = {
778 "title": "sdn controller information schema",
779 "$schema": "http://json-schema.org/draft-04/schema#",
780 "type": "object",
781 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100782 "required": ["name", "type"],
783 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100784}
785sdn_edit_schema = {
786 "title": "sdn controller update information schema",
787 "$schema": "http://json-schema.org/draft-04/schema#",
788 "type": "object",
789 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200790 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100791 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100792}
793sdn_port_mapping_schema = {
794 "$schema": "http://json-schema.org/draft-04/schema#",
795 "title": "sdn port mapping information schema",
796 "type": "array",
797 "items": {
798 "type": "object",
799 "properties": {
tiernofd160572019-01-21 10:41:37 +0000800 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100801 "ports": {
802 "type": "array",
803 "items": {
804 "type": "object",
805 "properties": {
tierno42fce592018-11-02 09:23:43 +0100806 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000807 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100808 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100809 },
garciadeblas4568a372021-03-24 09:19:48 +0100810 "required": ["pci"],
811 },
812 },
tierno0f98af52018-03-19 10:28:22 +0100813 },
garciadeblas4568a372021-03-24 09:19:48 +0100814 "required": ["compute_node", "ports"],
815 },
tierno0f98af52018-03-19 10:28:22 +0100816}
817sdn_external_port_schema = {
818 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200819 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100820 "type": "object",
821 "properties": {
822 "port": {"type": "string", "minLength": 1, "maxLength": 60},
823 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100824 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100825 },
garciadeblas4568a372021-03-24 09:19:48 +0100826 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100827}
828
delacruzramofe598fe2019-10-23 18:25:11 +0200829# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500830k8scluster_deploy_method_schema = {
831 "$schema": "http://json-schema.org/draft-04/schema#",
832 "title": "Deployment methods for K8s cluster",
833 "type": "object",
834 "properties": {
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500835 "juju-bundle": {"type": "boolean"},
836 "helm-chart-v3": {"type": "boolean"},
837 },
838 "additionalProperties": False,
Luis Vega0a1efed2023-11-28 16:44:30 +0000839 "minProperties": 2,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500840}
delacruzramofe598fe2019-10-23 18:25:11 +0200841k8scluster_nets_schema = {
842 "title": "k8scluster nets input schema",
843 "$schema": "http://json-schema.org/draft-04/schema#",
844 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000845 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200846 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100847 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200848}
849k8scluster_new_schema = {
850 "title": "k8scluster creation input schema",
851 "$schema": "http://json-schema.org/draft-04/schema#",
852 "type": "object",
853 "properties": {
854 "schema_version": schema_version,
855 "schema_type": schema_type,
856 "name": name_schema,
857 "description": description_schema,
858 "credentials": object_schema,
859 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200860 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200861 "k8s_version": string_schema,
862 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500863 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200864 "namespace": name_schema,
865 "cni": nameshort_list_schema,
866 },
867 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100868 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200869}
870k8scluster_edit_schema = {
871 "title": "vim_account edit input schema",
872 "$schema": "http://json-schema.org/draft-04/schema#",
873 "type": "object",
874 "properties": {
875 "name": name_schema,
876 "description": description_schema,
877 "credentials": object_schema,
878 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200879 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200880 "k8s_version": string_schema,
881 "nets": k8scluster_nets_schema,
882 "namespace": name_schema,
883 "cni": nameshort_list_schema,
884 },
garciadeblas4568a372021-03-24 09:19:48 +0100885 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200886}
887
David Garciaecb41322021-03-31 19:10:46 +0200888# VCA
889vca_new_schema = {
890 "title": "vca creation input schema",
891 "$schema": "http://json-schema.org/draft-04/schema#",
892 "type": "object",
893 "properties": {
894 "schema_version": schema_version,
895 "schema_type": schema_type,
896 "name": name_schema,
897 "description": description_schema,
898 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100899 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200900 "secret": passwd_schema,
901 "cacert": long_description_schema,
902 "lxd-cloud": shortname_schema,
903 "lxd-credentials": shortname_schema,
904 "k8s-cloud": shortname_schema,
905 "k8s-credentials": shortname_schema,
906 "model-config": object_schema,
907 },
908 "required": [
909 "name",
910 "endpoints",
911 "user",
912 "secret",
913 "cacert",
914 "lxd-cloud",
915 "lxd-credentials",
916 "k8s-cloud",
917 "k8s-credentials",
918 ],
919 "additionalProperties": False,
920}
921vca_edit_schema = {
922 "title": "vca creation input schema",
923 "$schema": "http://json-schema.org/draft-04/schema#",
924 "type": "object",
925 "properties": {
926 "name": name_schema,
927 "description": description_schema,
928 "endpoints": description_list_schema,
929 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100930 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200931 "secret": passwd_schema,
932 "cacert": long_description_schema,
933 "lxd-cloud": shortname_schema,
934 "lxd-credentials": shortname_schema,
935 "k8s-cloud": shortname_schema,
936 "k8s-credentials": shortname_schema,
937 "model-config": object_schema,
938 },
939 "additionalProperties": False,
940}
941
delacruzramofe598fe2019-10-23 18:25:11 +0200942# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000943k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200944k8srepo_properties = {
945 "name": name_schema,
946 "description": description_schema,
947 "type": k8srepo_types,
948 "url": description_schema,
Luis Vegaf6574e32023-07-11 18:47:22 +0000949 "cacert": long_description_schema,
950 "user": string_schema,
951 "password": passwd_schema,
garciadeblasf3543892023-10-20 11:53:51 +0200952 "oci": bool_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200953}
954k8srepo_new_schema = {
955 "title": "k8scluster creation input schema",
956 "$schema": "http://json-schema.org/draft-04/schema#",
957 "type": "object",
958 "properties": k8srepo_properties,
959 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100960 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200961}
962k8srepo_edit_schema = {
963 "title": "vim_account edit input schema",
964 "$schema": "http://json-schema.org/draft-04/schema#",
965 "type": "object",
966 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100967 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200968}
969
Felipe Vicensb66b0412020-05-06 10:11:00 +0200970# OSM Repos
971osmrepo_types = {"enum": ["osm"]}
972osmrepo_properties = {
973 "name": name_schema,
974 "description": description_schema,
975 "type": osmrepo_types,
976 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100977 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200978 # "password": passwd_schema
979}
980osmrepo_new_schema = {
981 "title": "osm repo creation input schema",
982 "$schema": "http://json-schema.org/draft-04/schema#",
983 "type": "object",
984 "properties": osmrepo_properties,
985 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100986 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200987}
988osmrepo_edit_schema = {
989 "title": "osm repo edit input schema",
990 "$schema": "http://json-schema.org/draft-04/schema#",
991 "type": "object",
992 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100993 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200994}
995
tiernocb83c942018-09-24 17:28:13 +0200996# PDUs
997pdu_interface = {
998 "type": "object",
999 "properties": {
tiernofd160572019-01-21 10:41:37 +00001000 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001001 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001002 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +02001003 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +02001004 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +01001005 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +00001006 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
1007 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +01001008 # # provide this in case SDN assist must deal with this interface
1009 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +00001010 # "switch-port": shortname_schema,
1011 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +01001012 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +02001013 },
tierno36ec8602018-11-02 17:27:11 +01001014 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +01001015 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001016}
tiernocb83c942018-09-24 17:28:13 +02001017pdu_new_schema = {
1018 "title": "pdu creation input schema",
1019 "$schema": "http://json-schema.org/draft-04/schema#",
1020 "type": "object",
1021 "properties": {
tiernofd160572019-01-21 10:41:37 +00001022 "name": shortname_schema,
1023 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001024 "description": description_schema,
1025 "shared": bool_schema,
1026 "vims": nameshort_list_schema,
1027 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001028 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +02001029 },
1030 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +01001031 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +02001032}
tiernocb83c942018-09-24 17:28:13 +02001033pdu_edit_schema = {
1034 "title": "pdu edit input schema",
1035 "$schema": "http://json-schema.org/draft-04/schema#",
1036 "type": "object",
1037 "properties": {
tiernofd160572019-01-21 10:41:37 +00001038 "name": shortname_schema,
1039 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001040 "description": description_schema,
1041 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +01001042 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1043 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +01001044 "interfaces": {
1045 "oneOf": [
1046 array_edition_schema,
1047 {"type": "array", "items": pdu_interface, "minItems": 1},
1048 ]
1049 },
tiernocb83c942018-09-24 17:28:13 +02001050 },
1051 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001052 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001053}
1054
delacruzramo271d2002019-12-02 21:00:37 +01001055# VNF PKG OPERATIONS
1056vnfpkgop_new_schema = {
1057 "title": "VNF PKG operation creation input schema",
1058 "$schema": "http://json-schema.org/draft-04/schema#",
1059 "type": "object",
1060 "properties": {
1061 "lcmOperationType": string_schema,
1062 "vnfPkgId": id_schema,
1063 "kdu_name": name_schema,
1064 "primitive": name_schema,
1065 "primitive_params": {"type": "object"},
1066 },
garciadeblas4568a372021-03-24 09:19:48 +01001067 "required": [
1068 "lcmOperationType",
1069 "vnfPkgId",
1070 "kdu_name",
1071 "primitive",
1072 "primitive_params",
1073 ],
1074 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001075}
1076
tiernocb83c942018-09-24 17:28:13 +02001077# USERS
tiernocf042d32019-06-13 09:06:40 +00001078project_role_mappings = {
1079 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001080 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001081 "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", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001086 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001087 },
garciadeblas4568a372021-03-24 09:19:48 +01001088 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001089}
1090project_role_mappings_optional = {
1091 "title": "list of projects/roles or projects only",
1092 "$schema": "http://json-schema.org/draft-04/schema#",
1093 "type": "array",
1094 "items": {
1095 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001096 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001097 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001098 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001099 },
garciadeblas4568a372021-03-24 09:19:48 +01001100 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001101}
tiernocd54a4a2018-09-12 16:40:35 +02001102user_new_schema = {
1103 "$schema": "http://json-schema.org/draft-04/schema#",
1104 "title": "New user schema",
1105 "type": "object",
1106 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001107 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001108 "domain_name": shortname_schema,
garciadeblas6d83f8f2023-06-19 22:34:49 +02001109 "password": user_passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001110 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001111 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001112 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001113 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001114 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001115}
1116user_edit_schema = {
1117 "$schema": "http://json-schema.org/draft-04/schema#",
1118 "title": "User edit schema for administrators",
1119 "type": "object",
1120 "properties": {
garciadeblas6d83f8f2023-06-19 22:34:49 +02001121 "password": user_passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001122 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001123 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001124 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001125 "project_role_mappings": project_role_mappings,
1126 "add_project_role_mappings": project_role_mappings,
1127 "remove_project_role_mappings": project_role_mappings_optional,
garciadeblas6d83f8f2023-06-19 22:34:49 +02001128 "system_admin_id": id_schema,
1129 "unlock": bool_schema,
1130 "renew": bool_schema,
tiernocb83c942018-09-24 17:28:13 +02001131 },
1132 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001133 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001134}
1135
1136# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001137topics_with_quota = [
1138 "vnfds",
1139 "nsds",
1140 "slice_templates",
1141 "pduds",
1142 "ns_instances",
1143 "slice_instances",
1144 "vim_accounts",
1145 "wim_accounts",
1146 "sdn_controllers",
1147 "k8sclusters",
1148 "vca",
1149 "k8srepos",
1150 "osmrepos",
1151 "ns_subscriptions",
1152]
tiernocd54a4a2018-09-12 16:40:35 +02001153project_new_schema = {
1154 "$schema": "http://json-schema.org/draft-04/schema#",
1155 "title": "New project schema for administrators",
1156 "type": "object",
1157 "properties": {
tiernofd160572019-01-21 10:41:37 +00001158 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001159 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001160 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001161 "quotas": {
1162 "type": "object",
1163 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001164 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001165 },
tiernocd54a4a2018-09-12 16:40:35 +02001166 },
1167 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001168 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001169}
1170project_edit_schema = {
1171 "$schema": "http://json-schema.org/draft-04/schema#",
1172 "title": "Project edit schema for administrators",
1173 "type": "object",
1174 "properties": {
1175 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001176 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001177 "quotas": {
1178 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001179 "properties": {
1180 topic: {"oneOf": [integer0_schema, null_schema]}
1181 for topic in topics_with_quota
1182 },
1183 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001184 },
tiernocd54a4a2018-09-12 16:40:35 +02001185 },
1186 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001187 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001188}
1189
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001190# ROLES
1191roles_new_schema = {
1192 "$schema": "http://json-schema.org/draft-04/schema#",
1193 "title": "New role schema for administrators",
1194 "type": "object",
1195 "properties": {
1196 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001197 "permissions": {
1198 "type": "object",
1199 "patternProperties": {
1200 ".": bool_schema,
1201 },
1202 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001203 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001204 },
tierno1f029d82019-06-13 22:37:04 +00001205 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001206 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001207}
1208roles_edit_schema = {
1209 "$schema": "http://json-schema.org/draft-04/schema#",
1210 "title": "Roles edit schema for administrators",
1211 "type": "object",
1212 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001213 "name": shortname_schema,
1214 "permissions": {
1215 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001216 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001217 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001218 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001219 },
tierno1f029d82019-06-13 22:37:04 +00001220 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001221 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001222}
1223
tiernocd54a4a2018-09-12 16:40:35 +02001224# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001225
1226nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001227 "users": user_new_schema,
1228 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001229 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001230 "sdns": sdn_new_schema,
1231 "ns_instantiate": ns_instantiate,
1232 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001233 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001234 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001235 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001236 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001237}
1238
1239nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001240 "users": user_edit_schema,
1241 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001242 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001243 "sdns": sdn_edit_schema,
1244 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001245}
1246
Felipe Vicens07f31722018-10-29 15:16:44 +01001247# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001248nsi_subnet_instantiate = deepcopy(ns_instantiate)
1249nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1250nsi_subnet_instantiate["properties"]["id"] = name_schema
1251del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001252
1253nsi_vld_instantiate = {
1254 "title": "netslice vld instantiation params input schema",
1255 "$schema": "http://json-schema.org/draft-04/schema#",
1256 "type": "object",
1257 "properties": {
1258 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001259 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1260 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001261 "ip-profile": object_schema,
1262 },
delacruzramoc061f562019-04-05 11:00:02 +02001263 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001264 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001265}
1266
Felipe Vicens07f31722018-10-29 15:16:44 +01001267nsi_instantiate = {
1268 "title": "netslice action instantiate input schema",
1269 "$schema": "http://json-schema.org/draft-04/schema#",
1270 "type": "object",
1271 "properties": {
1272 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001273 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001274 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001275 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001276 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001277 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001278 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001279 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001280 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001281 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001282 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001283 "type": "array",
1284 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001285 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001286 },
garciadeblas4568a372021-03-24 09:19:48 +01001287 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001288 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001289 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001290 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001291}
1292
garciadeblas4568a372021-03-24 09:19:48 +01001293nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001294
garciadeblas4568a372021-03-24 09:19:48 +01001295nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001296
preethika.p329b8182020-04-22 12:25:39 +05301297nsinstancesubscriptionfilter_schema = {
1298 "title": "instance identifier schema",
1299 "$schema": "http://json-schema.org/draft-07/schema#",
1300 "type": "object",
1301 "properties": {
1302 "nsdIds": {"type": "array"},
1303 "vnfdIds": {"type": "array"},
1304 "pnfdIds": {"type": "array"},
1305 "nsInstanceIds": {"type": "array"},
1306 "nsInstanceNames": {"type": "array"},
1307 },
1308}
1309
1310nslcmsub_schema = {
1311 "title": "nslcmsubscription input schema",
1312 "$schema": "http://json-schema.org/draft-07/schema#",
1313 "type": "object",
1314 "properties": {
1315 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1316 "notificationTypes": {
1317 "type": "array",
1318 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001319 "enum": [
1320 "NsLcmOperationOccurrenceNotification",
1321 "NsChangeNotification",
1322 "NsIdentifierCreationNotification",
1323 "NsIdentifierDeletionNotification",
1324 ]
1325 },
preethika.p329b8182020-04-22 12:25:39 +05301326 },
1327 "operationTypes": {
1328 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001329 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301330 },
1331 "operationStates": {
1332 "type": "array",
1333 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001334 "enum": [
1335 "PROCESSING",
1336 "COMPLETED",
1337 "PARTIALLY_COMPLETED",
1338 "FAILED",
1339 "FAILED_TEMP",
1340 "ROLLING_BACK",
1341 "ROLLED_BACK",
1342 ]
1343 },
preethika.p329b8182020-04-22 12:25:39 +05301344 },
garciadeblas4568a372021-03-24 09:19:48 +01001345 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301346 "lcmOpNameImpactingNsComponent": {
1347 "type": "array",
1348 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001349 "enum": [
1350 "VNF_INSTANTIATE",
1351 "VNF_SCALE",
1352 "VNF_SCALE_TO_LEVEL",
1353 "VNF_CHANGE_FLAVOUR",
1354 "VNF_TERMINATE",
1355 "VNF_HEAL",
1356 "VNF_OPERATE",
1357 "VNF_CHANGE_EXT_CONN",
1358 "VNF_MODIFY_INFO",
1359 "NS_INSTANTIATE",
1360 "NS_SCALE",
1361 "NS_UPDATE",
1362 "NS_TERMINATE",
1363 "NS_HEAL",
1364 ]
1365 },
preethika.p329b8182020-04-22 12:25:39 +05301366 },
1367 "lcmOpOccStatusImpactingNsComponent": {
1368 "type": "array",
1369 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001370 "enum": [
1371 "START",
1372 "COMPLETED",
1373 "PARTIALLY_COMPLETED",
1374 "FAILED",
1375 "ROLLED_BACK",
1376 ]
1377 },
preethika.p329b8182020-04-22 12:25:39 +05301378 },
1379 },
1380 "allOf": [
1381 {
1382 "if": {
1383 "properties": {
1384 "notificationTypes": {
1385 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1386 }
1387 },
1388 },
1389 "then": {
1390 "anyOf": [
1391 {"required": ["operationTypes"]},
1392 {"required": ["operationStates"]},
1393 ]
garciadeblas4568a372021-03-24 09:19:48 +01001394 },
preethika.p329b8182020-04-22 12:25:39 +05301395 },
1396 {
1397 "if": {
1398 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001399 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301400 },
1401 },
1402 "then": {
1403 "anyOf": [
1404 {"required": ["nsComponentTypes"]},
1405 {"required": ["lcmOpNameImpactingNsComponent"]},
1406 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1407 ]
garciadeblas4568a372021-03-24 09:19:48 +01001408 },
1409 },
1410 ],
preethika.p329b8182020-04-22 12:25:39 +05301411}
1412
1413authentication_schema = {
1414 "title": "authentication schema for subscription",
1415 "$schema": "http://json-schema.org/draft-07/schema#",
1416 "type": "object",
1417 "properties": {
1418 "authType": {"enum": ["basic"]},
1419 "paramsBasic": {
1420 "type": "object",
1421 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001422 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301423 "password": passwd_schema,
1424 },
1425 },
1426 },
1427}
1428
1429subscription = {
1430 "title": "subscription input schema",
1431 "$schema": "http://json-schema.org/draft-07/schema#",
1432 "type": "object",
1433 "properties": {
1434 "filter": nslcmsub_schema,
1435 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001436 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301437 },
1438 "required": ["CallbackUri"],
1439}
1440
selvi.jf1004592022-04-29 05:42:35 +00001441vnflcmsub_schema = {
1442 "title": "vnflcmsubscription input schema",
1443 "$schema": "http://json-schema.org/draft-07/schema#",
1444 "type": "object",
1445 "properties": {
1446 "VnfInstanceSubscriptionFilter": {
1447 "type": "object",
1448 "properties": {
1449 "vnfdIds": {"type": "array"},
1450 "vnfInstanceIds": {"type": "array"},
1451 },
1452 },
1453 "notificationTypes": {
1454 "type": "array",
1455 "items": {
1456 "enum": [
1457 "VnfIdentifierCreationNotification",
1458 "VnfLcmOperationOccurrenceNotification",
garciadeblasf2af4a12023-01-24 16:56:54 +01001459 "VnfIdentifierDeletionNotification",
1460 ]
1461 },
selvi.jf1004592022-04-29 05:42:35 +00001462 },
1463 "operationTypes": {
1464 "type": "array",
1465 "items": {
1466 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001467 "INSTANTIATE",
1468 "SCALE",
1469 "SCALE_TO_LEVEL",
1470 "CHANGE_FLAVOUR",
1471 "TERMINATE",
1472 "HEAL",
1473 "OPERATE",
1474 "CHANGE_EXT_CONN",
1475 "MODIFY_INFO",
1476 "CREATE_SNAPSHOT",
1477 "REVERT_TO_SNAPSHOT",
1478 "CHANGE_VNFPKG",
1479 ]
1480 },
selvi.jf1004592022-04-29 05:42:35 +00001481 },
1482 "operationStates": {
1483 "type": "array",
1484 "items": {
1485 "enum": [
garciadeblasf2af4a12023-01-24 16:56:54 +01001486 "STARTING",
1487 "PROCESSING",
1488 "COMPLETED",
1489 "FAILED_TEMP",
1490 "FAILED",
1491 "ROLLING_BACK",
1492 "ROLLED_BACK",
1493 ]
1494 },
1495 },
selvi.jf1004592022-04-29 05:42:35 +00001496 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001497 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"],
1498}
selvi.jf1004592022-04-29 05:42:35 +00001499
1500vnf_subscription = {
1501 "title": "vnf subscription input schema",
1502 "$schema": "http://json-schema.org/draft-07/schema#",
1503 "type": "object",
1504 "properties": {
1505 "filter": vnflcmsub_schema,
1506 "CallbackUri": description_schema,
garciadeblasf2af4a12023-01-24 16:56:54 +01001507 "authentication": authentication_schema,
selvi.jf1004592022-04-29 05:42:35 +00001508 },
garciadeblasf2af4a12023-01-24 16:56:54 +01001509 "required": ["filter", "CallbackUri"],
selvi.jf1004592022-04-29 05:42:35 +00001510}
1511
tierno0f98af52018-03-19 10:28:22 +01001512
1513class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001514 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1515 self.http_code = http_code
1516 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001517
1518
tiernob24258a2018-10-04 18:39:49 +02001519def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001520 """
tiernocd54a4a2018-09-12 16:40:35 +02001521 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001522 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001523 :param schema_to_use: jsonschema to test
1524 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001525 """
1526 try:
tierno0f98af52018-03-19 10:28:22 +01001527 if schema_to_use:
1528 js_v(indata, schema_to_use)
1529 return None
1530 except js_e.ValidationError as e:
1531 if e.path:
tierno0da52252018-06-27 15:47:22 +02001532 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001533 else:
1534 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001535 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001536 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001537 raise ValidationError(
1538 "Bad json schema {}".format(schema_to_use),
1539 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1540 )
delacruzramoc061f562019-04-05 11:00:02 +02001541
1542
1543def is_valid_uuid(x):
1544 """
1545 Test for a valid UUID
1546 :param x: string to test
1547 :return: True if x is a valid uuid, False otherwise
1548 """
1549 try:
1550 if UUID(x):
1551 return True
tiernobdebce92019-07-01 15:36:49 +00001552 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001553 return False