blob: d1cfc1df1d0cf7cec1242521f4b6c7cf817f82b0 [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 },
tiernofd160572019-01-21 10:41:37 +0000319 },
tierno714954e2019-11-29 13:43:26 +0000320 "required": ["member-vnf-index"],
321 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100322 "additionalProperties": False,
323 },
tiernofd160572019-01-21 10:41:37 +0000324}
325
tierno65acb4d2018-04-06 16:42:40 +0200326ns_instantiate = {
327 "title": "ns action instantiate input schema",
328 "$schema": "http://json-schema.org/draft-04/schema#",
329 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200330 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200331 "lcmOperationType": string_schema,
332 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100333 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200334 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000335 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200336 "nsdId": id_schema,
337 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000338 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100339 "placement-engine": string_schema,
340 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000341 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000342 "additionalParamsForVnf": additional_params_for_vnf,
garciadeblas4568a372021-03-24 09:19:48 +0100343 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000344 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100345 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000346 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200347 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200348 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200349 "vnf": {
350 "type": "array",
351 "minItems": 1,
352 "items": {
353 "type": "object",
354 "properties": {
355 "member-vnf-index": name_schema,
356 "vimAccountId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200357 "vdu": {
358 "type": "array",
359 "minItems": 1,
360 "items": ns_instantiate_vdu,
361 },
362 "internal-vld": {
363 "type": "array",
364 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100365 "items": ns_instantiate_internal_vld,
366 },
tierno0da52252018-06-27 15:47:22 +0200367 },
tierno441dbbf2018-07-10 12:52:48 +0200368 "required": ["member-vnf-index"],
369 "minProperties": 2,
garciadeblas4568a372021-03-24 09:19:48 +0100370 "additionalProperties": False,
371 },
tierno0da52252018-06-27 15:47:22 +0200372 },
373 "vld": {
374 "type": "array",
375 "minItems": 1,
376 "items": {
377 "type": "object",
378 "properties": {
379 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000380 "vim-network-name": {"oneOf": [string_schema, object_schema]},
381 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100382 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000383 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200384 "ip-profile": object_schema,
kbsub21f03f52019-10-17 16:26:56 +0000385 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200386 "vnfd-connection-point-ref": {
387 "type": "array",
388 "minItems": 1,
389 "items": {
390 "type": "object",
391 "properties": {
392 "member-vnf-index-ref": name_schema,
393 "vnfd-connection-point-ref": name_schema,
garciadeblas9fb32712022-04-04 16:33:59 +0200394 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernob7c6f2a2018-09-03 14:32:10 +0200395 # "mac-address": mac_schema,
396 },
garciadeblas4568a372021-03-24 09:19:48 +0100397 "required": [
398 "member-vnf-index-ref",
399 "vnfd-connection-point-ref",
400 ],
tiernob7c6f2a2018-09-03 14:32:10 +0200401 "minProperties": 3,
garciadeblas4568a372021-03-24 09:19:48 +0100402 "additionalProperties": False,
tiernob7c6f2a2018-09-03 14:32:10 +0200403 },
garciadeblas4568a372021-03-24 09:19:48 +0100404 },
tierno0da52252018-06-27 15:47:22 +0200405 },
tierno441dbbf2018-07-10 12:52:48 +0200406 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100407 "additionalProperties": False,
408 },
tierno0da52252018-06-27 15:47:22 +0200409 },
410 },
tierno441dbbf2018-07-10 12:52:48 +0200411 "required": ["nsName", "nsdId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +0100412 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200413}
tierno0da52252018-06-27 15:47:22 +0200414
tierno1c38f2f2020-03-24 11:51:39 +0000415ns_terminate = {
416 "title": "ns terminate input schema",
417 "$schema": "http://json-schema.org/draft-04/schema#",
418 "type": "object",
419 "properties": {
420 "lcmOperationType": string_schema,
421 "nsInstanceId": id_schema,
422 "autoremove": bool_schema,
423 "timeout_ns_terminate": integer1_schema,
424 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000425 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000426 },
garciadeblas4568a372021-03-24 09:19:48 +0100427 "additionalProperties": False,
tierno1c38f2f2020-03-24 11:51:39 +0000428}
429
garciadeblas4568a372021-03-24 09:19:48 +0100430ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200431 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200432 "$schema": "http://json-schema.org/draft-04/schema#",
433 "type": "object",
434 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200435 "lcmOperationType": string_schema,
436 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200437 "member_vnf_index": name_schema,
438 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200439 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000440 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000441 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200442 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000443 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200444 "primitive_params": {"type": "object"},
445 },
garciadeblas4568a372021-03-24 09:19:48 +0100446 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
447 "additionalProperties": False,
tierno65acb4d2018-04-06 16:42:40 +0200448}
garciadeblas4568a372021-03-24 09:19:48 +0100449ns_scale = { # TODO for the moment it is only VDU-scaling
tiernof759d822018-06-11 18:54:54 +0200450 "title": "ns scale input schema",
451 "$schema": "http://json-schema.org/draft-04/schema#",
452 "type": "object",
453 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200454 "lcmOperationType": string_schema,
455 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200456 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000457 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200458 "scaleVnfData": {
459 "type": "object",
460 "properties": {
461 "vnfInstanceId": name_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100462 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]},
tiernof759d822018-06-11 18:54:54 +0200463 "scaleByStepData": {
464 "type": "object",
465 "properties": {
466 "scaling-group-descriptor": name_schema,
467 "member-vnf-index": name_schema,
468 "scaling-policy": name_schema,
469 },
470 "required": ["scaling-group-descriptor", "member-vnf-index"],
garciadeblas4568a372021-03-24 09:19:48 +0100471 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200472 },
473 },
474 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
garciadeblas4568a372021-03-24 09:19:48 +0100475 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200476 },
477 "scaleTime": time_schema,
478 },
479 "required": ["scaleType", "scaleVnfData"],
garciadeblas4568a372021-03-24 09:19:48 +0100480 "additionalProperties": False,
tiernof759d822018-06-11 18:54:54 +0200481}
tierno65acb4d2018-04-06 16:42:40 +0200482
483
tierno0f98af52018-03-19 10:28:22 +0100484schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000485schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000486vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200487
tierno09c073e2018-04-26 13:36:48 +0200488vim_account_edit_schema = {
489 "title": "vim_account edit input schema",
490 "$schema": "http://json-schema.org/draft-04/schema#",
491 "type": "object",
492 "properties": {
493 "name": name_schema,
494 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200495 "vim": name_schema,
496 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200497 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200498 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200499 # "vim_url_admin": description_schema,
500 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200501 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200502 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200503 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200504 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100505 "config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200506 },
garciadeblas4568a372021-03-24 09:19:48 +0100507 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200508}
tierno0f98af52018-03-19 10:28:22 +0100509
tierno09c073e2018-04-26 13:36:48 +0200510vim_account_new_schema = {
511 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100512 "$schema": "http://json-schema.org/draft-04/schema#",
513 "type": "object",
514 "properties": {
515 "schema_version": schema_version,
516 "schema_type": schema_type,
517 "name": name_schema,
518 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200519 "vim": name_schema,
520 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200521 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100522 "vim_url": description_schema,
523 # "vim_url_admin": description_schema,
524 # "vim_tenant": name_schema,
525 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200526 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200527 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200528 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100529 "config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100530 },
garciadeblas4568a372021-03-24 09:19:48 +0100531 "required": [
532 "name",
533 "vim_url",
534 "vim_type",
535 "vim_user",
536 "vim_password",
537 "vim_tenant_name",
538 ],
539 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100540}
tierno0f98af52018-03-19 10:28:22 +0100541
tierno85807722019-12-20 14:11:35 +0000542wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200543
tierno55ba2e62018-12-11 17:22:22 +0000544wim_account_edit_schema = {
545 "title": "wim_account edit input schema",
546 "$schema": "http://json-schema.org/draft-04/schema#",
547 "type": "object",
548 "properties": {
549 "name": name_schema,
550 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000551 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200552 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000553 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100554 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000555 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100556 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000557 },
garciadeblas4568a372021-03-24 09:19:48 +0100558 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000559}
560
561wim_account_new_schema = {
562 "title": "wim_account creation input schema",
563 "$schema": "http://json-schema.org/draft-04/schema#",
564 "type": "object",
565 "properties": {
566 "schema_version": schema_version,
567 "schema_type": schema_type,
568 "name": name_schema,
569 "description": description_schema,
570 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200571 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000572 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100573 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000574 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000575 "config": {
576 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100577 "patternProperties": {".": {"not": {"type": "null"}}},
578 },
tierno55ba2e62018-12-11 17:22:22 +0000579 },
580 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100581 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000582}
tierno0f98af52018-03-19 10:28:22 +0100583
584sdn_properties = {
585 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000586 "type": {"type": "string"},
587 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100588 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000589 "password": passwd_schema,
590 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200591 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000592 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200593 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100594 "ip": ip_schema,
595 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100596 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100597}
598sdn_new_schema = {
599 "title": "sdn controller information schema",
600 "$schema": "http://json-schema.org/draft-04/schema#",
601 "type": "object",
602 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100603 "required": ["name", "type"],
604 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100605}
606sdn_edit_schema = {
607 "title": "sdn controller update information schema",
608 "$schema": "http://json-schema.org/draft-04/schema#",
609 "type": "object",
610 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200611 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100612 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100613}
614sdn_port_mapping_schema = {
615 "$schema": "http://json-schema.org/draft-04/schema#",
616 "title": "sdn port mapping information schema",
617 "type": "array",
618 "items": {
619 "type": "object",
620 "properties": {
tiernofd160572019-01-21 10:41:37 +0000621 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100622 "ports": {
623 "type": "array",
624 "items": {
625 "type": "object",
626 "properties": {
tierno42fce592018-11-02 09:23:43 +0100627 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000628 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100629 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100630 },
garciadeblas4568a372021-03-24 09:19:48 +0100631 "required": ["pci"],
632 },
633 },
tierno0f98af52018-03-19 10:28:22 +0100634 },
garciadeblas4568a372021-03-24 09:19:48 +0100635 "required": ["compute_node", "ports"],
636 },
tierno0f98af52018-03-19 10:28:22 +0100637}
638sdn_external_port_schema = {
639 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200640 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100641 "type": "object",
642 "properties": {
643 "port": {"type": "string", "minLength": 1, "maxLength": 60},
644 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100645 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100646 },
garciadeblas4568a372021-03-24 09:19:48 +0100647 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100648}
649
delacruzramofe598fe2019-10-23 18:25:11 +0200650# K8s Clusters
651k8scluster_nets_schema = {
652 "title": "k8scluster nets input schema",
653 "$schema": "http://json-schema.org/draft-04/schema#",
654 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000655 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200656 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100657 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200658}
659k8scluster_new_schema = {
660 "title": "k8scluster creation input schema",
661 "$schema": "http://json-schema.org/draft-04/schema#",
662 "type": "object",
663 "properties": {
664 "schema_version": schema_version,
665 "schema_type": schema_type,
666 "name": name_schema,
667 "description": description_schema,
668 "credentials": object_schema,
669 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200670 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200671 "k8s_version": string_schema,
672 "nets": k8scluster_nets_schema,
673 "namespace": name_schema,
674 "cni": nameshort_list_schema,
675 },
676 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100677 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200678}
679k8scluster_edit_schema = {
680 "title": "vim_account edit input schema",
681 "$schema": "http://json-schema.org/draft-04/schema#",
682 "type": "object",
683 "properties": {
684 "name": name_schema,
685 "description": description_schema,
686 "credentials": object_schema,
687 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200688 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200689 "k8s_version": string_schema,
690 "nets": k8scluster_nets_schema,
691 "namespace": name_schema,
692 "cni": nameshort_list_schema,
693 },
garciadeblas4568a372021-03-24 09:19:48 +0100694 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200695}
696
David Garciaecb41322021-03-31 19:10:46 +0200697# VCA
698vca_new_schema = {
699 "title": "vca creation input schema",
700 "$schema": "http://json-schema.org/draft-04/schema#",
701 "type": "object",
702 "properties": {
703 "schema_version": schema_version,
704 "schema_type": schema_type,
705 "name": name_schema,
706 "description": description_schema,
707 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100708 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200709 "secret": passwd_schema,
710 "cacert": long_description_schema,
711 "lxd-cloud": shortname_schema,
712 "lxd-credentials": shortname_schema,
713 "k8s-cloud": shortname_schema,
714 "k8s-credentials": shortname_schema,
715 "model-config": object_schema,
716 },
717 "required": [
718 "name",
719 "endpoints",
720 "user",
721 "secret",
722 "cacert",
723 "lxd-cloud",
724 "lxd-credentials",
725 "k8s-cloud",
726 "k8s-credentials",
727 ],
728 "additionalProperties": False,
729}
730vca_edit_schema = {
731 "title": "vca creation input schema",
732 "$schema": "http://json-schema.org/draft-04/schema#",
733 "type": "object",
734 "properties": {
735 "name": name_schema,
736 "description": description_schema,
737 "endpoints": description_list_schema,
738 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100739 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200740 "secret": passwd_schema,
741 "cacert": long_description_schema,
742 "lxd-cloud": shortname_schema,
743 "lxd-credentials": shortname_schema,
744 "k8s-cloud": shortname_schema,
745 "k8s-credentials": shortname_schema,
746 "model-config": object_schema,
747 },
748 "additionalProperties": False,
749}
750
delacruzramofe598fe2019-10-23 18:25:11 +0200751# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000752k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200753k8srepo_properties = {
754 "name": name_schema,
755 "description": description_schema,
756 "type": k8srepo_types,
757 "url": description_schema,
758}
759k8srepo_new_schema = {
760 "title": "k8scluster creation input schema",
761 "$schema": "http://json-schema.org/draft-04/schema#",
762 "type": "object",
763 "properties": k8srepo_properties,
764 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100765 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200766}
767k8srepo_edit_schema = {
768 "title": "vim_account edit input schema",
769 "$schema": "http://json-schema.org/draft-04/schema#",
770 "type": "object",
771 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100772 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200773}
774
Felipe Vicensb66b0412020-05-06 10:11:00 +0200775# OSM Repos
776osmrepo_types = {"enum": ["osm"]}
777osmrepo_properties = {
778 "name": name_schema,
779 "description": description_schema,
780 "type": osmrepo_types,
781 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100782 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200783 # "password": passwd_schema
784}
785osmrepo_new_schema = {
786 "title": "osm repo creation input schema",
787 "$schema": "http://json-schema.org/draft-04/schema#",
788 "type": "object",
789 "properties": osmrepo_properties,
790 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100791 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200792}
793osmrepo_edit_schema = {
794 "title": "osm repo edit input schema",
795 "$schema": "http://json-schema.org/draft-04/schema#",
796 "type": "object",
797 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100798 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200799}
800
tiernocb83c942018-09-24 17:28:13 +0200801# PDUs
802pdu_interface = {
803 "type": "object",
804 "properties": {
tiernofd160572019-01-21 10:41:37 +0000805 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200806 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100807 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200808 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200809 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100810 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000811 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
812 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100813 # # provide this in case SDN assist must deal with this interface
814 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000815 # "switch-port": shortname_schema,
816 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100817 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200818 },
tierno36ec8602018-11-02 17:27:11 +0100819 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100820 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200821}
tiernocb83c942018-09-24 17:28:13 +0200822pdu_new_schema = {
823 "title": "pdu creation input schema",
824 "$schema": "http://json-schema.org/draft-04/schema#",
825 "type": "object",
826 "properties": {
tiernofd160572019-01-21 10:41:37 +0000827 "name": shortname_schema,
828 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200829 "description": description_schema,
830 "shared": bool_schema,
831 "vims": nameshort_list_schema,
832 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100833 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +0200834 },
835 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +0100836 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +0200837}
tiernocb83c942018-09-24 17:28:13 +0200838pdu_edit_schema = {
839 "title": "pdu edit input schema",
840 "$schema": "http://json-schema.org/draft-04/schema#",
841 "type": "object",
842 "properties": {
tiernofd160572019-01-21 10:41:37 +0000843 "name": shortname_schema,
844 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200845 "description": description_schema,
846 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +0100847 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
848 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +0100849 "interfaces": {
850 "oneOf": [
851 array_edition_schema,
852 {"type": "array", "items": pdu_interface, "minItems": 1},
853 ]
854 },
tiernocb83c942018-09-24 17:28:13 +0200855 },
856 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +0100857 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +0200858}
859
delacruzramo271d2002019-12-02 21:00:37 +0100860# VNF PKG OPERATIONS
861vnfpkgop_new_schema = {
862 "title": "VNF PKG operation creation input schema",
863 "$schema": "http://json-schema.org/draft-04/schema#",
864 "type": "object",
865 "properties": {
866 "lcmOperationType": string_schema,
867 "vnfPkgId": id_schema,
868 "kdu_name": name_schema,
869 "primitive": name_schema,
870 "primitive_params": {"type": "object"},
871 },
garciadeblas4568a372021-03-24 09:19:48 +0100872 "required": [
873 "lcmOperationType",
874 "vnfPkgId",
875 "kdu_name",
876 "primitive",
877 "primitive_params",
878 ],
879 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +0100880}
881
tiernocb83c942018-09-24 17:28:13 +0200882# USERS
tiernocf042d32019-06-13 09:06:40 +0000883project_role_mappings = {
884 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100885 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +0000886 "type": "array",
887 "items": {
888 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100889 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000890 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +0100891 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100892 },
garciadeblas4568a372021-03-24 09:19:48 +0100893 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +0000894}
895project_role_mappings_optional = {
896 "title": "list of projects/roles or projects only",
897 "$schema": "http://json-schema.org/draft-04/schema#",
898 "type": "array",
899 "items": {
900 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100901 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +0000902 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +0100903 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +0000904 },
garciadeblas4568a372021-03-24 09:19:48 +0100905 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100906}
tiernocd54a4a2018-09-12 16:40:35 +0200907user_new_schema = {
908 "$schema": "http://json-schema.org/draft-04/schema#",
909 "title": "New user schema",
910 "type": "object",
911 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +0100912 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +0000913 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200914 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200915 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +0000916 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +0200917 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100918 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +0100919 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200920}
921user_edit_schema = {
922 "$schema": "http://json-schema.org/draft-04/schema#",
923 "title": "User edit schema for administrators",
924 "type": "object",
925 "properties": {
926 "password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100927 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +0100928 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +0000929 "project_role_mappings": project_role_mappings,
930 "add_project_role_mappings": project_role_mappings,
931 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +0200932 },
933 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100934 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200935}
936
937# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +0100938topics_with_quota = [
939 "vnfds",
940 "nsds",
941 "slice_templates",
942 "pduds",
943 "ns_instances",
944 "slice_instances",
945 "vim_accounts",
946 "wim_accounts",
947 "sdn_controllers",
948 "k8sclusters",
949 "vca",
950 "k8srepos",
951 "osmrepos",
952 "ns_subscriptions",
953]
tiernocd54a4a2018-09-12 16:40:35 +0200954project_new_schema = {
955 "$schema": "http://json-schema.org/draft-04/schema#",
956 "title": "New project schema for administrators",
957 "type": "object",
958 "properties": {
tiernofd160572019-01-21 10:41:37 +0000959 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200960 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +0000961 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +0200962 "quotas": {
963 "type": "object",
964 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +0100965 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +0200966 },
tiernocd54a4a2018-09-12 16:40:35 +0200967 },
968 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +0100969 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200970}
971project_edit_schema = {
972 "$schema": "http://json-schema.org/draft-04/schema#",
973 "title": "Project edit schema for administrators",
974 "type": "object",
975 "properties": {
976 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100977 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +0200978 "quotas": {
979 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100980 "properties": {
981 topic: {"oneOf": [integer0_schema, null_schema]}
982 for topic in topics_with_quota
983 },
984 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +0200985 },
tiernocd54a4a2018-09-12 16:40:35 +0200986 },
987 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +0100988 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +0200989}
990
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100991# ROLES
992roles_new_schema = {
993 "$schema": "http://json-schema.org/draft-04/schema#",
994 "title": "New role schema for administrators",
995 "type": "object",
996 "properties": {
997 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +0000998 "permissions": {
999 "type": "object",
1000 "patternProperties": {
1001 ".": bool_schema,
1002 },
1003 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001004 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001005 },
tierno1f029d82019-06-13 22:37:04 +00001006 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001007 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001008}
1009roles_edit_schema = {
1010 "$schema": "http://json-schema.org/draft-04/schema#",
1011 "title": "Roles edit schema for administrators",
1012 "type": "object",
1013 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001014 "name": shortname_schema,
1015 "permissions": {
1016 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001017 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001018 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001019 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001020 },
tierno1f029d82019-06-13 22:37:04 +00001021 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001022 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001023}
1024
tiernocd54a4a2018-09-12 16:40:35 +02001025# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001026
1027nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001028 "users": user_new_schema,
1029 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001030 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001031 "sdns": sdn_new_schema,
1032 "ns_instantiate": ns_instantiate,
1033 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001034 "ns_scale": ns_scale,
1035 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001036}
1037
1038nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001039 "users": user_edit_schema,
1040 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001041 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001042 "sdns": sdn_edit_schema,
1043 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001044}
1045
Felipe Vicens07f31722018-10-29 15:16:44 +01001046# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001047nsi_subnet_instantiate = deepcopy(ns_instantiate)
1048nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1049nsi_subnet_instantiate["properties"]["id"] = name_schema
1050del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001051
1052nsi_vld_instantiate = {
1053 "title": "netslice vld instantiation params input schema",
1054 "$schema": "http://json-schema.org/draft-04/schema#",
1055 "type": "object",
1056 "properties": {
1057 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001058 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1059 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001060 "ip-profile": object_schema,
1061 },
delacruzramoc061f562019-04-05 11:00:02 +02001062 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001063 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001064}
1065
Felipe Vicens07f31722018-10-29 15:16:44 +01001066nsi_instantiate = {
1067 "title": "netslice action instantiate input schema",
1068 "$schema": "http://json-schema.org/draft-04/schema#",
1069 "type": "object",
1070 "properties": {
1071 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001072 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001073 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001074 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001075 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001076 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001077 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001078 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001079 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001080 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001081 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001082 "type": "array",
1083 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001084 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001085 },
garciadeblas4568a372021-03-24 09:19:48 +01001086 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001087 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001088 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001089 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001090}
1091
garciadeblas4568a372021-03-24 09:19:48 +01001092nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001093
garciadeblas4568a372021-03-24 09:19:48 +01001094nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001095
preethika.p329b8182020-04-22 12:25:39 +05301096nsinstancesubscriptionfilter_schema = {
1097 "title": "instance identifier schema",
1098 "$schema": "http://json-schema.org/draft-07/schema#",
1099 "type": "object",
1100 "properties": {
1101 "nsdIds": {"type": "array"},
1102 "vnfdIds": {"type": "array"},
1103 "pnfdIds": {"type": "array"},
1104 "nsInstanceIds": {"type": "array"},
1105 "nsInstanceNames": {"type": "array"},
1106 },
1107}
1108
1109nslcmsub_schema = {
1110 "title": "nslcmsubscription input schema",
1111 "$schema": "http://json-schema.org/draft-07/schema#",
1112 "type": "object",
1113 "properties": {
1114 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1115 "notificationTypes": {
1116 "type": "array",
1117 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001118 "enum": [
1119 "NsLcmOperationOccurrenceNotification",
1120 "NsChangeNotification",
1121 "NsIdentifierCreationNotification",
1122 "NsIdentifierDeletionNotification",
1123 ]
1124 },
preethika.p329b8182020-04-22 12:25:39 +05301125 },
1126 "operationTypes": {
1127 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001128 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301129 },
1130 "operationStates": {
1131 "type": "array",
1132 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001133 "enum": [
1134 "PROCESSING",
1135 "COMPLETED",
1136 "PARTIALLY_COMPLETED",
1137 "FAILED",
1138 "FAILED_TEMP",
1139 "ROLLING_BACK",
1140 "ROLLED_BACK",
1141 ]
1142 },
preethika.p329b8182020-04-22 12:25:39 +05301143 },
garciadeblas4568a372021-03-24 09:19:48 +01001144 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301145 "lcmOpNameImpactingNsComponent": {
1146 "type": "array",
1147 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001148 "enum": [
1149 "VNF_INSTANTIATE",
1150 "VNF_SCALE",
1151 "VNF_SCALE_TO_LEVEL",
1152 "VNF_CHANGE_FLAVOUR",
1153 "VNF_TERMINATE",
1154 "VNF_HEAL",
1155 "VNF_OPERATE",
1156 "VNF_CHANGE_EXT_CONN",
1157 "VNF_MODIFY_INFO",
1158 "NS_INSTANTIATE",
1159 "NS_SCALE",
1160 "NS_UPDATE",
1161 "NS_TERMINATE",
1162 "NS_HEAL",
1163 ]
1164 },
preethika.p329b8182020-04-22 12:25:39 +05301165 },
1166 "lcmOpOccStatusImpactingNsComponent": {
1167 "type": "array",
1168 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001169 "enum": [
1170 "START",
1171 "COMPLETED",
1172 "PARTIALLY_COMPLETED",
1173 "FAILED",
1174 "ROLLED_BACK",
1175 ]
1176 },
preethika.p329b8182020-04-22 12:25:39 +05301177 },
1178 },
1179 "allOf": [
1180 {
1181 "if": {
1182 "properties": {
1183 "notificationTypes": {
1184 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1185 }
1186 },
1187 },
1188 "then": {
1189 "anyOf": [
1190 {"required": ["operationTypes"]},
1191 {"required": ["operationStates"]},
1192 ]
garciadeblas4568a372021-03-24 09:19:48 +01001193 },
preethika.p329b8182020-04-22 12:25:39 +05301194 },
1195 {
1196 "if": {
1197 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001198 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301199 },
1200 },
1201 "then": {
1202 "anyOf": [
1203 {"required": ["nsComponentTypes"]},
1204 {"required": ["lcmOpNameImpactingNsComponent"]},
1205 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1206 ]
garciadeblas4568a372021-03-24 09:19:48 +01001207 },
1208 },
1209 ],
preethika.p329b8182020-04-22 12:25:39 +05301210}
1211
1212authentication_schema = {
1213 "title": "authentication schema for subscription",
1214 "$schema": "http://json-schema.org/draft-07/schema#",
1215 "type": "object",
1216 "properties": {
1217 "authType": {"enum": ["basic"]},
1218 "paramsBasic": {
1219 "type": "object",
1220 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001221 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301222 "password": passwd_schema,
1223 },
1224 },
1225 },
1226}
1227
1228subscription = {
1229 "title": "subscription input schema",
1230 "$schema": "http://json-schema.org/draft-07/schema#",
1231 "type": "object",
1232 "properties": {
1233 "filter": nslcmsub_schema,
1234 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001235 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301236 },
1237 "required": ["CallbackUri"],
1238}
1239
tierno0f98af52018-03-19 10:28:22 +01001240
1241class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001242 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1243 self.http_code = http_code
1244 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001245
1246
tiernob24258a2018-10-04 18:39:49 +02001247def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001248 """
tiernocd54a4a2018-09-12 16:40:35 +02001249 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001250 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001251 :param schema_to_use: jsonschema to test
1252 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001253 """
1254 try:
tierno0f98af52018-03-19 10:28:22 +01001255 if schema_to_use:
1256 js_v(indata, schema_to_use)
1257 return None
1258 except js_e.ValidationError as e:
1259 if e.path:
tierno0da52252018-06-27 15:47:22 +02001260 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001261 else:
1262 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001263 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001264 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001265 raise ValidationError(
1266 "Bad json schema {}".format(schema_to_use),
1267 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1268 )
delacruzramoc061f562019-04-05 11:00:02 +02001269
1270
1271def is_valid_uuid(x):
1272 """
1273 Test for a valid UUID
1274 :param x: string to test
1275 :return: True if x is a valid uuid, False otherwise
1276 """
1277 try:
1278 if UUID(x):
1279 return True
tiernobdebce92019-07-01 15:36:49 +00001280 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001281 return False