blob: ae9644c44b458d0146b9ef0a43548511f6fcd7ce [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",
99 "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]))",
100}
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": {
452 "enum": ["CHANGE_VNFPKG", "REMOVE_VNF", "MODIFY_VNF_INFORMATION"]
453 },
454 "modifyVnfInfoData": {
455 "type": "object",
456 "properties": {
457 "vnfInstanceId": id_schema,
458 "vnfdId": id_schema,
459 },
460 "required": ["vnfInstanceId", "vnfdId"],
461 },
462 "removeVnfInstanceId": id_schema,
463 "changeVnfPackageData": {
464 "type": "object",
465 "properties": {
466 "vnfInstanceId": id_schema,
467 "vnfdId": id_schema,
468 },
469 "required": ["vnfInstanceId", "vnfdId"],
470 },
471 },
472 "required": ["updateType"],
473 "additionalProperties": False,
474}
475
garciadeblas4568a372021-03-24 09:19:48 +0100476ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200477 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200478 "$schema": "http://json-schema.org/draft-04/schema#",
479 "type": "object",
480 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200481 "lcmOperationType": string_schema,
482 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200483 "member_vnf_index": name_schema,
484 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200485 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000486 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000487 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200488 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000489 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200490 "primitive_params": {"type": "object"},
491 },
garciadeblas4568a372021-03-24 09:19:48 +0100492 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
493 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200494}
garciadeblas4568a372021-03-24 09:19:48 +0100495ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200496 "title": "ns scale input schema",
497 "$schema": "http://json-schema.org/draft-04/schema#",
498 "type": "object",
499 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200500 "lcmOperationType": string_schema,
501 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200502 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000503 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200504 "scaleVnfData": {
505 "type": "object",
506 "properties": {
507 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100508 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200509 "scaleByStepData": {
510 "type": "object",
511 "properties": {
512 "scaling-group-descriptor": name_schema,
513 "member-vnf-index": name_schema,
514 "scaling-policy": name_schema,
515 },
516 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100517 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200518 },
519 },
520 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100521 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200522 },
523 "scaleTime": time_schema,
524 },
525 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100526 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200527}
tierno65acb4d2018-04-06 16:42:40 +0200528
elumalai8e3806c2022-04-28 17:26:24 +0530529ns_migrate = {
530 "title": "ns migrate input schema",
531 "$schema": "http://json-schema.org/draft-04/schema#",
532 "type": "object",
533 "properties": {
534 "lcmOperationType": string_schema,
535 "nsInstanceId": id_schema,
536 "vnfInstanceId": id_schema,
537 "migrateToHost": string_schema,
538 "vdu": {
539 "type": "object",
540 "properties": {
541 "vduId": name_schema,
542 "vduCountIndex": integer0_schema,
543 },
544 "required": ["vduId"],
545 "additionalProperties": False,
546 },
547 },
548 "required": ["vnfInstanceId"],
549 "additionalProperties": False
550}
tierno65acb4d2018-04-06 16:42:40 +0200551
tierno0f98af52018-03-19 10:28:22 +0100552schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000553schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000554vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200555
tierno09c073e2018-04-26 13:36:48 +0200556vim_account_edit_schema = {
557 "title": "vim_account edit input schema",
558 "$schema": "http://json-schema.org/draft-04/schema#",
559 "type": "object",
560 "properties": {
561 "name": name_schema,
562 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200563 "vim": name_schema,
564 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200565 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200566 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200567 # "vim_url_admin": description_schema,
568 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200569 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200570 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200571 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200572 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100573 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000574 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200575 },
garciadeblas4568a372021-03-24 09:19:48 +0100576 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200577}
tierno0f98af52018-03-19 10:28:22 +0100578
tierno09c073e2018-04-26 13:36:48 +0200579vim_account_new_schema = {
580 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100581 "$schema": "http://json-schema.org/draft-04/schema#",
582 "type": "object",
583 "properties": {
584 "schema_version": schema_version,
585 "schema_type": schema_type,
586 "name": name_schema,
587 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200588 "vim": name_schema,
589 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200590 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100591 "vim_url": description_schema,
592 # "vim_url_admin": description_schema,
593 # "vim_tenant": name_schema,
594 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200595 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200596 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200597 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100598 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000599 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100600 },
garciadeblas4568a372021-03-24 09:19:48 +0100601 "required": [
602 "name",
603 "vim_url",
604 "vim_type",
605 "vim_user",
606 "vim_password",
607 "vim_tenant_name",
608 ],
609 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100610}
tierno0f98af52018-03-19 10:28:22 +0100611
tierno85807722019-12-20 14:11:35 +0000612wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200613
tierno55ba2e62018-12-11 17:22:22 +0000614wim_account_edit_schema = {
615 "title": "wim_account edit input schema",
616 "$schema": "http://json-schema.org/draft-04/schema#",
617 "type": "object",
618 "properties": {
619 "name": name_schema,
620 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000621 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200622 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000623 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100624 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000625 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100626 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000627 },
garciadeblas4568a372021-03-24 09:19:48 +0100628 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000629}
630
631wim_account_new_schema = {
632 "title": "wim_account creation input schema",
633 "$schema": "http://json-schema.org/draft-04/schema#",
634 "type": "object",
635 "properties": {
636 "schema_version": schema_version,
637 "schema_type": schema_type,
638 "name": name_schema,
639 "description": description_schema,
640 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200641 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000642 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100643 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000644 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000645 "config": {
646 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100647 "patternProperties": {".": {"not": {"type": "null"}}},
648 },
tierno55ba2e62018-12-11 17:22:22 +0000649 },
650 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100651 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000652}
tierno0f98af52018-03-19 10:28:22 +0100653
654sdn_properties = {
655 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000656 "type": {"type": "string"},
657 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100658 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000659 "password": passwd_schema,
660 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200661 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000662 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200663 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100664 "ip": ip_schema,
665 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100666 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100667}
668sdn_new_schema = {
669 "title": "sdn controller information schema",
670 "$schema": "http://json-schema.org/draft-04/schema#",
671 "type": "object",
672 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100673 "required": ["name", "type"],
674 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100675}
676sdn_edit_schema = {
677 "title": "sdn controller update information schema",
678 "$schema": "http://json-schema.org/draft-04/schema#",
679 "type": "object",
680 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200681 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100682 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100683}
684sdn_port_mapping_schema = {
685 "$schema": "http://json-schema.org/draft-04/schema#",
686 "title": "sdn port mapping information schema",
687 "type": "array",
688 "items": {
689 "type": "object",
690 "properties": {
tiernofd160572019-01-21 10:41:37 +0000691 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100692 "ports": {
693 "type": "array",
694 "items": {
695 "type": "object",
696 "properties": {
tierno42fce592018-11-02 09:23:43 +0100697 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000698 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100699 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100700 },
garciadeblas4568a372021-03-24 09:19:48 +0100701 "required": ["pci"],
702 },
703 },
tierno0f98af52018-03-19 10:28:22 +0100704 },
garciadeblas4568a372021-03-24 09:19:48 +0100705 "required": ["compute_node", "ports"],
706 },
tierno0f98af52018-03-19 10:28:22 +0100707}
708sdn_external_port_schema = {
709 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200710 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100711 "type": "object",
712 "properties": {
713 "port": {"type": "string", "minLength": 1, "maxLength": 60},
714 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100715 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100716 },
garciadeblas4568a372021-03-24 09:19:48 +0100717 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100718}
719
delacruzramofe598fe2019-10-23 18:25:11 +0200720# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500721k8scluster_deploy_method_schema = {
722 "$schema": "http://json-schema.org/draft-04/schema#",
723 "title": "Deployment methods for K8s cluster",
724 "type": "object",
725 "properties": {
726 "helm-chart": {"type": "boolean"},
727 "juju-bundle": {"type": "boolean"},
728 "helm-chart-v3": {"type": "boolean"},
729 },
730 "additionalProperties": False,
731 "minProperties": 3,
732}
delacruzramofe598fe2019-10-23 18:25:11 +0200733k8scluster_nets_schema = {
734 "title": "k8scluster nets input schema",
735 "$schema": "http://json-schema.org/draft-04/schema#",
736 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000737 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200738 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100739 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200740}
741k8scluster_new_schema = {
742 "title": "k8scluster creation input schema",
743 "$schema": "http://json-schema.org/draft-04/schema#",
744 "type": "object",
745 "properties": {
746 "schema_version": schema_version,
747 "schema_type": schema_type,
748 "name": name_schema,
749 "description": description_schema,
750 "credentials": object_schema,
751 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200752 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200753 "k8s_version": string_schema,
754 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500755 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200756 "namespace": name_schema,
757 "cni": nameshort_list_schema,
758 },
759 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100760 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200761}
762k8scluster_edit_schema = {
763 "title": "vim_account edit input schema",
764 "$schema": "http://json-schema.org/draft-04/schema#",
765 "type": "object",
766 "properties": {
767 "name": name_schema,
768 "description": description_schema,
769 "credentials": object_schema,
770 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200771 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200772 "k8s_version": string_schema,
773 "nets": k8scluster_nets_schema,
774 "namespace": name_schema,
775 "cni": nameshort_list_schema,
776 },
garciadeblas4568a372021-03-24 09:19:48 +0100777 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200778}
779
David Garciaecb41322021-03-31 19:10:46 +0200780# VCA
781vca_new_schema = {
782 "title": "vca creation input schema",
783 "$schema": "http://json-schema.org/draft-04/schema#",
784 "type": "object",
785 "properties": {
786 "schema_version": schema_version,
787 "schema_type": schema_type,
788 "name": name_schema,
789 "description": description_schema,
790 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100791 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200792 "secret": passwd_schema,
793 "cacert": long_description_schema,
794 "lxd-cloud": shortname_schema,
795 "lxd-credentials": shortname_schema,
796 "k8s-cloud": shortname_schema,
797 "k8s-credentials": shortname_schema,
798 "model-config": object_schema,
799 },
800 "required": [
801 "name",
802 "endpoints",
803 "user",
804 "secret",
805 "cacert",
806 "lxd-cloud",
807 "lxd-credentials",
808 "k8s-cloud",
809 "k8s-credentials",
810 ],
811 "additionalProperties": False,
812}
813vca_edit_schema = {
814 "title": "vca creation input schema",
815 "$schema": "http://json-schema.org/draft-04/schema#",
816 "type": "object",
817 "properties": {
818 "name": name_schema,
819 "description": description_schema,
820 "endpoints": description_list_schema,
821 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100822 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200823 "secret": passwd_schema,
824 "cacert": long_description_schema,
825 "lxd-cloud": shortname_schema,
826 "lxd-credentials": shortname_schema,
827 "k8s-cloud": shortname_schema,
828 "k8s-credentials": shortname_schema,
829 "model-config": object_schema,
830 },
831 "additionalProperties": False,
832}
833
delacruzramofe598fe2019-10-23 18:25:11 +0200834# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000835k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200836k8srepo_properties = {
837 "name": name_schema,
838 "description": description_schema,
839 "type": k8srepo_types,
840 "url": description_schema,
841}
842k8srepo_new_schema = {
843 "title": "k8scluster creation input schema",
844 "$schema": "http://json-schema.org/draft-04/schema#",
845 "type": "object",
846 "properties": k8srepo_properties,
847 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100848 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200849}
850k8srepo_edit_schema = {
851 "title": "vim_account edit input schema",
852 "$schema": "http://json-schema.org/draft-04/schema#",
853 "type": "object",
854 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100855 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200856}
857
Felipe Vicensb66b0412020-05-06 10:11:00 +0200858# OSM Repos
859osmrepo_types = {"enum": ["osm"]}
860osmrepo_properties = {
861 "name": name_schema,
862 "description": description_schema,
863 "type": osmrepo_types,
864 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100865 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200866 # "password": passwd_schema
867}
868osmrepo_new_schema = {
869 "title": "osm repo creation input schema",
870 "$schema": "http://json-schema.org/draft-04/schema#",
871 "type": "object",
872 "properties": osmrepo_properties,
873 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100874 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200875}
876osmrepo_edit_schema = {
877 "title": "osm repo edit input schema",
878 "$schema": "http://json-schema.org/draft-04/schema#",
879 "type": "object",
880 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100881 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200882}
883
tiernocb83c942018-09-24 17:28:13 +0200884# PDUs
885pdu_interface = {
886 "type": "object",
887 "properties": {
tiernofd160572019-01-21 10:41:37 +0000888 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200889 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100890 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200891 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200892 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100893 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000894 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
895 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100896 # # provide this in case SDN assist must deal with this interface
897 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000898 # "switch-port": shortname_schema,
899 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100900 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200901 },
tierno36ec8602018-11-02 17:27:11 +0100902 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100903 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200904}
tiernocb83c942018-09-24 17:28:13 +0200905pdu_new_schema = {
906 "title": "pdu creation input schema",
907 "$schema": "http://json-schema.org/draft-04/schema#",
908 "type": "object",
909 "properties": {
tiernofd160572019-01-21 10:41:37 +0000910 "name": shortname_schema,
911 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200912 "description": description_schema,
913 "shared": bool_schema,
914 "vims": nameshort_list_schema,
915 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100916 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +0200917 },
918 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +0100919 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +0200920}
tiernocb83c942018-09-24 17:28:13 +0200921pdu_edit_schema = {
922 "title": "pdu edit input schema",
923 "$schema": "http://json-schema.org/draft-04/schema#",
924 "type": "object",
925 "properties": {
tiernofd160572019-01-21 10:41:37 +0000926 "name": shortname_schema,
927 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200928 "description": description_schema,
929 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +0100930 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
931 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +0100932 "interfaces": {
933 "oneOf": [
934 array_edition_schema,
935 {"type": "array", "items": pdu_interface, "minItems": 1},
936 ]
937 },
tiernocb83c942018-09-24 17:28:13 +0200938 },
939 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +0100940 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +0200941}
942
delacruzramo271d2002019-12-02 21:00:37 +0100943# VNF PKG OPERATIONS
944vnfpkgop_new_schema = {
945 "title": "VNF PKG operation creation input schema",
946 "$schema": "http://json-schema.org/draft-04/schema#",
947 "type": "object",
948 "properties": {
949 "lcmOperationType": string_schema,
950 "vnfPkgId": id_schema,
951 "kdu_name": name_schema,
952 "primitive": name_schema,
953 "primitive_params": {"type": "object"},
954 },
garciadeblas4568a372021-03-24 09:19:48 +0100955 "required": [
956 "lcmOperationType",
957 "vnfPkgId",
958 "kdu_name",
959 "primitive",
960 "primitive_params",
961 ],
962 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +0100963}
964
tiernocb83c942018-09-24 17:28:13 +0200965# USERS
tiernocf042d32019-06-13 09:06:40 +0000966project_role_mappings = {
967 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100968 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +0000969 "type": "array",
970 "items": {
971 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100972 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000973 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +0100974 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100975 },
garciadeblas4568a372021-03-24 09:19:48 +0100976 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +0000977}
978project_role_mappings_optional = {
979 "title": "list of projects/roles or projects only",
980 "$schema": "http://json-schema.org/draft-04/schema#",
981 "type": "array",
982 "items": {
983 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100984 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000985 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +0100986 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +0000987 },
garciadeblas4568a372021-03-24 09:19:48 +0100988 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100989}
tiernocd54a4a2018-09-12 16:40:35 +0200990user_new_schema = {
991 "$schema": "http://json-schema.org/draft-04/schema#",
992 "title": "New user schema",
993 "type": "object",
994 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +0100995 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +0000996 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200997 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200998 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +0000999 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001000 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001001 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001002 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001003}
1004user_edit_schema = {
1005 "$schema": "http://json-schema.org/draft-04/schema#",
1006 "title": "User edit schema for administrators",
1007 "type": "object",
1008 "properties": {
1009 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001010 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001011 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001012 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001013 "project_role_mappings": project_role_mappings,
1014 "add_project_role_mappings": project_role_mappings,
1015 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +02001016 },
1017 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001018 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001019}
1020
1021# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001022topics_with_quota = [
1023 "vnfds",
1024 "nsds",
1025 "slice_templates",
1026 "pduds",
1027 "ns_instances",
1028 "slice_instances",
1029 "vim_accounts",
1030 "wim_accounts",
1031 "sdn_controllers",
1032 "k8sclusters",
1033 "vca",
1034 "k8srepos",
1035 "osmrepos",
1036 "ns_subscriptions",
1037]
tiernocd54a4a2018-09-12 16:40:35 +02001038project_new_schema = {
1039 "$schema": "http://json-schema.org/draft-04/schema#",
1040 "title": "New project schema for administrators",
1041 "type": "object",
1042 "properties": {
tiernofd160572019-01-21 10:41:37 +00001043 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001044 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001045 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001046 "quotas": {
1047 "type": "object",
1048 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001049 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001050 },
tiernocd54a4a2018-09-12 16:40:35 +02001051 },
1052 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001053 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001054}
1055project_edit_schema = {
1056 "$schema": "http://json-schema.org/draft-04/schema#",
1057 "title": "Project edit schema for administrators",
1058 "type": "object",
1059 "properties": {
1060 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001061 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001062 "quotas": {
1063 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001064 "properties": {
1065 topic: {"oneOf": [integer0_schema, null_schema]}
1066 for topic in topics_with_quota
1067 },
1068 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001069 },
tiernocd54a4a2018-09-12 16:40:35 +02001070 },
1071 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001072 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001073}
1074
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001075# ROLES
1076roles_new_schema = {
1077 "$schema": "http://json-schema.org/draft-04/schema#",
1078 "title": "New role schema for administrators",
1079 "type": "object",
1080 "properties": {
1081 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001082 "permissions": {
1083 "type": "object",
1084 "patternProperties": {
1085 ".": bool_schema,
1086 },
1087 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001088 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001089 },
tierno1f029d82019-06-13 22:37:04 +00001090 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001091 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001092}
1093roles_edit_schema = {
1094 "$schema": "http://json-schema.org/draft-04/schema#",
1095 "title": "Roles edit schema for administrators",
1096 "type": "object",
1097 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001098 "name": shortname_schema,
1099 "permissions": {
1100 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001101 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001102 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001103 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001104 },
tierno1f029d82019-06-13 22:37:04 +00001105 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001106 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001107}
1108
tiernocd54a4a2018-09-12 16:40:35 +02001109# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001110
1111nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001112 "users": user_new_schema,
1113 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001114 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001115 "sdns": sdn_new_schema,
1116 "ns_instantiate": ns_instantiate,
1117 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001118 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001119 "ns_update": ns_update,
tiernocb83c942018-09-24 17:28:13 +02001120 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001121}
1122
1123nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001124 "users": user_edit_schema,
1125 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001126 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001127 "sdns": sdn_edit_schema,
1128 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001129}
1130
Felipe Vicens07f31722018-10-29 15:16:44 +01001131# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001132nsi_subnet_instantiate = deepcopy(ns_instantiate)
1133nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1134nsi_subnet_instantiate["properties"]["id"] = name_schema
1135del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001136
1137nsi_vld_instantiate = {
1138 "title": "netslice vld instantiation params input schema",
1139 "$schema": "http://json-schema.org/draft-04/schema#",
1140 "type": "object",
1141 "properties": {
1142 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001143 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1144 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001145 "ip-profile": object_schema,
1146 },
delacruzramoc061f562019-04-05 11:00:02 +02001147 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001148 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001149}
1150
Felipe Vicens07f31722018-10-29 15:16:44 +01001151nsi_instantiate = {
1152 "title": "netslice action instantiate input schema",
1153 "$schema": "http://json-schema.org/draft-04/schema#",
1154 "type": "object",
1155 "properties": {
1156 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001157 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001158 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001159 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001160 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001161 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001162 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001163 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001164 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001165 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001166 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001167 "type": "array",
1168 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001169 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001170 },
garciadeblas4568a372021-03-24 09:19:48 +01001171 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001172 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001173 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001174 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001175}
1176
garciadeblas4568a372021-03-24 09:19:48 +01001177nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001178
garciadeblas4568a372021-03-24 09:19:48 +01001179nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001180
preethika.p329b8182020-04-22 12:25:39 +05301181nsinstancesubscriptionfilter_schema = {
1182 "title": "instance identifier schema",
1183 "$schema": "http://json-schema.org/draft-07/schema#",
1184 "type": "object",
1185 "properties": {
1186 "nsdIds": {"type": "array"},
1187 "vnfdIds": {"type": "array"},
1188 "pnfdIds": {"type": "array"},
1189 "nsInstanceIds": {"type": "array"},
1190 "nsInstanceNames": {"type": "array"},
1191 },
1192}
1193
1194nslcmsub_schema = {
1195 "title": "nslcmsubscription input schema",
1196 "$schema": "http://json-schema.org/draft-07/schema#",
1197 "type": "object",
1198 "properties": {
1199 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1200 "notificationTypes": {
1201 "type": "array",
1202 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001203 "enum": [
1204 "NsLcmOperationOccurrenceNotification",
1205 "NsChangeNotification",
1206 "NsIdentifierCreationNotification",
1207 "NsIdentifierDeletionNotification",
1208 ]
1209 },
preethika.p329b8182020-04-22 12:25:39 +05301210 },
1211 "operationTypes": {
1212 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001213 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301214 },
1215 "operationStates": {
1216 "type": "array",
1217 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001218 "enum": [
1219 "PROCESSING",
1220 "COMPLETED",
1221 "PARTIALLY_COMPLETED",
1222 "FAILED",
1223 "FAILED_TEMP",
1224 "ROLLING_BACK",
1225 "ROLLED_BACK",
1226 ]
1227 },
preethika.p329b8182020-04-22 12:25:39 +05301228 },
garciadeblas4568a372021-03-24 09:19:48 +01001229 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301230 "lcmOpNameImpactingNsComponent": {
1231 "type": "array",
1232 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001233 "enum": [
1234 "VNF_INSTANTIATE",
1235 "VNF_SCALE",
1236 "VNF_SCALE_TO_LEVEL",
1237 "VNF_CHANGE_FLAVOUR",
1238 "VNF_TERMINATE",
1239 "VNF_HEAL",
1240 "VNF_OPERATE",
1241 "VNF_CHANGE_EXT_CONN",
1242 "VNF_MODIFY_INFO",
1243 "NS_INSTANTIATE",
1244 "NS_SCALE",
1245 "NS_UPDATE",
1246 "NS_TERMINATE",
1247 "NS_HEAL",
1248 ]
1249 },
preethika.p329b8182020-04-22 12:25:39 +05301250 },
1251 "lcmOpOccStatusImpactingNsComponent": {
1252 "type": "array",
1253 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001254 "enum": [
1255 "START",
1256 "COMPLETED",
1257 "PARTIALLY_COMPLETED",
1258 "FAILED",
1259 "ROLLED_BACK",
1260 ]
1261 },
preethika.p329b8182020-04-22 12:25:39 +05301262 },
1263 },
1264 "allOf": [
1265 {
1266 "if": {
1267 "properties": {
1268 "notificationTypes": {
1269 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1270 }
1271 },
1272 },
1273 "then": {
1274 "anyOf": [
1275 {"required": ["operationTypes"]},
1276 {"required": ["operationStates"]},
1277 ]
garciadeblas4568a372021-03-24 09:19:48 +01001278 },
preethika.p329b8182020-04-22 12:25:39 +05301279 },
1280 {
1281 "if": {
1282 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001283 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301284 },
1285 },
1286 "then": {
1287 "anyOf": [
1288 {"required": ["nsComponentTypes"]},
1289 {"required": ["lcmOpNameImpactingNsComponent"]},
1290 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1291 ]
garciadeblas4568a372021-03-24 09:19:48 +01001292 },
1293 },
1294 ],
preethika.p329b8182020-04-22 12:25:39 +05301295}
1296
1297authentication_schema = {
1298 "title": "authentication schema for subscription",
1299 "$schema": "http://json-schema.org/draft-07/schema#",
1300 "type": "object",
1301 "properties": {
1302 "authType": {"enum": ["basic"]},
1303 "paramsBasic": {
1304 "type": "object",
1305 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001306 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301307 "password": passwd_schema,
1308 },
1309 },
1310 },
1311}
1312
1313subscription = {
1314 "title": "subscription input schema",
1315 "$schema": "http://json-schema.org/draft-07/schema#",
1316 "type": "object",
1317 "properties": {
1318 "filter": nslcmsub_schema,
1319 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001320 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301321 },
1322 "required": ["CallbackUri"],
1323}
1324
selvi.jf1004592022-04-29 05:42:35 +00001325vnflcmsub_schema = {
1326 "title": "vnflcmsubscription input schema",
1327 "$schema": "http://json-schema.org/draft-07/schema#",
1328 "type": "object",
1329 "properties": {
1330 "VnfInstanceSubscriptionFilter": {
1331 "type": "object",
1332 "properties": {
1333 "vnfdIds": {"type": "array"},
1334 "vnfInstanceIds": {"type": "array"},
1335 },
1336 },
1337 "notificationTypes": {
1338 "type": "array",
1339 "items": {
1340 "enum": [
1341 "VnfIdentifierCreationNotification",
1342 "VnfLcmOperationOccurrenceNotification",
1343 "VnfIdentifierDeletionNotification"
1344 ]
1345 }
1346 },
1347 "operationTypes": {
1348 "type": "array",
1349 "items": {
1350 "enum": [
1351 "INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE",
1352 "HEAL", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO", "CREATE_SNAPSHOT",
1353 "REVERT_TO_SNAPSHOT", "CHANGE_VNFPKG"
1354 ]
1355 }
1356 },
1357 "operationStates": {
1358 "type": "array",
1359 "items": {
1360 "enum": [
1361 "STARTING", "PROCESSING", "COMPLETED", "FAILED_TEMP", "FAILED",
1362 "ROLLING_BACK", "ROLLED_BACK"
1363 ]
1364 }
1365 }
1366 },
1367 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"]
1368 }
1369
1370vnf_subscription = {
1371 "title": "vnf subscription input schema",
1372 "$schema": "http://json-schema.org/draft-07/schema#",
1373 "type": "object",
1374 "properties": {
1375 "filter": vnflcmsub_schema,
1376 "CallbackUri": description_schema,
1377 "authentication": authentication_schema
1378 },
1379 "required": ["filter", "CallbackUri"]
1380}
1381
tierno0f98af52018-03-19 10:28:22 +01001382
1383class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001384 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1385 self.http_code = http_code
1386 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001387
1388
tiernob24258a2018-10-04 18:39:49 +02001389def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001390 """
tiernocd54a4a2018-09-12 16:40:35 +02001391 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001392 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001393 :param schema_to_use: jsonschema to test
1394 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001395 """
1396 try:
tierno0f98af52018-03-19 10:28:22 +01001397 if schema_to_use:
1398 js_v(indata, schema_to_use)
1399 return None
1400 except js_e.ValidationError as e:
1401 if e.path:
tierno0da52252018-06-27 15:47:22 +02001402 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001403 else:
1404 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001405 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001406 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001407 raise ValidationError(
1408 "Bad json schema {}".format(schema_to_use),
1409 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1410 )
delacruzramoc061f562019-04-05 11:00:02 +02001411
1412
1413def is_valid_uuid(x):
1414 """
1415 Test for a valid UUID
1416 :param x: string to test
1417 :return: True if x is a valid uuid, False otherwise
1418 """
1419 try:
1420 if UUID(x):
1421 return True
tiernobdebce92019-07-01 15:36:49 +00001422 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001423 return False