blob: 6ed6fbab3fd909cc208628d36f2b783ed02ea8f0 [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
govindarajul519da482022-04-29 19:05:22 +0530616ns_verticalscale = {
617 "title": "vertial scale input schema",
618 "$schema": "http://json-schema.org/draft-04/schema#",
619 "type": "object",
620 "properties": {
621 "lcmOperationType": string_schema,
622 "nsInstanceId": id_schema,
623 "vnfInstanceId": id_schema,
624 "migrateToHost": string_schema,
625 "vdu": {
626 "type": "object",
627 "properties": {
628 "vduId": name_schema,
629 "vduCountIndex": integer0_schema,
630 },
631 "required": ["vduId"],
632 "additionalProperties": False,
633 },
634 },
635 "required": ["vnfInstanceId"],
636 "additionalProperties": False
637}
638
tierno0f98af52018-03-19 10:28:22 +0100639schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000640schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000641vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200642
tierno09c073e2018-04-26 13:36:48 +0200643vim_account_edit_schema = {
644 "title": "vim_account edit input schema",
645 "$schema": "http://json-schema.org/draft-04/schema#",
646 "type": "object",
647 "properties": {
648 "name": name_schema,
649 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200650 "vim": name_schema,
651 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200652 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200653 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200654 # "vim_url_admin": description_schema,
655 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200656 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200657 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200658 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200659 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100660 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000661 "prometheus-config": {"type": "object"},
tierno09c073e2018-04-26 13:36:48 +0200662 },
garciadeblas4568a372021-03-24 09:19:48 +0100663 "additionalProperties": False,
tierno09c073e2018-04-26 13:36:48 +0200664}
tierno0f98af52018-03-19 10:28:22 +0100665
tierno09c073e2018-04-26 13:36:48 +0200666vim_account_new_schema = {
667 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100668 "$schema": "http://json-schema.org/draft-04/schema#",
669 "type": "object",
670 "properties": {
671 "schema_version": schema_version,
672 "schema_type": schema_type,
673 "name": name_schema,
674 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200675 "vim": name_schema,
676 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200677 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100678 "vim_url": description_schema,
679 # "vim_url_admin": description_schema,
680 # "vim_tenant": name_schema,
681 "vim_tenant_name": name_schema,
sousaeduf2feafd2021-07-12 10:21:06 +0200682 "vim_user": string_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200683 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200684 "vca": id_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100685 "config": {"type": "object"},
vegall5c59aab2022-04-27 15:31:49 +0000686 "prometheus-config": {"type": "object"},
tierno0f98af52018-03-19 10:28:22 +0100687 },
garciadeblas4568a372021-03-24 09:19:48 +0100688 "required": [
689 "name",
690 "vim_url",
691 "vim_type",
692 "vim_user",
693 "vim_password",
694 "vim_tenant_name",
695 ],
696 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100697}
tierno0f98af52018-03-19 10:28:22 +0100698
tierno85807722019-12-20 14:11:35 +0000699wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200700
tierno55ba2e62018-12-11 17:22:22 +0000701wim_account_edit_schema = {
702 "title": "wim_account edit input schema",
703 "$schema": "http://json-schema.org/draft-04/schema#",
704 "type": "object",
705 "properties": {
706 "name": name_schema,
707 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000708 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200709 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000710 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100711 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000712 "password": passwd_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100713 "config": {"type": "object"},
tierno55ba2e62018-12-11 17:22:22 +0000714 },
garciadeblas4568a372021-03-24 09:19:48 +0100715 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000716}
717
718wim_account_new_schema = {
719 "title": "wim_account creation input schema",
720 "$schema": "http://json-schema.org/draft-04/schema#",
721 "type": "object",
722 "properties": {
723 "schema_version": schema_version,
724 "schema_type": schema_type,
725 "name": name_schema,
726 "description": description_schema,
727 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200728 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000729 "wim_url": description_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100730 "user": string_schema,
tierno55ba2e62018-12-11 17:22:22 +0000731 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000732 "config": {
733 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +0100734 "patternProperties": {".": {"not": {"type": "null"}}},
735 },
tierno55ba2e62018-12-11 17:22:22 +0000736 },
737 "required": ["name", "wim_url", "wim_type"],
garciadeblas4568a372021-03-24 09:19:48 +0100738 "additionalProperties": False,
tierno55ba2e62018-12-11 17:22:22 +0000739}
tierno0f98af52018-03-19 10:28:22 +0100740
741sdn_properties = {
742 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000743 "type": {"type": "string"},
744 "url": {"type": "string"},
sousaedu80b6fed2021-10-07 15:17:32 +0100745 "user": string_schema,
tierno7adaeb02019-12-17 16:46:12 +0000746 "password": passwd_schema,
747 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200748 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000749 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200750 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100751 "ip": ip_schema,
752 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100753 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100754}
755sdn_new_schema = {
756 "title": "sdn controller information schema",
757 "$schema": "http://json-schema.org/draft-04/schema#",
758 "type": "object",
759 "properties": sdn_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100760 "required": ["name", "type"],
761 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100762}
763sdn_edit_schema = {
764 "title": "sdn controller update information schema",
765 "$schema": "http://json-schema.org/draft-04/schema#",
766 "type": "object",
767 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200768 # "required": ["name", "port", 'ip', 'dpid', 'type'],
garciadeblas4568a372021-03-24 09:19:48 +0100769 "additionalProperties": False,
tierno0f98af52018-03-19 10:28:22 +0100770}
771sdn_port_mapping_schema = {
772 "$schema": "http://json-schema.org/draft-04/schema#",
773 "title": "sdn port mapping information schema",
774 "type": "array",
775 "items": {
776 "type": "object",
777 "properties": {
tiernofd160572019-01-21 10:41:37 +0000778 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100779 "ports": {
780 "type": "array",
781 "items": {
782 "type": "object",
783 "properties": {
tierno42fce592018-11-02 09:23:43 +0100784 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000785 "switch_port": shortname_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100786 "switch_mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100787 },
garciadeblas4568a372021-03-24 09:19:48 +0100788 "required": ["pci"],
789 },
790 },
tierno0f98af52018-03-19 10:28:22 +0100791 },
garciadeblas4568a372021-03-24 09:19:48 +0100792 "required": ["compute_node", "ports"],
793 },
tierno0f98af52018-03-19 10:28:22 +0100794}
795sdn_external_port_schema = {
796 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200797 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100798 "type": "object",
799 "properties": {
800 "port": {"type": "string", "minLength": 1, "maxLength": 60},
801 "vlan": vlan_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100802 "mac": mac_schema,
tierno0f98af52018-03-19 10:28:22 +0100803 },
garciadeblas4568a372021-03-24 09:19:48 +0100804 "required": ["port"],
tierno0f98af52018-03-19 10:28:22 +0100805}
806
delacruzramofe598fe2019-10-23 18:25:11 +0200807# K8s Clusters
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500808k8scluster_deploy_method_schema = {
809 "$schema": "http://json-schema.org/draft-04/schema#",
810 "title": "Deployment methods for K8s cluster",
811 "type": "object",
812 "properties": {
813 "helm-chart": {"type": "boolean"},
814 "juju-bundle": {"type": "boolean"},
815 "helm-chart-v3": {"type": "boolean"},
816 },
817 "additionalProperties": False,
818 "minProperties": 3,
819}
delacruzramofe598fe2019-10-23 18:25:11 +0200820k8scluster_nets_schema = {
821 "title": "k8scluster nets input schema",
822 "$schema": "http://json-schema.org/draft-04/schema#",
823 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000824 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200825 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +0100826 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200827}
828k8scluster_new_schema = {
829 "title": "k8scluster creation input schema",
830 "$schema": "http://json-schema.org/draft-04/schema#",
831 "type": "object",
832 "properties": {
833 "schema_version": schema_version,
834 "schema_type": schema_type,
835 "name": name_schema,
836 "description": description_schema,
837 "credentials": object_schema,
838 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200839 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200840 "k8s_version": string_schema,
841 "nets": k8scluster_nets_schema,
Gabriel Cuba50e815b2022-03-22 14:01:26 -0500842 "deployment_methods": k8scluster_deploy_method_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200843 "namespace": name_schema,
844 "cni": nameshort_list_schema,
845 },
846 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
garciadeblas4568a372021-03-24 09:19:48 +0100847 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200848}
849k8scluster_edit_schema = {
850 "title": "vim_account edit input schema",
851 "$schema": "http://json-schema.org/draft-04/schema#",
852 "type": "object",
853 "properties": {
854 "name": name_schema,
855 "description": description_schema,
856 "credentials": object_schema,
857 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200858 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200859 "k8s_version": string_schema,
860 "nets": k8scluster_nets_schema,
861 "namespace": name_schema,
862 "cni": nameshort_list_schema,
863 },
garciadeblas4568a372021-03-24 09:19:48 +0100864 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200865}
866
David Garciaecb41322021-03-31 19:10:46 +0200867# VCA
868vca_new_schema = {
869 "title": "vca creation input schema",
870 "$schema": "http://json-schema.org/draft-04/schema#",
871 "type": "object",
872 "properties": {
873 "schema_version": schema_version,
874 "schema_type": schema_type,
875 "name": name_schema,
876 "description": description_schema,
877 "endpoints": description_list_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100878 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200879 "secret": passwd_schema,
880 "cacert": long_description_schema,
881 "lxd-cloud": shortname_schema,
882 "lxd-credentials": shortname_schema,
883 "k8s-cloud": shortname_schema,
884 "k8s-credentials": shortname_schema,
885 "model-config": object_schema,
886 },
887 "required": [
888 "name",
889 "endpoints",
890 "user",
891 "secret",
892 "cacert",
893 "lxd-cloud",
894 "lxd-credentials",
895 "k8s-cloud",
896 "k8s-credentials",
897 ],
898 "additionalProperties": False,
899}
900vca_edit_schema = {
901 "title": "vca creation input schema",
902 "$schema": "http://json-schema.org/draft-04/schema#",
903 "type": "object",
904 "properties": {
905 "name": name_schema,
906 "description": description_schema,
907 "endpoints": description_list_schema,
908 "port": integer1_schema,
sousaedu80b6fed2021-10-07 15:17:32 +0100909 "user": string_schema,
David Garciaecb41322021-03-31 19:10:46 +0200910 "secret": passwd_schema,
911 "cacert": long_description_schema,
912 "lxd-cloud": shortname_schema,
913 "lxd-credentials": shortname_schema,
914 "k8s-cloud": shortname_schema,
915 "k8s-credentials": shortname_schema,
916 "model-config": object_schema,
917 },
918 "additionalProperties": False,
919}
920
delacruzramofe598fe2019-10-23 18:25:11 +0200921# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000922k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200923k8srepo_properties = {
924 "name": name_schema,
925 "description": description_schema,
926 "type": k8srepo_types,
927 "url": description_schema,
928}
929k8srepo_new_schema = {
930 "title": "k8scluster creation input schema",
931 "$schema": "http://json-schema.org/draft-04/schema#",
932 "type": "object",
933 "properties": k8srepo_properties,
934 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100935 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200936}
937k8srepo_edit_schema = {
938 "title": "vim_account edit input schema",
939 "$schema": "http://json-schema.org/draft-04/schema#",
940 "type": "object",
941 "properties": k8srepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100942 "additionalProperties": False,
delacruzramofe598fe2019-10-23 18:25:11 +0200943}
944
Felipe Vicensb66b0412020-05-06 10:11:00 +0200945# OSM Repos
946osmrepo_types = {"enum": ["osm"]}
947osmrepo_properties = {
948 "name": name_schema,
949 "description": description_schema,
950 "type": osmrepo_types,
951 "url": description_schema
sousaedu80b6fed2021-10-07 15:17:32 +0100952 # "user": string_schema,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200953 # "password": passwd_schema
954}
955osmrepo_new_schema = {
956 "title": "osm repo creation input schema",
957 "$schema": "http://json-schema.org/draft-04/schema#",
958 "type": "object",
959 "properties": osmrepo_properties,
960 "required": ["name", "type", "url"],
garciadeblas4568a372021-03-24 09:19:48 +0100961 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200962}
963osmrepo_edit_schema = {
964 "title": "osm repo edit input schema",
965 "$schema": "http://json-schema.org/draft-04/schema#",
966 "type": "object",
967 "properties": osmrepo_properties,
garciadeblas4568a372021-03-24 09:19:48 +0100968 "additionalProperties": False,
Felipe Vicensb66b0412020-05-06 10:11:00 +0200969}
970
tiernocb83c942018-09-24 17:28:13 +0200971# PDUs
972pdu_interface = {
973 "type": "object",
974 "properties": {
tiernofd160572019-01-21 10:41:37 +0000975 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200976 "mgmt": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +0100977 "type": {"enum": ["overlay", "underlay"]},
garciadeblas1a01e1f2021-10-26 17:27:35 +0200978 "ip-address": {"oneOf": [ip_schema, ipv6_schema]},
tiernocb83c942018-09-24 17:28:13 +0200979 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100980 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000981 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
982 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100983 # # provide this in case SDN assist must deal with this interface
984 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000985 # "switch-port": shortname_schema,
986 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100987 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200988 },
tierno36ec8602018-11-02 17:27:11 +0100989 "required": ["name", "mgmt", "ip-address"],
garciadeblas4568a372021-03-24 09:19:48 +0100990 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +0200991}
tiernocb83c942018-09-24 17:28:13 +0200992pdu_new_schema = {
993 "title": "pdu creation input schema",
994 "$schema": "http://json-schema.org/draft-04/schema#",
995 "type": "object",
996 "properties": {
tiernofd160572019-01-21 10:41:37 +0000997 "name": shortname_schema,
998 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200999 "description": description_schema,
1000 "shared": bool_schema,
1001 "vims": nameshort_list_schema,
1002 "vim_accounts": nameshort_list_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001003 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1},
tiernocb83c942018-09-24 17:28:13 +02001004 },
1005 "required": ["name", "type", "interfaces"],
garciadeblas4568a372021-03-24 09:19:48 +01001006 "additionalProperties": False,
tiernocb83c942018-09-24 17:28:13 +02001007}
tiernocb83c942018-09-24 17:28:13 +02001008pdu_edit_schema = {
1009 "title": "pdu edit input schema",
1010 "$schema": "http://json-schema.org/draft-04/schema#",
1011 "type": "object",
1012 "properties": {
tiernofd160572019-01-21 10:41:37 +00001013 "name": shortname_schema,
1014 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +02001015 "description": description_schema,
1016 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +01001017 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
1018 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
garciadeblas4568a372021-03-24 09:19:48 +01001019 "interfaces": {
1020 "oneOf": [
1021 array_edition_schema,
1022 {"type": "array", "items": pdu_interface, "minItems": 1},
1023 ]
1024 },
tiernocb83c942018-09-24 17:28:13 +02001025 },
1026 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001027 "minProperties": 1,
tiernocb83c942018-09-24 17:28:13 +02001028}
1029
delacruzramo271d2002019-12-02 21:00:37 +01001030# VNF PKG OPERATIONS
1031vnfpkgop_new_schema = {
1032 "title": "VNF PKG operation creation input schema",
1033 "$schema": "http://json-schema.org/draft-04/schema#",
1034 "type": "object",
1035 "properties": {
1036 "lcmOperationType": string_schema,
1037 "vnfPkgId": id_schema,
1038 "kdu_name": name_schema,
1039 "primitive": name_schema,
1040 "primitive_params": {"type": "object"},
1041 },
garciadeblas4568a372021-03-24 09:19:48 +01001042 "required": [
1043 "lcmOperationType",
1044 "vnfPkgId",
1045 "kdu_name",
1046 "primitive",
1047 "primitive_params",
1048 ],
1049 "additionalProperties": False,
delacruzramo271d2002019-12-02 21:00:37 +01001050}
1051
tiernocb83c942018-09-24 17:28:13 +02001052# USERS
tiernocf042d32019-06-13 09:06:40 +00001053project_role_mappings = {
1054 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001055 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +00001056 "type": "array",
1057 "items": {
1058 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001059 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001060 "required": ["project", "role"],
garciadeblas4568a372021-03-24 09:19:48 +01001061 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001062 },
garciadeblas4568a372021-03-24 09:19:48 +01001063 "minItems": 1,
tiernocf042d32019-06-13 09:06:40 +00001064}
1065project_role_mappings_optional = {
1066 "title": "list of projects/roles or projects only",
1067 "$schema": "http://json-schema.org/draft-04/schema#",
1068 "type": "array",
1069 "items": {
1070 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001071 "properties": {"project": shortname_schema, "role": shortname_schema},
tiernocf042d32019-06-13 09:06:40 +00001072 "required": ["project"],
garciadeblas4568a372021-03-24 09:19:48 +01001073 "additionalProperties": False,
tiernocf042d32019-06-13 09:06:40 +00001074 },
garciadeblas4568a372021-03-24 09:19:48 +01001075 "minItems": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001076}
tiernocd54a4a2018-09-12 16:40:35 +02001077user_new_schema = {
1078 "$schema": "http://json-schema.org/draft-04/schema#",
1079 "title": "New user schema",
1080 "type": "object",
1081 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001082 "username": string_schema,
tiernoad6d5332020-02-19 14:29:49 +00001083 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001084 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +02001085 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +00001086 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +02001087 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001088 "required": ["username", "password"],
garciadeblas4568a372021-03-24 09:19:48 +01001089 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001090}
1091user_edit_schema = {
1092 "$schema": "http://json-schema.org/draft-04/schema#",
1093 "title": "User edit schema for administrators",
1094 "type": "object",
1095 "properties": {
1096 "password": passwd_schema,
selvi.ja9a1fc82022-04-04 06:54:30 +00001097 "old_password": passwd_schema,
sousaedu80b6fed2021-10-07 15:17:32 +01001098 "username": string_schema, # To allow User Name modification
garciadeblas4568a372021-03-24 09:19:48 +01001099 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]},
tiernocf042d32019-06-13 09:06:40 +00001100 "project_role_mappings": project_role_mappings,
1101 "add_project_role_mappings": project_role_mappings,
1102 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +02001103 },
1104 "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001105 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001106}
1107
1108# PROJECTS
garciadeblas4568a372021-03-24 09:19:48 +01001109topics_with_quota = [
1110 "vnfds",
1111 "nsds",
1112 "slice_templates",
1113 "pduds",
1114 "ns_instances",
1115 "slice_instances",
1116 "vim_accounts",
1117 "wim_accounts",
1118 "sdn_controllers",
1119 "k8sclusters",
1120 "vca",
1121 "k8srepos",
1122 "osmrepos",
1123 "ns_subscriptions",
1124]
tiernocd54a4a2018-09-12 16:40:35 +02001125project_new_schema = {
1126 "$schema": "http://json-schema.org/draft-04/schema#",
1127 "title": "New project schema for administrators",
1128 "type": "object",
1129 "properties": {
tiernofd160572019-01-21 10:41:37 +00001130 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +02001131 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +00001132 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +02001133 "quotas": {
1134 "type": "object",
1135 "properties": {topic: integer0_schema for topic in topics_with_quota},
garciadeblas4568a372021-03-24 09:19:48 +01001136 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001137 },
tiernocd54a4a2018-09-12 16:40:35 +02001138 },
1139 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001140 "additionalProperties": False,
tiernocd54a4a2018-09-12 16:40:35 +02001141}
1142project_edit_schema = {
1143 "$schema": "http://json-schema.org/draft-04/schema#",
1144 "title": "Project edit schema for administrators",
1145 "type": "object",
1146 "properties": {
1147 "admin": bool_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001148 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +02001149 "quotas": {
1150 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001151 "properties": {
1152 topic: {"oneOf": [integer0_schema, null_schema]}
1153 for topic in topics_with_quota
1154 },
1155 "additionalProperties": False,
delacruzramo32bab472019-09-13 12:24:22 +02001156 },
tiernocd54a4a2018-09-12 16:40:35 +02001157 },
1158 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001159 "minProperties": 1,
tiernocd54a4a2018-09-12 16:40:35 +02001160}
1161
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001162# ROLES
1163roles_new_schema = {
1164 "$schema": "http://json-schema.org/draft-04/schema#",
1165 "title": "New role schema for administrators",
1166 "type": "object",
1167 "properties": {
1168 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +00001169 "permissions": {
1170 "type": "object",
1171 "patternProperties": {
1172 ".": bool_schema,
1173 },
1174 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001175 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001176 },
tierno1f029d82019-06-13 22:37:04 +00001177 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001178 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001179}
1180roles_edit_schema = {
1181 "$schema": "http://json-schema.org/draft-04/schema#",
1182 "title": "Roles edit schema for administrators",
1183 "type": "object",
1184 "properties": {
tierno1f029d82019-06-13 22:37:04 +00001185 "name": shortname_schema,
1186 "permissions": {
1187 "type": "object",
garciadeblas4568a372021-03-24 09:19:48 +01001188 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}},
tierno1f029d82019-06-13 22:37:04 +00001189 # "minProperties": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001190 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001191 },
tierno1f029d82019-06-13 22:37:04 +00001192 "additionalProperties": False,
garciadeblas4568a372021-03-24 09:19:48 +01001193 "minProperties": 1,
Eduardo Sousa5c01e192019-05-08 02:35:47 +01001194}
1195
tiernocd54a4a2018-09-12 16:40:35 +02001196# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +01001197
1198nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001199 "users": user_new_schema,
1200 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +02001201 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +02001202 "sdns": sdn_new_schema,
1203 "ns_instantiate": ns_instantiate,
1204 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +02001205 "ns_scale": ns_scale,
aticig544a2ae2022-04-05 09:00:17 +03001206 "ns_update": ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +01001207 "ns_heal": ns_heal,
tiernocb83c942018-09-24 17:28:13 +02001208 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +01001209}
1210
1211nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +02001212 "users": user_edit_schema,
1213 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +02001214 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +02001215 "sdns": sdn_edit_schema,
1216 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +01001217}
1218
Felipe Vicens07f31722018-10-29 15:16:44 +01001219# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +00001220nsi_subnet_instantiate = deepcopy(ns_instantiate)
1221nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
1222nsi_subnet_instantiate["properties"]["id"] = name_schema
1223del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001224
1225nsi_vld_instantiate = {
1226 "title": "netslice vld instantiation params input schema",
1227 "$schema": "http://json-schema.org/draft-04/schema#",
1228 "type": "object",
1229 "properties": {
1230 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001231 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1232 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001233 "ip-profile": object_schema,
1234 },
delacruzramoc061f562019-04-05 11:00:02 +02001235 "required": ["name"],
garciadeblas4568a372021-03-24 09:19:48 +01001236 "additionalProperties": False,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001237}
1238
Felipe Vicens07f31722018-10-29 15:16:44 +01001239nsi_instantiate = {
1240 "title": "netslice action instantiate input schema",
1241 "$schema": "http://json-schema.org/draft-04/schema#",
1242 "type": "object",
1243 "properties": {
1244 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001245 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001246 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001247 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001248 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001249 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001250 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001251 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001252 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001253 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001254 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001255 "type": "array",
1256 "minItems": 1,
garciadeblas4568a372021-03-24 09:19:48 +01001257 "items": nsi_subnet_instantiate,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001258 },
garciadeblas4568a372021-03-24 09:19:48 +01001259 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate},
Felipe Vicens07f31722018-10-29 15:16:44 +01001260 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001261 "required": ["nsiName", "nstId", "vimAccountId"],
garciadeblas4568a372021-03-24 09:19:48 +01001262 "additionalProperties": False,
Felipe Vicens07f31722018-10-29 15:16:44 +01001263}
1264
garciadeblas4568a372021-03-24 09:19:48 +01001265nsi_action = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001266
garciadeblas4568a372021-03-24 09:19:48 +01001267nsi_terminate = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001268
preethika.p329b8182020-04-22 12:25:39 +05301269nsinstancesubscriptionfilter_schema = {
1270 "title": "instance identifier schema",
1271 "$schema": "http://json-schema.org/draft-07/schema#",
1272 "type": "object",
1273 "properties": {
1274 "nsdIds": {"type": "array"},
1275 "vnfdIds": {"type": "array"},
1276 "pnfdIds": {"type": "array"},
1277 "nsInstanceIds": {"type": "array"},
1278 "nsInstanceNames": {"type": "array"},
1279 },
1280}
1281
1282nslcmsub_schema = {
1283 "title": "nslcmsubscription input schema",
1284 "$schema": "http://json-schema.org/draft-07/schema#",
1285 "type": "object",
1286 "properties": {
1287 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1288 "notificationTypes": {
1289 "type": "array",
1290 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001291 "enum": [
1292 "NsLcmOperationOccurrenceNotification",
1293 "NsChangeNotification",
1294 "NsIdentifierCreationNotification",
1295 "NsIdentifierDeletionNotification",
1296 ]
1297 },
preethika.p329b8182020-04-22 12:25:39 +05301298 },
1299 "operationTypes": {
1300 "type": "array",
garciadeblas4568a372021-03-24 09:19:48 +01001301 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]},
preethika.p329b8182020-04-22 12:25:39 +05301302 },
1303 "operationStates": {
1304 "type": "array",
1305 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001306 "enum": [
1307 "PROCESSING",
1308 "COMPLETED",
1309 "PARTIALLY_COMPLETED",
1310 "FAILED",
1311 "FAILED_TEMP",
1312 "ROLLING_BACK",
1313 "ROLLED_BACK",
1314 ]
1315 },
preethika.p329b8182020-04-22 12:25:39 +05301316 },
garciadeblas4568a372021-03-24 09:19:48 +01001317 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}},
preethika.p329b8182020-04-22 12:25:39 +05301318 "lcmOpNameImpactingNsComponent": {
1319 "type": "array",
1320 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001321 "enum": [
1322 "VNF_INSTANTIATE",
1323 "VNF_SCALE",
1324 "VNF_SCALE_TO_LEVEL",
1325 "VNF_CHANGE_FLAVOUR",
1326 "VNF_TERMINATE",
1327 "VNF_HEAL",
1328 "VNF_OPERATE",
1329 "VNF_CHANGE_EXT_CONN",
1330 "VNF_MODIFY_INFO",
1331 "NS_INSTANTIATE",
1332 "NS_SCALE",
1333 "NS_UPDATE",
1334 "NS_TERMINATE",
1335 "NS_HEAL",
1336 ]
1337 },
preethika.p329b8182020-04-22 12:25:39 +05301338 },
1339 "lcmOpOccStatusImpactingNsComponent": {
1340 "type": "array",
1341 "items": {
garciadeblas4568a372021-03-24 09:19:48 +01001342 "enum": [
1343 "START",
1344 "COMPLETED",
1345 "PARTIALLY_COMPLETED",
1346 "FAILED",
1347 "ROLLED_BACK",
1348 ]
1349 },
preethika.p329b8182020-04-22 12:25:39 +05301350 },
1351 },
1352 "allOf": [
1353 {
1354 "if": {
1355 "properties": {
1356 "notificationTypes": {
1357 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1358 }
1359 },
1360 },
1361 "then": {
1362 "anyOf": [
1363 {"required": ["operationTypes"]},
1364 {"required": ["operationStates"]},
1365 ]
garciadeblas4568a372021-03-24 09:19:48 +01001366 },
preethika.p329b8182020-04-22 12:25:39 +05301367 },
1368 {
1369 "if": {
1370 "properties": {
garciadeblas4568a372021-03-24 09:19:48 +01001371 "notificationTypes": {"contains": {"const": "NsChangeNotification"}}
preethika.p329b8182020-04-22 12:25:39 +05301372 },
1373 },
1374 "then": {
1375 "anyOf": [
1376 {"required": ["nsComponentTypes"]},
1377 {"required": ["lcmOpNameImpactingNsComponent"]},
1378 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1379 ]
garciadeblas4568a372021-03-24 09:19:48 +01001380 },
1381 },
1382 ],
preethika.p329b8182020-04-22 12:25:39 +05301383}
1384
1385authentication_schema = {
1386 "title": "authentication schema for subscription",
1387 "$schema": "http://json-schema.org/draft-07/schema#",
1388 "type": "object",
1389 "properties": {
1390 "authType": {"enum": ["basic"]},
1391 "paramsBasic": {
1392 "type": "object",
1393 "properties": {
sousaedu80b6fed2021-10-07 15:17:32 +01001394 "userName": string_schema,
preethika.p329b8182020-04-22 12:25:39 +05301395 "password": passwd_schema,
1396 },
1397 },
1398 },
1399}
1400
1401subscription = {
1402 "title": "subscription input schema",
1403 "$schema": "http://json-schema.org/draft-07/schema#",
1404 "type": "object",
1405 "properties": {
1406 "filter": nslcmsub_schema,
1407 "CallbackUri": description_schema,
garciadeblas4568a372021-03-24 09:19:48 +01001408 "authentication": authentication_schema,
preethika.p329b8182020-04-22 12:25:39 +05301409 },
1410 "required": ["CallbackUri"],
1411}
1412
selvi.jf1004592022-04-29 05:42:35 +00001413vnflcmsub_schema = {
1414 "title": "vnflcmsubscription input schema",
1415 "$schema": "http://json-schema.org/draft-07/schema#",
1416 "type": "object",
1417 "properties": {
1418 "VnfInstanceSubscriptionFilter": {
1419 "type": "object",
1420 "properties": {
1421 "vnfdIds": {"type": "array"},
1422 "vnfInstanceIds": {"type": "array"},
1423 },
1424 },
1425 "notificationTypes": {
1426 "type": "array",
1427 "items": {
1428 "enum": [
1429 "VnfIdentifierCreationNotification",
1430 "VnfLcmOperationOccurrenceNotification",
1431 "VnfIdentifierDeletionNotification"
1432 ]
1433 }
1434 },
1435 "operationTypes": {
1436 "type": "array",
1437 "items": {
1438 "enum": [
1439 "INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE",
1440 "HEAL", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO", "CREATE_SNAPSHOT",
1441 "REVERT_TO_SNAPSHOT", "CHANGE_VNFPKG"
1442 ]
1443 }
1444 },
1445 "operationStates": {
1446 "type": "array",
1447 "items": {
1448 "enum": [
1449 "STARTING", "PROCESSING", "COMPLETED", "FAILED_TEMP", "FAILED",
1450 "ROLLING_BACK", "ROLLED_BACK"
1451 ]
1452 }
1453 }
1454 },
1455 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"]
1456 }
1457
1458vnf_subscription = {
1459 "title": "vnf subscription input schema",
1460 "$schema": "http://json-schema.org/draft-07/schema#",
1461 "type": "object",
1462 "properties": {
1463 "filter": vnflcmsub_schema,
1464 "CallbackUri": description_schema,
1465 "authentication": authentication_schema
1466 },
1467 "required": ["filter", "CallbackUri"]
1468}
1469
tierno0f98af52018-03-19 10:28:22 +01001470
1471class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001472 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1473 self.http_code = http_code
1474 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001475
1476
tiernob24258a2018-10-04 18:39:49 +02001477def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001478 """
tiernocd54a4a2018-09-12 16:40:35 +02001479 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001480 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001481 :param schema_to_use: jsonschema to test
1482 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001483 """
1484 try:
tierno0f98af52018-03-19 10:28:22 +01001485 if schema_to_use:
1486 js_v(indata, schema_to_use)
1487 return None
1488 except js_e.ValidationError as e:
1489 if e.path:
tierno0da52252018-06-27 15:47:22 +02001490 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001491 else:
1492 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001493 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001494 except js_e.SchemaError:
garciadeblas4568a372021-03-24 09:19:48 +01001495 raise ValidationError(
1496 "Bad json schema {}".format(schema_to_use),
1497 http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1498 )
delacruzramoc061f562019-04-05 11:00:02 +02001499
1500
1501def is_valid_uuid(x):
1502 """
1503 Test for a valid UUID
1504 :param x: string to test
1505 :return: True if x is a valid uuid, False otherwise
1506 """
1507 try:
1508 if UUID(x):
1509 return True
tiernobdebce92019-07-01 15:36:49 +00001510 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001511 return False