blob: f9213d83d72e7c1901abc5f6482a253870dbc165 [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": {
k4.rahule3dca382022-04-29 12:30:36 +0000452 "enum": ["CHANGE_VNFPKG", "REMOVE_VNF", "MODIFY_VNF_INFORMATION", "OPERATE_VNF"]
aticig544a2ae2022-04-05 09:00:17 +0300453 },
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 },
k4.rahule3dca382022-04-29 12:30:36 +0000471 "operateVnfData": {
472 "type": "object",
473 "properties": {
474 "vnfInstanceId": id_schema,
475 "changeStateTo": name_schema,
476 "additionalParam": {
477 "type": "object",
478 "properties": {
479 "run-day1": bool_schema,
480 "vdu_id": name_schema,
481 "count-index": integer0_schema,
482 },
483 "required": ["vdu_id", "count-index"],
484 "additionalProperties": False,
485 }
486 },
487 "required": ["vnfInstanceId", "changeStateTo"],
488 }
aticig544a2ae2022-04-05 09:00:17 +0300489 },
490 "required": ["updateType"],
491 "additionalProperties": False,
492}
493
garciadeblas4568a372021-03-24 09:19:48 +0100494ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200495 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200496 "$schema": "http://json-schema.org/draft-04/schema#",
497 "type": "object",
498 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200499 "lcmOperationType": string_schema,
500 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200501 "member_vnf_index": name_schema,
502 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200503 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000504 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000505 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200506 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000507 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200508 "primitive_params": {"type": "object"},
509 },
garciadeblas4568a372021-03-24 09:19:48 +0100510 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
511 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200512}
garciadeblas0964edf2022-02-11 00:43:44 +0100513
garciadeblas4568a372021-03-24 09:19:48 +0100514ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200515 "title": "ns scale input schema",
516 "$schema": "http://json-schema.org/draft-04/schema#",
517 "type": "object",
518 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200519 "lcmOperationType": string_schema,
520 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200521 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000522 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200523 "scaleVnfData": {
524 "type": "object",
525 "properties": {
526 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100527 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200528 "scaleByStepData": {
529 "type": "object",
530 "properties": {
531 "scaling-group-descriptor": name_schema,
532 "member-vnf-index": name_schema,
533 "scaling-policy": name_schema,
534 },
535 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100536 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200537 },
538 },
539 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100540 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200541 },
542 "scaleTime": time_schema,
543 },
544 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100545 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200546}
tierno65acb4d2018-04-06 16:42:40 +0200547
elumalai8e3806c2022-04-28 17:26:24 +0530548ns_migrate = {
549 "title": "ns migrate input schema",
550 "$schema": "http://json-schema.org/draft-04/schema#",
551 "type": "object",
552 "properties": {
553 "lcmOperationType": string_schema,
554 "nsInstanceId": id_schema,
555 "vnfInstanceId": id_schema,
556 "migrateToHost": string_schema,
557 "vdu": {
558 "type": "object",
559 "properties": {
560 "vduId": name_schema,
561 "vduCountIndex": integer0_schema,
562 },
563 "required": ["vduId"],
564 "additionalProperties": False,
565 },
566 },
567 "required": ["vnfInstanceId"],
568 "additionalProperties": False
569}
tierno65acb4d2018-04-06 16:42:40 +0200570
garciadeblas0964edf2022-02-11 00:43:44 +0100571ns_heal = {
572 "title": "ns heal input schema",
573 "$schema": "http://json-schema.org/draft-04/schema#",
574 "type": "object",
575 "properties": {
576 "lcmOperationType": string_schema,
577 "nsInstanceId": id_schema,
578 "timeout_ns_heal": integer1_schema,
579 "healVnfData": {
580 "type": "array",
581 "items": {
582 "type": "object",
583 "properties": {
584 "vnfInstanceId": id_schema,
585 "cause": description_schema,
586 "additionalParams": {
587 "type": "object",
588 "properties": {
589 "run-day1": bool_schema,
590 "vdu": {
591 "type": "array",
592 "items": {
593 "type": "object",
594 "properties": {
595 "run-day1": bool_schema,
596 "vdu-id": name_schema,
597 "count-index": integer0_schema,
598 },
599 "required": ["vdu-id"],
600 "additionalProperties": False,
601 },
602 },
603 },
604 "additionalProperties": False,
605 },
606 },
607 "required": ["vnfInstanceId"],
608 "additionalProperties": False,
609 },
610 },
611 },
612 "required": ["healVnfData"],
613 "additionalProperties": False,
614}
615
tierno0f98af52018-03-19 10:28:22 +0100616schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000617schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000618vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200619
tierno09c073e2018-04-26 13:36:48 +0200620vim_account_edit_schema = {
621 "title": "vim_account edit input schema",
622 "$schema": "http://json-schema.org/draft-04/schema#",
623 "type": "object",
624 "properties": {
625 "name": name_schema,
626 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200627 "vim": name_schema,
628 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200629 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200630 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200631 # "vim_url_admin": description_schema,
632 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200633 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200634 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200635 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200636 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100637 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000638 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200639 },
garciadeblas4568a372021-03-24 09:19:48 +0100640 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200641}
tierno0f98af52018-03-19 10:28:22 +0100642
tierno09c073e2018-04-26 13:36:48 +0200643vim_account_new_schema = {
644 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100645 "$schema": "http://json-schema.org/draft-04/schema#",
646 "type": "object",
647 "properties": {
648 "schema_version": schema_version,
649 "schema_type": schema_type,
650 "name": name_schema,
651 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200652 "vim": name_schema,
653 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200654 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100655 "vim_url": description_schema,
656 # "vim_url_admin": description_schema,
657 # "vim_tenant": name_schema,
658 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200659 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200660 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200661 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100662 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000663 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100664 },
garciadeblas4568a372021-03-24 09:19:48 +0100665 "required": [
666 "name",
667 "vim_url",
668 "vim_type",
669 "vim_user",
670 "vim_password",
671 "vim_tenant_name",
672 ],
673 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100674}
tierno0f98af52018-03-19 10:28:22 +0100675
tierno85807722019-12-20 14:11:35 +0000676wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200677
tierno55ba2e62018-12-11 17:22:22 +0000678wim_account_edit_schema = {
679 "title": "wim_account edit input schema",
680 "$schema": "http://json-schema.org/draft-04/schema#",
681 "type": "object",
682 "properties": {
683 "name": name_schema,
684 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000685 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200686 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000687 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100688 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000689 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100690 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000691 },
garciadeblas4568a372021-03-24 09:19:48 +0100692 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000693}
694
695wim_account_new_schema = {
696 "title": "wim_account creation input schema",
697 "$schema": "http://json-schema.org/draft-04/schema#",
698 "type": "object",
699 "properties": {
700 "schema_version": schema_version,
701 "schema_type": schema_type,
702 "name": name_schema,
703 "description": description_schema,
704 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200705 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000706 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100707 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000708 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000709 "config": {
710 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100711 "patternProperties": {".": {"not": {"type": "null"}}},
712 },
tierno55ba2e62018-12-11 17:22:22 +0000713 },
714 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100715 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000716}
tierno0f98af52018-03-19 10:28:22 +0100717
718sdn_properties = {
719 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000720 "type": {"type": "string"},
721 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100722 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000723 "password": passwd_schema,
724 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200725 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000726 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200727 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100728 "ip": ip_schema,
729 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100730 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100731}
732sdn_new_schema = {
733 "title": "sdn controller information schema",
734 "$schema": "http://json-schema.org/draft-04/schema#",
735 "type": "object",
736 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100737 "required": ["name", "type"],
738 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100739}
740sdn_edit_schema = {
741 "title": "sdn controller update information schema",
742 "$schema": "http://json-schema.org/draft-04/schema#",
743 "type": "object",
744 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200745 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100746 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100747}
748sdn_port_mapping_schema = {
749 "$schema": "http://json-schema.org/draft-04/schema#",
750 "title": "sdn port mapping information schema",
751 "type": "array",
752 "items": {
753 "type": "object",
754 "properties": {
tiernofd160572019-01-21 10:41:37 +0000755 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100756 "ports": {
757 "type": "array",
758 "items": {
759 "type": "object",
760 "properties": {
tierno42fce592018-11-02 09:23:43 +0100761 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000762 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100763 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100764 },
garciadeblas4568a372021-03-24 09:19:48 +0100765 "required": ["pci"],
766 },
767 },
tierno0f98af52018-03-19 10:28:22 +0100768 },
garciadeblas4568a372021-03-24 09:19:48 +0100769 "required": ["compute_node", "ports"],
770 },
tierno0f98af52018-03-19 10:28:22 +0100771}
772sdn_external_port_schema = {
773 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200774 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100775 "type": "object",
776 "properties": {
777 "port": {"type": "string", "minLength": 1, "maxLength": 60},
778 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100779 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100780 },
garciadeblas4568a372021-03-24 09:19:48 +0100781 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100782}
783
delacruzramofe598fe2019-10-23 18:25:11 +0200784# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500785k8scluster_deploy_method_schema = {
786 "$schema": "http://json-schema.org/draft-04/schema#",
787 "title": "Deployment methods for K8s cluster",
788 "type": "object",
789 "properties": {
790 "helm-chart": {"type": "boolean"},
791 "juju-bundle": {"type": "boolean"},
792 "helm-chart-v3": {"type": "boolean"},
793 },
794 "additionalProperties": False,
795 "minProperties": 3,
796}
delacruzramofe598fe2019-10-23 18:25:11 +0200797k8scluster_nets_schema = {
798 "title": "k8scluster nets input schema",
799 "$schema": "http://json-schema.org/draft-04/schema#",
800 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000801 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200802 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100803 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200804}
805k8scluster_new_schema = {
806 "title": "k8scluster creation input schema",
807 "$schema": "http://json-schema.org/draft-04/schema#",
808 "type": "object",
809 "properties": {
810 "schema_version": schema_version,
811 "schema_type": schema_type,
812 "name": name_schema,
813 "description": description_schema,
814 "credentials": object_schema,
815 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200816 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200817 "k8s_version": string_schema,
818 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500819 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200820 "namespace": name_schema,
821 "cni": nameshort_list_schema,
822 },
823 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100824 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200825}
826k8scluster_edit_schema = {
827 "title": "vim_account edit input schema",
828 "$schema": "http://json-schema.org/draft-04/schema#",
829 "type": "object",
830 "properties": {
831 "name": name_schema,
832 "description": description_schema,
833 "credentials": object_schema,
834 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200835 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200836 "k8s_version": string_schema,
837 "nets": k8scluster_nets_schema,
838 "namespace": name_schema,
839 "cni": nameshort_list_schema,
840 },
garciadeblas4568a372021-03-24 09:19:48 +0100841 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200842}
843
David Garciaecb41322021-03-31 19:10:46 +0200844# VCA
845vca_new_schema = {
846 "title": "vca creation input schema",
847 "$schema": "http://json-schema.org/draft-04/schema#",
848 "type": "object",
849 "properties": {
850 "schema_version": schema_version,
851 "schema_type": schema_type,
852 "name": name_schema,
853 "description": description_schema,
854 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100855 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200856 "secret": passwd_schema,
857 "cacert": long_description_schema,
858 "lxd-cloud": shortname_schema,
859 "lxd-credentials": shortname_schema,
860 "k8s-cloud": shortname_schema,
861 "k8s-credentials": shortname_schema,
862 "model-config": object_schema,
863 },
864 "required": [
865 "name",
866 "endpoints",
867 "user",
868 "secret",
869 "cacert",
870 "lxd-cloud",
871 "lxd-credentials",
872 "k8s-cloud",
873 "k8s-credentials",
874 ],
875 "additionalProperties": False,
876}
877vca_edit_schema = {
878 "title": "vca creation input schema",
879 "$schema": "http://json-schema.org/draft-04/schema#",
880 "type": "object",
881 "properties": {
882 "name": name_schema,
883 "description": description_schema,
884 "endpoints": description_list_schema,
885 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100886 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200887 "secret": passwd_schema,
888 "cacert": long_description_schema,
889 "lxd-cloud": shortname_schema,
890 "lxd-credentials": shortname_schema,
891 "k8s-cloud": shortname_schema,
892 "k8s-credentials": shortname_schema,
893 "model-config": object_schema,
894 },
895 "additionalProperties": False,
896}
897
delacruzramofe598fe2019-10-23 18:25:11 +0200898# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000899k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200900k8srepo_properties = {
901 "name": name_schema,
902 "description": description_schema,
903 "type": k8srepo_types,
904 "url": description_schema,
905}
906k8srepo_new_schema = {
907 "title": "k8scluster creation input schema",
908 "$schema": "http://json-schema.org/draft-04/schema#",
909 "type": "object",
910 "properties": k8srepo_properties,
911 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100912 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200913}
914k8srepo_edit_schema = {
915 "title": "vim_account edit input schema",
916 "$schema": "http://json-schema.org/draft-04/schema#",
917 "type": "object",
918 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100919 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200920}
921
Felipe Vicensb66b0412020-05-06 10:11:00 +0200922# OSM Repos
923osmrepo_types = {"enum": ["osm"]}
924osmrepo_properties = {
925 "name": name_schema,
926 "description": description_schema,
927 "type": osmrepo_types,
928 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100929 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200930 # "password": passwd_schema
931}
932osmrepo_new_schema = {
933 "title": "osm repo creation input schema",
934 "$schema": "http://json-schema.org/draft-04/schema#",
935 "type": "object",
936 "properties": osmrepo_properties,
937 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100938 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200939}
940osmrepo_edit_schema = {
941 "title": "osm repo edit input schema",
942 "$schema": "http://json-schema.org/draft-04/schema#",
943 "type": "object",
944 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100945 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200946}
947
tiernocb83c942018-09-24 17:28:13 +0200948# PDUs
949pdu_interface = {
950 "type": "object",
951 "properties": {
tiernofd160572019-01-21 10:41:37 +0000952 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200953 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100954 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200955 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200956 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100957 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000958 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
959 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100960 # # provide this in case SDN assist must deal with this interface
961 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000962 # "switch-port": shortname_schema,
963 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100964 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200965 },
tierno36ec8602018-11-02 17:27:11 +0100966 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100967 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200968}
tiernocb83c942018-09-24 17:28:13 +0200969pdu_new_schema = {
970 "title": "pdu creation input schema",
971 "$schema": "http://json-schema.org/draft-04/schema#",
972 "type": "object",
973 "properties": {
tiernofd160572019-01-21 10:41:37 +0000974 "name": shortname_schema,
975 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200976 "description": description_schema,
977 "shared": bool_schema,
978 "vims": nameshort_list_schema,
979 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100980 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +0200981 },
982 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +0100983 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +0200984}
tiernocb83c942018-09-24 17:28:13 +0200985pdu_edit_schema = {
986 "title": "pdu edit input schema",
987 "$schema": "http://json-schema.org/draft-04/schema#",
988 "type": "object",
989 "properties": {
tiernofd160572019-01-21 10:41:37 +0000990 "name": shortname_schema,
991 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200992 "description": description_schema,
993 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +0100994 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
995 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +0100996 "interfaces": {
997 "oneOf": [
998 array_edition_schema,
999 {"type": "array", "items": pdu_interface, "minItems": 1},
1000 ]
1001 },
tiernocb83c942018-09-24 17:28:13 +02001002 },
1003 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001004 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001005}
1006
delacruzramo271d2002019-12-02 21:00:37 +01001007# VNF PKG OPERATIONS
1008vnfpkgop_new_schema = {
1009 "title": "VNF PKG operation creation input schema",
1010 "$schema": "http://json-schema.org/draft-04/schema#",
1011 "type": "object",
1012 "properties": {
1013 "lcmOperationType": string_schema,
1014 "vnfPkgId": id_schema,
1015 "kdu_name": name_schema,
1016 "primitive": name_schema,
1017 "primitive_params": {"type": "object"},
1018 },
garciadeblas4568a372021-03-24 09:19:48 +01001019 "required": [
1020 "lcmOperationType",
1021 "vnfPkgId",
1022 "kdu_name",
1023 "primitive",
1024 "primitive_params",
1025 ],
1026 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001027}
1028
tiernocb83c942018-09-24 17:28:13 +02001029# USERS
tiernocf042d32019-06-13 09:06:40 +00001030project_role_mappings = {
1031 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001032 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001033 "type": "array",
1034 "items": {
1035 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001036 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001037 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001038 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001039 },
garciadeblas4568a372021-03-24 09:19:48 +01001040 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001041}
1042project_role_mappings_optional = {
1043 "title": "list of projects/roles or projects only",
1044 "$schema": "http://json-schema.org/draft-04/schema#",
1045 "type": "array",
1046 "items": {
1047 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001048 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001049 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001050 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001051 },
garciadeblas4568a372021-03-24 09:19:48 +01001052 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001053}
tiernocd54a4a2018-09-12 16:40:35 +02001054user_new_schema = {
1055 "$schema": "http://json-schema.org/draft-04/schema#",
1056 "title": "New user schema",
1057 "type": "object",
1058 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001059 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001060 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001061 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001062 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001063 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001064 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001065 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001066 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001067}
1068user_edit_schema = {
1069 "$schema": "http://json-schema.org/draft-04/schema#",
1070 "title": "User edit schema for administrators",
1071 "type": "object",
1072 "properties": {
1073 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001074 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001075 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001076 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001077 "project_role_mappings": project_role_mappings,
1078 "add_project_role_mappings": project_role_mappings,
1079 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +02001080 },
1081 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001082 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001083}
1084
1085# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001086topics_with_quota = [
1087 "vnfds",
1088 "nsds",
1089 "slice_templates",
1090 "pduds",
1091 "ns_instances",
1092 "slice_instances",
1093 "vim_accounts",
1094 "wim_accounts",
1095 "sdn_controllers",
1096 "k8sclusters",
1097 "vca",
1098 "k8srepos",
1099 "osmrepos",
1100 "ns_subscriptions",
1101]
tiernocd54a4a2018-09-12 16:40:35 +02001102project_new_schema = {
1103 "$schema": "http://json-schema.org/draft-04/schema#",
1104 "title": "New project schema for administrators",
1105 "type": "object",
1106 "properties": {
tiernofd160572019-01-21 10:41:37 +00001107 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001108 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001109 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001110 "quotas": {
1111 "type": "object",
1112 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001113 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001114 },
tiernocd54a4a2018-09-12 16:40:35 +02001115 },
1116 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001117 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001118}
1119project_edit_schema = {
1120 "$schema": "http://json-schema.org/draft-04/schema#",
1121 "title": "Project edit schema for administrators",
1122 "type": "object",
1123 "properties": {
1124 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001125 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001126 "quotas": {
1127 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001128 "properties": {
1129 topic: {"oneOf": [integer0_schema, null_schema]}
1130 for topic in topics_with_quota
1131 },
1132 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001133 },
tiernocd54a4a2018-09-12 16:40:35 +02001134 },
1135 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001136 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001137}
1138
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001139# ROLES
1140roles_new_schema = {
1141 "$schema": "http://json-schema.org/draft-04/schema#",
1142 "title": "New role schema for administrators",
1143 "type": "object",
1144 "properties": {
1145 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001146 "permissions": {
1147 "type": "object",
1148 "patternProperties": {
1149 ".": bool_schema,
1150 },
1151 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001152 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001153 },
tierno1f029d82019-06-13 22:37:04 +00001154 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001155 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001156}
1157roles_edit_schema = {
1158 "$schema": "http://json-schema.org/draft-04/schema#",
1159 "title": "Roles edit schema for administrators",
1160 "type": "object",
1161 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001162 "name": shortname_schema,
1163 "permissions": {
1164 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001165 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001166 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001167 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001168 },
tierno1f029d82019-06-13 22:37:04 +00001169 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001170 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001171}
1172
tiernocd54a4a2018-09-12 16:40:35 +02001173# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001174
1175nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001176 "users": user_new_schema,
1177 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001178 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001179 "sdns": sdn_new_schema,
1180 "ns_instantiate": ns_instantiate,
1181 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001182 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001183 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001184 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001185 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001186}
1187
1188nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001189 "users": user_edit_schema,
1190 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001191 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001192 "sdns": sdn_edit_schema,
1193 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001194}
1195
Felipe Vicens07f31722018-10-29 15:16:44 +01001196# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001197nsi_subnet_instantiate = deepcopy(ns_instantiate)
1198nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1199nsi_subnet_instantiate["properties"]["id"] = name_schema
1200del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001201
1202nsi_vld_instantiate = {
1203 "title": "netslice vld instantiation params input schema",
1204 "$schema": "http://json-schema.org/draft-04/schema#",
1205 "type": "object",
1206 "properties": {
1207 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001208 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1209 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001210 "ip-profile": object_schema,
1211 },
delacruzramoc061f562019-04-05 11:00:02 +02001212 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001213 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001214}
1215
Felipe Vicens07f31722018-10-29 15:16:44 +01001216nsi_instantiate = {
1217 "title": "netslice action instantiate input schema",
1218 "$schema": "http://json-schema.org/draft-04/schema#",
1219 "type": "object",
1220 "properties": {
1221 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001222 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001223 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001224 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001225 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001226 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001227 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001228 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001229 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001230 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001231 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001232 "type": "array",
1233 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001234 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001235 },
garciadeblas4568a372021-03-24 09:19:48 +01001236 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001237 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001238 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001239 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001240}
1241
garciadeblas4568a372021-03-24 09:19:48 +01001242nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001243
garciadeblas4568a372021-03-24 09:19:48 +01001244nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001245
preethika.p329b8182020-04-22 12:25:39 +05301246nsinstancesubscriptionfilter_schema = {
1247 "title": "instance identifier schema",
1248 "$schema": "http://json-schema.org/draft-07/schema#",
1249 "type": "object",
1250 "properties": {
1251 "nsdIds": {"type": "array"},
1252 "vnfdIds": {"type": "array"},
1253 "pnfdIds": {"type": "array"},
1254 "nsInstanceIds": {"type": "array"},
1255 "nsInstanceNames": {"type": "array"},
1256 },
1257}
1258
1259nslcmsub_schema = {
1260 "title": "nslcmsubscription input schema",
1261 "$schema": "http://json-schema.org/draft-07/schema#",
1262 "type": "object",
1263 "properties": {
1264 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1265 "notificationTypes": {
1266 "type": "array",
1267 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001268 "enum": [
1269 "NsLcmOperationOccurrenceNotification",
1270 "NsChangeNotification",
1271 "NsIdentifierCreationNotification",
1272 "NsIdentifierDeletionNotification",
1273 ]
1274 },
preethika.p329b8182020-04-22 12:25:39 +05301275 },
1276 "operationTypes": {
1277 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001278 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301279 },
1280 "operationStates": {
1281 "type": "array",
1282 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001283 "enum": [
1284 "PROCESSING",
1285 "COMPLETED",
1286 "PARTIALLY_COMPLETED",
1287 "FAILED",
1288 "FAILED_TEMP",
1289 "ROLLING_BACK",
1290 "ROLLED_BACK",
1291 ]
1292 },
preethika.p329b8182020-04-22 12:25:39 +05301293 },
garciadeblas4568a372021-03-24 09:19:48 +01001294 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301295 "lcmOpNameImpactingNsComponent": {
1296 "type": "array",
1297 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001298 "enum": [
1299 "VNF_INSTANTIATE",
1300 "VNF_SCALE",
1301 "VNF_SCALE_TO_LEVEL",
1302 "VNF_CHANGE_FLAVOUR",
1303 "VNF_TERMINATE",
1304 "VNF_HEAL",
1305 "VNF_OPERATE",
1306 "VNF_CHANGE_EXT_CONN",
1307 "VNF_MODIFY_INFO",
1308 "NS_INSTANTIATE",
1309 "NS_SCALE",
1310 "NS_UPDATE",
1311 "NS_TERMINATE",
1312 "NS_HEAL",
1313 ]
1314 },
preethika.p329b8182020-04-22 12:25:39 +05301315 },
1316 "lcmOpOccStatusImpactingNsComponent": {
1317 "type": "array",
1318 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001319 "enum": [
1320 "START",
1321 "COMPLETED",
1322 "PARTIALLY_COMPLETED",
1323 "FAILED",
1324 "ROLLED_BACK",
1325 ]
1326 },
preethika.p329b8182020-04-22 12:25:39 +05301327 },
1328 },
1329 "allOf": [
1330 {
1331 "if": {
1332 "properties": {
1333 "notificationTypes": {
1334 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1335 }
1336 },
1337 },
1338 "then": {
1339 "anyOf": [
1340 {"required": ["operationTypes"]},
1341 {"required": ["operationStates"]},
1342 ]
garciadeblas4568a372021-03-24 09:19:48 +01001343 },
preethika.p329b8182020-04-22 12:25:39 +05301344 },
1345 {
1346 "if": {
1347 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001348 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301349 },
1350 },
1351 "then": {
1352 "anyOf": [
1353 {"required": ["nsComponentTypes"]},
1354 {"required": ["lcmOpNameImpactingNsComponent"]},
1355 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1356 ]
garciadeblas4568a372021-03-24 09:19:48 +01001357 },
1358 },
1359 ],
preethika.p329b8182020-04-22 12:25:39 +05301360}
1361
1362authentication_schema = {
1363 "title": "authentication schema for subscription",
1364 "$schema": "http://json-schema.org/draft-07/schema#",
1365 "type": "object",
1366 "properties": {
1367 "authType": {"enum": ["basic"]},
1368 "paramsBasic": {
1369 "type": "object",
1370 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001371 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301372 "password": passwd_schema,
1373 },
1374 },
1375 },
1376}
1377
1378subscription = {
1379 "title": "subscription input schema",
1380 "$schema": "http://json-schema.org/draft-07/schema#",
1381 "type": "object",
1382 "properties": {
1383 "filter": nslcmsub_schema,
1384 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001385 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301386 },
1387 "required": ["CallbackUri"],
1388}
1389
selvi.jf1004592022-04-29 05:42:35 +00001390vnflcmsub_schema = {
1391 "title": "vnflcmsubscription input schema",
1392 "$schema": "http://json-schema.org/draft-07/schema#",
1393 "type": "object",
1394 "properties": {
1395 "VnfInstanceSubscriptionFilter": {
1396 "type": "object",
1397 "properties": {
1398 "vnfdIds": {"type": "array"},
1399 "vnfInstanceIds": {"type": "array"},
1400 },
1401 },
1402 "notificationTypes": {
1403 "type": "array",
1404 "items": {
1405 "enum": [
1406 "VnfIdentifierCreationNotification",
1407 "VnfLcmOperationOccurrenceNotification",
1408 "VnfIdentifierDeletionNotification"
1409 ]
1410 }
1411 },
1412 "operationTypes": {
1413 "type": "array",
1414 "items": {
1415 "enum": [
1416 "INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE",
1417 "HEAL", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO", "CREATE_SNAPSHOT",
1418 "REVERT_TO_SNAPSHOT", "CHANGE_VNFPKG"
1419 ]
1420 }
1421 },
1422 "operationStates": {
1423 "type": "array",
1424 "items": {
1425 "enum": [
1426 "STARTING", "PROCESSING", "COMPLETED", "FAILED_TEMP", "FAILED",
1427 "ROLLING_BACK", "ROLLED_BACK"
1428 ]
1429 }
1430 }
1431 },
1432 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"]
1433 }
1434
1435vnf_subscription = {
1436 "title": "vnf subscription input schema",
1437 "$schema": "http://json-schema.org/draft-07/schema#",
1438 "type": "object",
1439 "properties": {
1440 "filter": vnflcmsub_schema,
1441 "CallbackUri": description_schema,
1442 "authentication": authentication_schema
1443 },
1444 "required": ["filter", "CallbackUri"]
1445}
1446
tierno0f98af52018-03-19 10:28:22 +01001447
1448class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001449 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1450 self.http_code = http_code
1451 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001452
1453
tiernob24258a2018-10-04 18:39:49 +02001454def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001455 """
tiernocd54a4a2018-09-12 16:40:35 +02001456 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001457 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001458 :param schema_to_use: jsonschema to test
1459 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001460 """
1461 try:
tierno0f98af52018-03-19 10:28:22 +01001462 if schema_to_use:
1463 js_v(indata, schema_to_use)
1464 return None
1465 except js_e.ValidationError as e:
1466 if e.path:
tierno0da52252018-06-27 15:47:22 +02001467 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001468 else:
1469 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001470 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001471 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001472 raise ValidationError(
1473 "Bad json schema {}".format(schema_to_use),
1474 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1475 )
delacruzramoc061f562019-04-05 11:00:02 +02001476
1477
1478def is_valid_uuid(x):
1479 """
1480 Test for a valid UUID
1481 :param x: string to test
1482 :return: True if x is a valid uuid, False otherwise
1483 """
1484 try:
1485 if UUID(x):
1486 return True
tiernobdebce92019-07-01 15:36:49 +00001487 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001488 return False