blob: 43fd84dbe43b5c9168fd176847d23db3d83b79a7 [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
delacruzramoc061f562019-04-05 11:00:02 +020019from 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 = "^[ -~]+$"
tiernofd160572019-01-21 10:41:37 +000031shortname_schema = {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()\\.\\$'\"]+$"}
tierno0f98af52018-03-19 10:28:22 +010032passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60}
tierno0f98af52018-03-19 10:28:22 +010033name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
tierno0da52252018-06-27 15:47:22 +020034string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
tierno0f98af52018-03-19 10:28:22 +010035xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
36description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
David Garciaecb41322021-03-31 19:10:46 +020037long_description_schema = {"type": ["string", "null"], "maxLength": 3000, "pattern": "^[^'\"]+$"}
tierno441dbbf2018-07-10 12:52:48 +020038id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
39bool_schema = {"type": "boolean"}
40null_schema = {"type": "null"}
tierno2236d202018-05-16 19:05:16 +020041# "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}$"
tierno0f98af52018-03-19 10:28:22 +010042id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
tiernof759d822018-06-11 18:54:54 +020043time_schema = {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"}
tierno87006042018-10-24 12:50:20 +020044pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"}
tierno42fce592018-11-02 09:23:43 +010045# allows [] for wildcards. For that reason huge length limit is set
46pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"}
K Sai Kiran990ac462020-05-20 12:25:12 +053047http_schema = {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"}
tierno0f98af52018-03-19 10:28:22 +010048bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
49memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"}
50integer0_schema = {"type": "integer", "minimum": 0}
51integer1_schema = {"type": "integer", "minimum": 1}
tierno87006042018-10-24 12:50:20 +020052path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"}
tierno0f98af52018-03-19 10:28:22 +010053vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095}
54vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095}
55mac_schema = {"type": "string",
56 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0
tiernocb83c942018-09-24 17:28:13 +020057dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"}
tierno0f98af52018-03-19 10:28:22 +010058# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"}
59ip_schema = {"type": "string",
tierno87006042018-10-24 12:50:20 +020060 "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]?)$"}
tierno0f98af52018-03-19 10:28:22 +010061ip_prefix_schema = {"type": "string",
tierno87006042018-10-24 12:50:20 +020062 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}"
tierno2236d202018-05-16 19:05:16 +020063 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"}
tierno0f98af52018-03-19 10:28:22 +010064port_schema = {"type": "integer", "minimum": 1, "maximum": 65534}
65object_schema = {"type": "object"}
66schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2}
67# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]}
68log_level_schema = {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]}
69checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"}
70size_schema = {"type": "integer", "minimum": 1, "maximum": 100}
tiernocd54a4a2018-09-12 16:40:35 +020071array_edition_schema = {
72 "type": "object",
73 "patternProperties": {
tiernofd160572019-01-21 10:41:37 +000074 "^\\$": {}
tiernocd54a4a2018-09-12 16:40:35 +020075 },
76 "additionalProperties": False,
77 "minProperties": 1,
78}
tiernocb83c942018-09-24 17:28:13 +020079nameshort_list_schema = {
80 "type": "array",
81 "minItems": 1,
tiernofd160572019-01-21 10:41:37 +000082 "items": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +020083}
tiernocd54a4a2018-09-12 16:40:35 +020084
David Garciaecb41322021-03-31 19:10:46 +020085description_list_schema = {
86 "type": "array",
87 "minItems": 1,
88 "items": description_schema,
89}
tierno0f98af52018-03-19 10:28:22 +010090
tierno441dbbf2018-07-10 12:52:48 +020091ns_instantiate_vdu = {
92 "title": "ns action instantiate input schema for vdu",
93 "$schema": "http://json-schema.org/draft-04/schema#",
94 "type": "object",
95 "properties": {
96 "id": name_schema,
97 "volume": {
98 "type": "array",
99 "minItems": 1,
100 "items": {
101 "type": "object",
102 "properties": {
103 "name": name_schema,
104 "vim-volume-id": name_schema,
105 },
106 "required": ["name", "vim-volume-id"],
107 "additionalProperties": False
108 }
109 },
110 "interface": {
111 "type": "array",
112 "minItems": 1,
113 "items": {
114 "type": "object",
115 "properties": {
116 "name": name_schema,
117 "ip-address": ip_schema,
118 "mac-address": mac_schema,
119 "floating-ip-required": bool_schema,
120 },
121 "required": ["name"],
122 "additionalProperties": False
123 }
124 }
125 },
126 "required": ["id"],
127 "additionalProperties": False
128}
129
130ip_profile_dns_schema = {
131 "type": "array",
132 "minItems": 1,
133 "items": {
134 "type": "object",
135 "properties": {
136 "address": ip_schema,
137 },
138 "required": ["address"],
139 "additionalProperties": False
140 }
141}
142
143ip_profile_dhcp_schema = {
144 "type": "object",
145 "properties": {
146 "enabled": {"type": "boolean"},
147 "count": integer1_schema,
148 "start-address": ip_schema
149 },
150 "additionalProperties": False,
151}
152
153ip_profile_schema = {
tierno2a929042020-03-10 16:34:25 +0000154 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200155 "$schema": "http://json-schema.org/draft-04/schema#",
156 "type": "object",
157 "properties": {
158 "ip-version": {"enum": ["ipv4", "ipv6"]},
159 "subnet-address": ip_prefix_schema,
160 "gateway-address": ip_schema,
161 "dns-server": ip_profile_dns_schema,
162 "dhcp-params": ip_profile_dhcp_schema,
163 }
164}
165
166ip_profile_update_schema = {
tierno2a929042020-03-10 16:34:25 +0000167 "title": "ip profile validation schema",
tierno441dbbf2018-07-10 12:52:48 +0200168 "$schema": "http://json-schema.org/draft-04/schema#",
169 "type": "object",
170 "properties": {
171 "ip-version": {"enum": ["ipv4", "ipv6"]},
172 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]},
173 "gateway-address": {"oneOf": [null_schema, ip_schema]},
174 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]},
175
176 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]},
177 },
178 "additionalProperties": False
179}
180
kbsub21f03f52019-10-17 16:26:56 +0000181provider_network_schema = {
tierno2a929042020-03-10 16:34:25 +0000182 "title": "provider network validation schema",
kbsub21f03f52019-10-17 16:26:56 +0000183 "$schema": "http://json-schema.org/draft-04/schema#",
184 "type": "object",
185 "properties": {
186 "physical-network": name_schema,
187 "segmentation-id": name_schema,
tierno2a929042020-03-10 16:34:25 +0000188 "sdn-ports": { # external ports to append to the SDN-assist network
189 "type": "array",
190 "items": {
191 "type": "object",
192 "properties": {
193 "switch_id": shortname_schema,
194 "switch_port": shortname_schema,
195 "mac_address": mac_schema,
196 "vlan": vlan_schema,
197 },
198 "additionalProperties": True
199 }
200 },
201 "network-type": shortname_schema,
kbsub21f03f52019-10-17 16:26:56 +0000202 },
tierno2a929042020-03-10 16:34:25 +0000203 "additionalProperties": True
kbsub21f03f52019-10-17 16:26:56 +0000204}
205
tierno441dbbf2018-07-10 12:52:48 +0200206ns_instantiate_internal_vld = {
207 "title": "ns action instantiate input schema for vdu",
208 "$schema": "http://json-schema.org/draft-04/schema#",
209 "type": "object",
210 "properties": {
211 "name": name_schema,
212 "vim-network-name": name_schema,
gcalvino17d5b732018-12-17 16:26:21 +0100213 "vim-network-id": name_schema,
tierno441dbbf2018-07-10 12:52:48 +0200214 "ip-profile": ip_profile_update_schema,
kbsub21f03f52019-10-17 16:26:56 +0000215 "provider-network": provider_network_schema,
tierno441dbbf2018-07-10 12:52:48 +0200216 "internal-connection-point": {
217 "type": "array",
218 "minItems": 1,
219 "items": {
220 "type": "object",
221 "properties": {
222 "id-ref": name_schema,
223 "ip-address": ip_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200224 # "mac-address": mac_schema,
tierno441dbbf2018-07-10 12:52:48 +0200225 },
tiernob7c6f2a2018-09-03 14:32:10 +0200226 "required": ["id-ref"],
227 "minProperties": 2,
tierno441dbbf2018-07-10 12:52:48 +0200228 "additionalProperties": False
229 },
230 }
231 },
232 "required": ["name"],
233 "minProperties": 2,
234 "additionalProperties": False
235}
tierno65acb4d2018-04-06 16:42:40 +0200236
tiernofd160572019-01-21 10:41:37 +0000237additional_params_for_vnf = {
238 "type": "array",
239 "items": {
240 "type": "object",
241 "properties": {
242 "member-vnf-index": name_schema,
243 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000244 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000245 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1
tierno714954e2019-11-29 13:43:26 +0000246 "additionalParamsForVdu": {
247 "type": "array",
248 "items": {
249 "type": "object",
250 "properties": {
251 "vdu_id": name_schema,
252 "additionalParams": object_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000253 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1
tierno714954e2019-11-29 13:43:26 +0000254 },
tiernof62ac6a2020-04-29 13:46:13 +0000255 "required": ["vdu_id"],
256 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000257 "additionalProperties": False,
258 },
259 },
260 "additionalParamsForKdu": {
261 "type": "array",
262 "items": {
263 "type": "object",
264 "properties": {
265 "kdu_name": name_schema,
266 "additionalParams": object_schema,
tierno54db2e42020-04-06 15:29:42 +0000267 "kdu_model": name_schema,
268 "k8s-namespace": name_schema,
tiernof62ac6a2020-04-29 13:46:13 +0000269 "config-units": integer1_schema, # number of configuration units of this knf, by default 1
tierno714954e2019-11-29 13:43:26 +0000270 },
tierno54db2e42020-04-06 15:29:42 +0000271 "required": ["kdu_name"],
272 "minProperties": 2,
tierno714954e2019-11-29 13:43:26 +0000273 "additionalProperties": False,
274 },
275 },
tiernofd160572019-01-21 10:41:37 +0000276 },
tierno714954e2019-11-29 13:43:26 +0000277 "required": ["member-vnf-index"],
278 "minProperties": 2,
tiernofd160572019-01-21 10:41:37 +0000279 "additionalProperties": False
280 }
tiernofd160572019-01-21 10:41:37 +0000281}
282
tierno65acb4d2018-04-06 16:42:40 +0200283ns_instantiate = {
284 "title": "ns action instantiate input schema",
285 "$schema": "http://json-schema.org/draft-04/schema#",
286 "type": "object",
tierno0da52252018-06-27 15:47:22 +0200287 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200288 "lcmOperationType": string_schema,
289 "nsInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +0100290 "netsliceInstanceId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200291 "nsName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +0000292 "nsDescription": {"oneOf": [description_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200293 "nsdId": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200294 "vcaId": id_schema,
tierno0da52252018-06-27 15:47:22 +0200295 "vimAccountId": id_schema,
tierno195a36c2020-09-18 14:18:55 +0000296 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
magnussonlf318b302020-01-20 18:38:18 +0100297 "placement-engine": string_schema,
298 "placement-constraints": object_schema,
tiernobee085c2018-12-12 17:03:04 +0000299 "additionalParamsForNs": object_schema,
tiernofd160572019-01-21 10:41:37 +0000300 "additionalParamsForVnf": additional_params_for_vnf,
tiernof62ac6a2020-04-29 13:46:13 +0000301 "config-units": integer1_schema, # number of configuration units of this ns, by default 1
tierno54db2e42020-04-06 15:29:42 +0000302 "k8s-namespace": name_schema,
tiernofc5089c2018-10-31 09:28:11 +0100303 "ssh_keys": {"type": "array", "items": {"type": "string"}},
tiernoa8186a52020-01-14 15:54:48 +0000304 "timeout_ns_deploy": integer1_schema,
tierno441dbbf2018-07-10 12:52:48 +0200305 "nsr_id": id_schema,
tiernocc103432018-10-19 14:10:35 +0200306 "vduImage": name_schema,
tierno0da52252018-06-27 15:47:22 +0200307 "vnf": {
308 "type": "array",
309 "minItems": 1,
310 "items": {
311 "type": "object",
312 "properties": {
313 "member-vnf-index": name_schema,
314 "vimAccountId": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200315 "vcaId": id_schema,
tierno441dbbf2018-07-10 12:52:48 +0200316 "vdu": {
317 "type": "array",
318 "minItems": 1,
319 "items": ns_instantiate_vdu,
320 },
321 "internal-vld": {
322 "type": "array",
323 "minItems": 1,
324 "items": ns_instantiate_internal_vld
325 }
tierno0da52252018-06-27 15:47:22 +0200326 },
tierno441dbbf2018-07-10 12:52:48 +0200327 "required": ["member-vnf-index"],
328 "minProperties": 2,
329 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200330 }
331 },
332 "vld": {
333 "type": "array",
334 "minItems": 1,
335 "items": {
336 "type": "object",
337 "properties": {
338 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +0000339 "vim-network-name": {"oneOf": [string_schema, object_schema]},
340 "vim-network-id": {"oneOf": [string_schema, object_schema]},
Felipe Vicens09e65422019-01-22 15:06:46 +0100341 "ns-net": object_schema,
tierno195a36c2020-09-18 14:18:55 +0000342 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
tierno0da52252018-06-27 15:47:22 +0200343 "ip-profile": object_schema,
kbsub21f03f52019-10-17 16:26:56 +0000344 "provider-network": provider_network_schema,
tiernob7c6f2a2018-09-03 14:32:10 +0200345 "vnfd-connection-point-ref": {
346 "type": "array",
347 "minItems": 1,
348 "items": {
349 "type": "object",
350 "properties": {
351 "member-vnf-index-ref": name_schema,
352 "vnfd-connection-point-ref": name_schema,
353 "ip-address": ip_schema,
354 # "mac-address": mac_schema,
355 },
356 "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"],
357 "minProperties": 3,
358 "additionalProperties": False
359 },
360 }
tierno0da52252018-06-27 15:47:22 +0200361 },
tierno441dbbf2018-07-10 12:52:48 +0200362 "required": ["name"],
363 "additionalProperties": False
tierno0da52252018-06-27 15:47:22 +0200364 }
365 },
366 },
tierno441dbbf2018-07-10 12:52:48 +0200367 "required": ["nsName", "nsdId", "vimAccountId"],
368 "additionalProperties": False
tierno65acb4d2018-04-06 16:42:40 +0200369}
tierno0da52252018-06-27 15:47:22 +0200370
tierno1c38f2f2020-03-24 11:51:39 +0000371ns_terminate = {
372 "title": "ns terminate input schema",
373 "$schema": "http://json-schema.org/draft-04/schema#",
374 "type": "object",
375 "properties": {
376 "lcmOperationType": string_schema,
377 "nsInstanceId": id_schema,
378 "autoremove": bool_schema,
379 "timeout_ns_terminate": integer1_schema,
380 "skip_terminate_primitives": bool_schema,
tierno0b8752f2020-05-12 09:42:02 +0000381 "netsliceInstanceId": id_schema,
tierno1c38f2f2020-03-24 11:51:39 +0000382 },
383 "additionalProperties": False
384}
385
tierno65acb4d2018-04-06 16:42:40 +0200386ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution
tiernof759d822018-06-11 18:54:54 +0200387 "title": "ns action input schema",
tierno65acb4d2018-04-06 16:42:40 +0200388 "$schema": "http://json-schema.org/draft-04/schema#",
389 "type": "object",
390 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200391 "lcmOperationType": string_schema,
392 "nsInstanceId": id_schema,
tiernof5298be2018-05-16 14:43:57 +0200393 "member_vnf_index": name_schema,
394 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future
tierno7ce1db92018-07-25 12:50:52 +0200395 "vdu_id": name_schema,
tiernof0637052019-03-07 16:26:47 +0000396 "vdu_count_index": integer0_schema,
tierno9cb7d672019-10-30 12:13:48 +0000397 "kdu_name": name_schema,
tierno65acb4d2018-04-06 16:42:40 +0200398 "primitive": name_schema,
tierno50c8e6e2020-04-02 15:40:12 +0000399 "timeout_ns_action": integer1_schema,
tierno65acb4d2018-04-06 16:42:40 +0200400 "primitive_params": {"type": "object"},
401 },
tiernof5298be2018-05-16 14:43:57 +0200402 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index
tierno65acb4d2018-04-06 16:42:40 +0200403 "additionalProperties": False
404}
tiernof759d822018-06-11 18:54:54 +0200405ns_scale = { # TODO for the moment it is only VDU-scaling
406 "title": "ns scale input schema",
407 "$schema": "http://json-schema.org/draft-04/schema#",
408 "type": "object",
409 "properties": {
tiernob24258a2018-10-04 18:39:49 +0200410 "lcmOperationType": string_schema,
411 "nsInstanceId": id_schema,
tiernof759d822018-06-11 18:54:54 +0200412 "scaleType": {"enum": ["SCALE_VNF"]},
tierno50c8e6e2020-04-02 15:40:12 +0000413 "timeout_ns_scale": integer1_schema,
tiernof759d822018-06-11 18:54:54 +0200414 "scaleVnfData": {
415 "type": "object",
416 "properties": {
417 "vnfInstanceId": name_schema,
418 "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']},
419 "scaleByStepData": {
420 "type": "object",
421 "properties": {
422 "scaling-group-descriptor": name_schema,
423 "member-vnf-index": name_schema,
424 "scaling-policy": name_schema,
425 },
426 "required": ["scaling-group-descriptor", "member-vnf-index"],
427 "additionalProperties": False
428 },
429 },
430 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId
431 "additionalProperties": False
432 },
433 "scaleTime": time_schema,
434 },
435 "required": ["scaleType", "scaleVnfData"],
436 "additionalProperties": False
437}
tierno65acb4d2018-04-06 16:42:40 +0200438
439
tierno0f98af52018-03-19 10:28:22 +0100440schema_version = {"type": "string", "enum": ["1.0"]}
tierno55ba2e62018-12-11 17:22:22 +0000441schema_type = {"type": "string"}
tiernob3d0a0e2019-11-13 15:57:51 +0000442vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200443
tierno09c073e2018-04-26 13:36:48 +0200444vim_account_edit_schema = {
445 "title": "vim_account edit input schema",
446 "$schema": "http://json-schema.org/draft-04/schema#",
447 "type": "object",
448 "properties": {
449 "name": name_schema,
450 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200451 "vim": name_schema,
452 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200453 "vim_type": vim_type,
tierno09c073e2018-04-26 13:36:48 +0200454 "vim_url": description_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200455 # "vim_url_admin": description_schema,
456 # "vim_tenant": name_schema,
tierno09c073e2018-04-26 13:36:48 +0200457 "vim_tenant_name": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200458 "vim_user": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200459 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200460 "vca": id_schema,
tierno09c073e2018-04-26 13:36:48 +0200461 "config": {"type": "object"}
462 },
463 "additionalProperties": False
464}
tierno0f98af52018-03-19 10:28:22 +0100465
tierno09c073e2018-04-26 13:36:48 +0200466vim_account_new_schema = {
467 "title": "vim_account creation input schema",
tierno0f98af52018-03-19 10:28:22 +0100468 "$schema": "http://json-schema.org/draft-04/schema#",
469 "type": "object",
470 "properties": {
471 "schema_version": schema_version,
472 "schema_type": schema_type,
473 "name": name_schema,
474 "description": description_schema,
tierno09c073e2018-04-26 13:36:48 +0200475 "vim": name_schema,
476 "datacenter": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200477 "vim_type": vim_type,
tierno0f98af52018-03-19 10:28:22 +0100478 "vim_url": description_schema,
479 # "vim_url_admin": description_schema,
480 # "vim_tenant": name_schema,
481 "vim_tenant_name": name_schema,
tiernofd160572019-01-21 10:41:37 +0000482 "vim_user": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200483 "vim_password": passwd_schema,
David Garciaecb41322021-03-31 19:10:46 +0200484 "vca": id_schema,
tierno0f98af52018-03-19 10:28:22 +0100485 "config": {"type": "object"}
486 },
487 "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
488 "additionalProperties": False
489}
tierno0f98af52018-03-19 10:28:22 +0100490
tierno85807722019-12-20 14:11:35 +0000491wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]}
delacruzramo3a144c92019-10-25 09:46:33 +0200492
tierno55ba2e62018-12-11 17:22:22 +0000493wim_account_edit_schema = {
494 "title": "wim_account edit input schema",
495 "$schema": "http://json-schema.org/draft-04/schema#",
496 "type": "object",
497 "properties": {
498 "name": name_schema,
499 "description": description_schema,
tierno55ba2e62018-12-11 17:22:22 +0000500 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200501 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000502 "wim_url": description_schema,
tiernofd160572019-01-21 10:41:37 +0000503 "user": shortname_schema,
tierno55ba2e62018-12-11 17:22:22 +0000504 "password": passwd_schema,
505 "config": {"type": "object"}
506 },
507 "additionalProperties": False
508}
509
510wim_account_new_schema = {
511 "title": "wim_account creation input schema",
512 "$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,
519 "wim": name_schema,
delacruzramo3a144c92019-10-25 09:46:33 +0200520 "wim_type": wim_type,
tierno55ba2e62018-12-11 17:22:22 +0000521 "wim_url": description_schema,
tiernofd160572019-01-21 10:41:37 +0000522 "user": shortname_schema,
tierno55ba2e62018-12-11 17:22:22 +0000523 "password": passwd_schema,
tiernof0637052019-03-07 16:26:47 +0000524 "config": {
525 "type": "object",
526 "patternProperties": {
527 ".": {"not": {"type": "null"}}
528 }
529 }
tierno55ba2e62018-12-11 17:22:22 +0000530 },
531 "required": ["name", "wim_url", "wim_type"],
532 "additionalProperties": False
533}
tierno0f98af52018-03-19 10:28:22 +0100534
535sdn_properties = {
536 "name": name_schema,
tierno7adaeb02019-12-17 16:46:12 +0000537 "type": {"type": "string"},
538 "url": {"type": "string"},
539 "user": shortname_schema,
540 "password": passwd_schema,
541 "config": {"type": "object"},
tiernocfb07c62018-05-10 18:30:51 +0200542 "description": description_schema,
tierno7adaeb02019-12-17 16:46:12 +0000543 # The folowing are deprecated. Maintanied for backward compatibility
tiernocb83c942018-09-24 17:28:13 +0200544 "dpid": dpid_Schema,
tierno0f98af52018-03-19 10:28:22 +0100545 "ip": ip_schema,
546 "port": port_schema,
tierno0f98af52018-03-19 10:28:22 +0100547 "version": {"type": "string", "minLength": 1, "maxLength": 12},
tierno0f98af52018-03-19 10:28:22 +0100548}
549sdn_new_schema = {
550 "title": "sdn controller information schema",
551 "$schema": "http://json-schema.org/draft-04/schema#",
552 "type": "object",
553 "properties": sdn_properties,
tierno7adaeb02019-12-17 16:46:12 +0000554 "required": ["name", 'type'],
tierno0f98af52018-03-19 10:28:22 +0100555 "additionalProperties": False
556}
557sdn_edit_schema = {
558 "title": "sdn controller update information schema",
559 "$schema": "http://json-schema.org/draft-04/schema#",
560 "type": "object",
561 "properties": sdn_properties,
tiernocfb07c62018-05-10 18:30:51 +0200562 # "required": ["name", "port", 'ip', 'dpid', 'type'],
tierno0f98af52018-03-19 10:28:22 +0100563 "additionalProperties": False
564}
565sdn_port_mapping_schema = {
566 "$schema": "http://json-schema.org/draft-04/schema#",
567 "title": "sdn port mapping information schema",
568 "type": "array",
569 "items": {
570 "type": "object",
571 "properties": {
tiernofd160572019-01-21 10:41:37 +0000572 "compute_node": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100573 "ports": {
574 "type": "array",
575 "items": {
576 "type": "object",
577 "properties": {
tierno42fce592018-11-02 09:23:43 +0100578 "pci": pci_extended_schema,
tiernofd160572019-01-21 10:41:37 +0000579 "switch_port": shortname_schema,
tierno0f98af52018-03-19 10:28:22 +0100580 "switch_mac": mac_schema
581 },
582 "required": ["pci"]
583 }
584 }
585 },
586 "required": ["compute_node", "ports"]
587 }
588}
589sdn_external_port_schema = {
590 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocd54a4a2018-09-12 16:40:35 +0200591 "title": "External port information",
tierno0f98af52018-03-19 10:28:22 +0100592 "type": "object",
593 "properties": {
594 "port": {"type": "string", "minLength": 1, "maxLength": 60},
595 "vlan": vlan_schema,
596 "mac": mac_schema
597 },
598 "required": ["port"]
599}
600
delacruzramofe598fe2019-10-23 18:25:11 +0200601# K8s Clusters
602k8scluster_nets_schema = {
603 "title": "k8scluster nets input schema",
604 "$schema": "http://json-schema.org/draft-04/schema#",
605 "type": "object",
tierno8c81ab02020-02-07 10:18:30 +0000606 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}},
delacruzramofe598fe2019-10-23 18:25:11 +0200607 "minProperties": 1,
608 "additionalProperties": False
609}
610k8scluster_new_schema = {
611 "title": "k8scluster creation input schema",
612 "$schema": "http://json-schema.org/draft-04/schema#",
613 "type": "object",
614 "properties": {
615 "schema_version": schema_version,
616 "schema_type": schema_type,
617 "name": name_schema,
618 "description": description_schema,
619 "credentials": object_schema,
620 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200621 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200622 "k8s_version": string_schema,
623 "nets": k8scluster_nets_schema,
624 "namespace": name_schema,
625 "cni": nameshort_list_schema,
626 },
627 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"],
628 "additionalProperties": False
629}
630k8scluster_edit_schema = {
631 "title": "vim_account edit input schema",
632 "$schema": "http://json-schema.org/draft-04/schema#",
633 "type": "object",
634 "properties": {
635 "name": name_schema,
636 "description": description_schema,
637 "credentials": object_schema,
638 "vim_account": id_schema,
David Garciaecb41322021-03-31 19:10:46 +0200639 "vca_id": id_schema,
delacruzramofe598fe2019-10-23 18:25:11 +0200640 "k8s_version": string_schema,
641 "nets": k8scluster_nets_schema,
642 "namespace": name_schema,
643 "cni": nameshort_list_schema,
644 },
645 "additionalProperties": False
646}
647
David Garciaecb41322021-03-31 19:10:46 +0200648# VCA
649vca_new_schema = {
650 "title": "vca creation input schema",
651 "$schema": "http://json-schema.org/draft-04/schema#",
652 "type": "object",
653 "properties": {
654 "schema_version": schema_version,
655 "schema_type": schema_type,
656 "name": name_schema,
657 "description": description_schema,
658 "endpoints": description_list_schema,
659 "user": shortname_schema,
660 "secret": passwd_schema,
661 "cacert": long_description_schema,
662 "lxd-cloud": shortname_schema,
663 "lxd-credentials": shortname_schema,
664 "k8s-cloud": shortname_schema,
665 "k8s-credentials": shortname_schema,
666 "model-config": object_schema,
667 },
668 "required": [
669 "name",
670 "endpoints",
671 "user",
672 "secret",
673 "cacert",
674 "lxd-cloud",
675 "lxd-credentials",
676 "k8s-cloud",
677 "k8s-credentials",
678 ],
679 "additionalProperties": False,
680}
681vca_edit_schema = {
682 "title": "vca creation input schema",
683 "$schema": "http://json-schema.org/draft-04/schema#",
684 "type": "object",
685 "properties": {
686 "name": name_schema,
687 "description": description_schema,
688 "endpoints": description_list_schema,
689 "port": integer1_schema,
690 "user": shortname_schema,
691 "secret": passwd_schema,
692 "cacert": long_description_schema,
693 "lxd-cloud": shortname_schema,
694 "lxd-credentials": shortname_schema,
695 "k8s-cloud": shortname_schema,
696 "k8s-credentials": shortname_schema,
697 "model-config": object_schema,
698 },
699 "additionalProperties": False,
700}
701
delacruzramofe598fe2019-10-23 18:25:11 +0200702# K8s Repos
tierno332e0802019-12-03 23:50:49 +0000703k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
delacruzramofe598fe2019-10-23 18:25:11 +0200704k8srepo_properties = {
705 "name": name_schema,
706 "description": description_schema,
707 "type": k8srepo_types,
708 "url": description_schema,
709}
710k8srepo_new_schema = {
711 "title": "k8scluster creation input schema",
712 "$schema": "http://json-schema.org/draft-04/schema#",
713 "type": "object",
714 "properties": k8srepo_properties,
715 "required": ["name", "type", "url"],
716 "additionalProperties": False
717}
718k8srepo_edit_schema = {
719 "title": "vim_account edit input schema",
720 "$schema": "http://json-schema.org/draft-04/schema#",
721 "type": "object",
722 "properties": k8srepo_properties,
723 "additionalProperties": False
724}
725
Felipe Vicensb66b0412020-05-06 10:11:00 +0200726# OSM Repos
727osmrepo_types = {"enum": ["osm"]}
728osmrepo_properties = {
729 "name": name_schema,
730 "description": description_schema,
731 "type": osmrepo_types,
732 "url": description_schema
733 # "user": shortname_schema,
734 # "password": passwd_schema
735}
736osmrepo_new_schema = {
737 "title": "osm repo creation input schema",
738 "$schema": "http://json-schema.org/draft-04/schema#",
739 "type": "object",
740 "properties": osmrepo_properties,
741 "required": ["name", "type", "url"],
742 "additionalProperties": False
743}
744osmrepo_edit_schema = {
745 "title": "osm repo edit input schema",
746 "$schema": "http://json-schema.org/draft-04/schema#",
747 "type": "object",
748 "properties": osmrepo_properties,
749 "additionalProperties": False
750}
751
tiernocb83c942018-09-24 17:28:13 +0200752# PDUs
753pdu_interface = {
754 "type": "object",
755 "properties": {
tiernofd160572019-01-21 10:41:37 +0000756 "name": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200757 "mgmt": bool_schema,
758 "type": {"enum": ["overlay", 'underlay']},
tierno36ec8602018-11-02 17:27:11 +0100759 "ip-address": ip_schema,
tiernocb83c942018-09-24 17:28:13 +0200760 # TODO, add user, password, ssh-key
tierno36ec8602018-11-02 17:27:11 +0100761 "mac-address": mac_schema,
tiernofd160572019-01-21 10:41:37 +0000762 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port
763 "vim-network-id": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100764 # # provide this in case SDN assist must deal with this interface
765 # "switch-dpid": dpid_Schema,
tiernofd160572019-01-21 10:41:37 +0000766 # "switch-port": shortname_schema,
767 # "switch-mac": shortname_schema,
tierno36ec8602018-11-02 17:27:11 +0100768 # "switch-vlan": vlan_schema,
tiernocb83c942018-09-24 17:28:13 +0200769 },
tierno36ec8602018-11-02 17:27:11 +0100770 "required": ["name", "mgmt", "ip-address"],
tiernocb83c942018-09-24 17:28:13 +0200771 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200772}
tiernocb83c942018-09-24 17:28:13 +0200773pdu_new_schema = {
774 "title": "pdu creation input schema",
775 "$schema": "http://json-schema.org/draft-04/schema#",
776 "type": "object",
777 "properties": {
tiernofd160572019-01-21 10:41:37 +0000778 "name": shortname_schema,
779 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200780 "description": description_schema,
781 "shared": bool_schema,
782 "vims": nameshort_list_schema,
783 "vim_accounts": nameshort_list_schema,
784 "interfaces": {
785 "type": "array",
tierno36ec8602018-11-02 17:27:11 +0100786 "items": pdu_interface,
tiernocb83c942018-09-24 17:28:13 +0200787 "minItems": 1
788 }
789 },
790 "required": ["name", "type", "interfaces"],
791 "additionalProperties": False
792}
tiernocb83c942018-09-24 17:28:13 +0200793pdu_edit_schema = {
794 "title": "pdu edit input schema",
795 "$schema": "http://json-schema.org/draft-04/schema#",
796 "type": "object",
797 "properties": {
tiernofd160572019-01-21 10:41:37 +0000798 "name": shortname_schema,
799 "type": shortname_schema,
tiernocb83c942018-09-24 17:28:13 +0200800 "description": description_schema,
801 "shared": bool_schema,
garciadeblas84bdd552018-11-30 22:59:45 +0100802 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]},
803 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]},
804 "interfaces": {"oneOf": [
tiernocb83c942018-09-24 17:28:13 +0200805 array_edition_schema,
806 {
807 "type": "array",
tierno36ec8602018-11-02 17:27:11 +0100808 "items": pdu_interface,
tiernocb83c942018-09-24 17:28:13 +0200809 "minItems": 1
810 }
811 ]}
812 },
813 "additionalProperties": False,
814 "minProperties": 1
815}
816
delacruzramo271d2002019-12-02 21:00:37 +0100817# VNF PKG OPERATIONS
818vnfpkgop_new_schema = {
819 "title": "VNF PKG operation creation input schema",
820 "$schema": "http://json-schema.org/draft-04/schema#",
821 "type": "object",
822 "properties": {
823 "lcmOperationType": string_schema,
824 "vnfPkgId": id_schema,
825 "kdu_name": name_schema,
826 "primitive": name_schema,
827 "primitive_params": {"type": "object"},
828 },
829 "required": ["lcmOperationType", "vnfPkgId", "kdu_name", "primitive", "primitive_params"],
830 "additionalProperties": False
831}
832
tiernocb83c942018-09-24 17:28:13 +0200833# USERS
tiernocf042d32019-06-13 09:06:40 +0000834project_role_mappings = {
835 "title": "list pf projects/roles",
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100836 "$schema": "http://json-schema.org/draft-04/schema#",
tiernocf042d32019-06-13 09:06:40 +0000837 "type": "array",
838 "items": {
839 "type": "object",
840 "properties": {
841 "project": shortname_schema,
842 "role": shortname_schema
843 },
844 "required": ["project", "role"],
845 "additionalProperties": False
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100846 },
tiernocf042d32019-06-13 09:06:40 +0000847 "minItems": 1
848}
849project_role_mappings_optional = {
850 "title": "list of projects/roles or projects only",
851 "$schema": "http://json-schema.org/draft-04/schema#",
852 "type": "array",
853 "items": {
854 "type": "object",
855 "properties": {
856 "project": shortname_schema,
857 "role": shortname_schema
858 },
859 "required": ["project"],
860 "additionalProperties": False
861 },
862 "minItems": 1
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100863}
tiernocd54a4a2018-09-12 16:40:35 +0200864user_new_schema = {
865 "$schema": "http://json-schema.org/draft-04/schema#",
866 "title": "New user schema",
867 "type": "object",
868 "properties": {
tiernofd160572019-01-21 10:41:37 +0000869 "username": shortname_schema,
tiernoad6d5332020-02-19 14:29:49 +0000870 "domain_name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200871 "password": passwd_schema,
tiernocb83c942018-09-24 17:28:13 +0200872 "projects": nameshort_list_schema,
tiernocf042d32019-06-13 09:06:40 +0000873 "project_role_mappings": project_role_mappings,
tiernocd54a4a2018-09-12 16:40:35 +0200874 },
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100875 "required": ["username", "password"],
tiernocd54a4a2018-09-12 16:40:35 +0200876 "additionalProperties": False
877}
878user_edit_schema = {
879 "$schema": "http://json-schema.org/draft-04/schema#",
880 "title": "User edit schema for administrators",
881 "type": "object",
882 "properties": {
883 "password": passwd_schema,
delacruzramoc061f562019-04-05 11:00:02 +0200884 "username": shortname_schema, # To allow User Name modification
tiernocd54a4a2018-09-12 16:40:35 +0200885 "projects": {
garciadeblas84bdd552018-11-30 22:59:45 +0100886 "oneOf": [
tiernocb83c942018-09-24 17:28:13 +0200887 nameshort_list_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200888 array_edition_schema
889 ]
890 },
tiernocf042d32019-06-13 09:06:40 +0000891 "project_role_mappings": project_role_mappings,
892 "add_project_role_mappings": project_role_mappings,
893 "remove_project_role_mappings": project_role_mappings_optional,
tiernocb83c942018-09-24 17:28:13 +0200894 },
895 "minProperties": 1,
896 "additionalProperties": False
tiernocd54a4a2018-09-12 16:40:35 +0200897}
898
899# PROJECTS
tierno6b02b052020-06-02 10:07:41 +0000900topics_with_quota = ["vnfds", "nsds", "slice_templates", "pduds", "ns_instances", "slice_instances", "vim_accounts",
David Garciaecb41322021-03-31 19:10:46 +0200901 "wim_accounts", "sdn_controllers", "k8sclusters", "vca", "k8srepos", "osmrepos", "ns_subscriptions"]
tiernocd54a4a2018-09-12 16:40:35 +0200902project_new_schema = {
903 "$schema": "http://json-schema.org/draft-04/schema#",
904 "title": "New project schema for administrators",
905 "type": "object",
906 "properties": {
tiernofd160572019-01-21 10:41:37 +0000907 "name": shortname_schema,
tiernocd54a4a2018-09-12 16:40:35 +0200908 "admin": bool_schema,
tiernoad6d5332020-02-19 14:29:49 +0000909 "domain_name": shortname_schema,
delacruzramo32bab472019-09-13 12:24:22 +0200910 "quotas": {
911 "type": "object",
912 "properties": {topic: integer0_schema for topic in topics_with_quota},
913 "additionalProperties": False
914 },
tiernocd54a4a2018-09-12 16:40:35 +0200915 },
916 "required": ["name"],
917 "additionalProperties": False
918}
919project_edit_schema = {
920 "$schema": "http://json-schema.org/draft-04/schema#",
921 "title": "Project edit schema for administrators",
922 "type": "object",
923 "properties": {
924 "admin": bool_schema,
delacruzramoc061f562019-04-05 11:00:02 +0200925 "name": shortname_schema, # To allow Project Name modification
delacruzramo32bab472019-09-13 12:24:22 +0200926 "quotas": {
927 "type": "object",
928 "properties": {topic: {"oneOf": [integer0_schema, null_schema]} for topic in topics_with_quota},
929 "additionalProperties": False
930 },
tiernocd54a4a2018-09-12 16:40:35 +0200931 },
932 "additionalProperties": False,
933 "minProperties": 1
934}
935
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100936# ROLES
937roles_new_schema = {
938 "$schema": "http://json-schema.org/draft-04/schema#",
939 "title": "New role schema for administrators",
940 "type": "object",
941 "properties": {
942 "name": shortname_schema,
tierno1f029d82019-06-13 22:37:04 +0000943 "permissions": {
944 "type": "object",
945 "patternProperties": {
946 ".": bool_schema,
947 },
948 # "minProperties": 1,
949 }
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100950 },
tierno1f029d82019-06-13 22:37:04 +0000951 "required": ["name"],
952 "additionalProperties": False
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100953}
954roles_edit_schema = {
955 "$schema": "http://json-schema.org/draft-04/schema#",
956 "title": "Roles edit schema for administrators",
957 "type": "object",
958 "properties": {
tierno1f029d82019-06-13 22:37:04 +0000959 "name": shortname_schema,
960 "permissions": {
961 "type": "object",
962 "patternProperties": {
963 ".": {
964 "oneOf": [bool_schema, null_schema]
965 }
966 },
967 # "minProperties": 1,
968 }
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100969 },
tierno1f029d82019-06-13 22:37:04 +0000970 "additionalProperties": False,
Eduardo Sousa5c01e192019-05-08 02:35:47 +0100971 "minProperties": 1
972}
973
tiernocd54a4a2018-09-12 16:40:35 +0200974# GLOBAL SCHEMAS
tierno0f98af52018-03-19 10:28:22 +0100975
976nbi_new_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200977 "users": user_new_schema,
978 "projects": project_new_schema,
tierno09c073e2018-04-26 13:36:48 +0200979 "vim_accounts": vim_account_new_schema,
tierno65acb4d2018-04-06 16:42:40 +0200980 "sdns": sdn_new_schema,
981 "ns_instantiate": ns_instantiate,
982 "ns_action": ns_action,
tiernocb83c942018-09-24 17:28:13 +0200983 "ns_scale": ns_scale,
984 "pdus": pdu_new_schema,
tierno0f98af52018-03-19 10:28:22 +0100985}
986
987nbi_edit_input_schemas = {
tiernocd54a4a2018-09-12 16:40:35 +0200988 "users": user_edit_schema,
989 "projects": project_edit_schema,
tierno09c073e2018-04-26 13:36:48 +0200990 "vim_accounts": vim_account_edit_schema,
tiernocb83c942018-09-24 17:28:13 +0200991 "sdns": sdn_edit_schema,
992 "pdus": pdu_edit_schema,
tierno0f98af52018-03-19 10:28:22 +0100993}
994
Felipe Vicens07f31722018-10-29 15:16:44 +0100995# NETSLICE SCHEMAS
tierno032916c2019-03-22 13:27:12 +0000996nsi_subnet_instantiate = deepcopy(ns_instantiate)
997nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema"
998nsi_subnet_instantiate["properties"]["id"] = name_schema
999del nsi_subnet_instantiate["required"]
garciadeblasdaf8cc52018-11-30 14:17:20 +01001000
1001nsi_vld_instantiate = {
1002 "title": "netslice vld instantiation params input schema",
1003 "$schema": "http://json-schema.org/draft-04/schema#",
1004 "type": "object",
1005 "properties": {
1006 "name": string_schema,
tierno195a36c2020-09-18 14:18:55 +00001007 "vim-network-name": {"oneOf": [string_schema, object_schema]},
1008 "vim-network-id": {"oneOf": [string_schema, object_schema]},
garciadeblasdaf8cc52018-11-30 14:17:20 +01001009 "ip-profile": object_schema,
1010 },
delacruzramoc061f562019-04-05 11:00:02 +02001011 "required": ["name"],
garciadeblasdaf8cc52018-11-30 14:17:20 +01001012 "additionalProperties": False
1013}
1014
Felipe Vicens07f31722018-10-29 15:16:44 +01001015nsi_instantiate = {
1016 "title": "netslice action instantiate input schema",
1017 "$schema": "http://json-schema.org/draft-04/schema#",
1018 "type": "object",
1019 "properties": {
1020 "lcmOperationType": string_schema,
Felipe Vicens126af572019-06-05 19:13:04 +02001021 "netsliceInstanceId": id_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001022 "nsiName": name_schema,
tierno4f9d4ae2019-03-20 17:24:11 +00001023 "nsiDescription": {"oneOf": [description_schema, null_schema]},
tierno9e5eea32018-11-29 09:42:09 +00001024 "nstId": string_schema,
Felipe Vicens07f31722018-10-29 15:16:44 +01001025 "vimAccountId": id_schema,
tiernoa8186a52020-01-14 15:54:48 +00001026 "timeout_nsi_deploy": integer1_schema,
Felipe Vicens26202bb2020-05-24 18:57:33 +02001027 "ssh_keys": {"type": "array", "items": {"type": "string"}},
Felipe Vicens07f31722018-10-29 15:16:44 +01001028 "nsi_id": id_schema,
tierno032916c2019-03-22 13:27:12 +00001029 "additionalParamsForNsi": object_schema,
garciadeblasdaf8cc52018-11-30 14:17:20 +01001030 "netslice-subnet": {
Felipe Vicens07f31722018-10-29 15:16:44 +01001031 "type": "array",
1032 "minItems": 1,
tierno032916c2019-03-22 13:27:12 +00001033 "items": nsi_subnet_instantiate
garciadeblasdaf8cc52018-11-30 14:17:20 +01001034 },
1035 "netslice-vld": {
1036 "type": "array",
1037 "minItems": 1,
1038 "items": nsi_vld_instantiate
Felipe Vicens07f31722018-10-29 15:16:44 +01001039 },
1040 },
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001041 "required": ["nsiName", "nstId", "vimAccountId"],
Felipe Vicens07f31722018-10-29 15:16:44 +01001042 "additionalProperties": False
1043}
1044
1045nsi_action = {
1046
1047}
1048
1049nsi_terminate = {
delacruzramoc061f562019-04-05 11:00:02 +02001050
Felipe Vicens07f31722018-10-29 15:16:44 +01001051}
1052
preethika.p329b8182020-04-22 12:25:39 +05301053nsinstancesubscriptionfilter_schema = {
1054 "title": "instance identifier schema",
1055 "$schema": "http://json-schema.org/draft-07/schema#",
1056 "type": "object",
1057 "properties": {
1058 "nsdIds": {"type": "array"},
1059 "vnfdIds": {"type": "array"},
1060 "pnfdIds": {"type": "array"},
1061 "nsInstanceIds": {"type": "array"},
1062 "nsInstanceNames": {"type": "array"},
1063 },
1064}
1065
1066nslcmsub_schema = {
1067 "title": "nslcmsubscription input schema",
1068 "$schema": "http://json-schema.org/draft-07/schema#",
1069 "type": "object",
1070 "properties": {
1071 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
1072 "notificationTypes": {
1073 "type": "array",
1074 "items": {
1075 "enum": ['NsLcmOperationOccurrenceNotification', 'NsChangeNotification',
1076 'NsIdentifierCreationNotification', 'NsIdentifierDeletionNotification']
1077 }
1078 },
1079 "operationTypes": {
1080 "type": "array",
1081 "items": {
1082 "enum": ['INSTANTIATE', 'SCALE', 'TERMINATE', 'UPDATE', 'HEAL']
1083 }
1084 },
1085 "operationStates": {
1086 "type": "array",
1087 "items": {
1088 "enum": ['PROCESSING', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED',
1089 'FAILED_TEMP', 'ROLLING_BACK', 'ROLLED_BACK']
1090 }
1091 },
1092 "nsComponentTypes": {
1093 "type": "array",
1094 "items": {
1095 "enum": ['VNF', 'NS', 'PNF']
1096 }
1097 },
1098 "lcmOpNameImpactingNsComponent": {
1099 "type": "array",
1100 "items": {
1101 "enum": ['VNF_INSTANTIATE', 'VNF_SCALE', 'VNF_SCALE_TO_LEVEL', 'VNF_CHANGE_FLAVOUR',
1102 'VNF_TERMINATE', 'VNF_HEAL', 'VNF_OPERATE', 'VNF_CHANGE_EXT_CONN', 'VNF_MODIFY_INFO',
1103 'NS_INSTANTIATE', 'NS_SCALE', 'NS_UPDATE', 'NS_TERMINATE', 'NS_HEAL']
1104 }
1105 },
1106 "lcmOpOccStatusImpactingNsComponent": {
1107 "type": "array",
1108 "items": {
1109 "enum": ['START', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED', 'ROLLED_BACK']
1110 }
1111 },
1112 },
1113 "allOf": [
1114 {
1115 "if": {
1116 "properties": {
1117 "notificationTypes": {
1118 "contains": {"const": "NsLcmOperationOccurrenceNotification"}
1119 }
1120 },
1121 },
1122 "then": {
1123 "anyOf": [
1124 {"required": ["operationTypes"]},
1125 {"required": ["operationStates"]},
1126 ]
1127 }
1128 },
1129 {
1130 "if": {
1131 "properties": {
1132 "notificationTypes": {
1133 "contains": {"const": "NsChangeNotification"}
1134 }
1135 },
1136 },
1137 "then": {
1138 "anyOf": [
1139 {"required": ["nsComponentTypes"]},
1140 {"required": ["lcmOpNameImpactingNsComponent"]},
1141 {"required": ["lcmOpOccStatusImpactingNsComponent"]},
1142 ]
1143 }
1144 }
1145 ]
1146}
1147
1148authentication_schema = {
1149 "title": "authentication schema for subscription",
1150 "$schema": "http://json-schema.org/draft-07/schema#",
1151 "type": "object",
1152 "properties": {
1153 "authType": {"enum": ["basic"]},
1154 "paramsBasic": {
1155 "type": "object",
1156 "properties": {
1157 "userName": shortname_schema,
1158 "password": passwd_schema,
1159 },
1160 },
1161 },
1162}
1163
1164subscription = {
1165 "title": "subscription input schema",
1166 "$schema": "http://json-schema.org/draft-07/schema#",
1167 "type": "object",
1168 "properties": {
1169 "filter": nslcmsub_schema,
1170 "CallbackUri": description_schema,
1171 "authentication": authentication_schema
1172 },
1173 "required": ["CallbackUri"],
1174}
1175
tierno0f98af52018-03-19 10:28:22 +01001176
1177class ValidationError(Exception):
tierno36ec8602018-11-02 17:27:11 +01001178 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):
1179 self.http_code = http_code
1180 Exception.__init__(self, message)
tierno0f98af52018-03-19 10:28:22 +01001181
1182
tiernob24258a2018-10-04 18:39:49 +02001183def validate_input(indata, schema_to_use):
tierno0f98af52018-03-19 10:28:22 +01001184 """
tiernocd54a4a2018-09-12 16:40:35 +02001185 Validates input data against json schema
tierno0f98af52018-03-19 10:28:22 +01001186 :param indata: user input data. Should be a dictionary
tiernob24258a2018-10-04 18:39:49 +02001187 :param schema_to_use: jsonschema to test
1188 :return: None if ok, raises ValidationError exception on error
tierno0f98af52018-03-19 10:28:22 +01001189 """
1190 try:
tierno0f98af52018-03-19 10:28:22 +01001191 if schema_to_use:
1192 js_v(indata, schema_to_use)
1193 return None
1194 except js_e.ValidationError as e:
1195 if e.path:
tierno0da52252018-06-27 15:47:22 +02001196 error_pos = "at '" + ":".join(map(str, e.path)) + "'"
tierno0f98af52018-03-19 10:28:22 +01001197 else:
1198 error_pos = ""
tierno441dbbf2018-07-10 12:52:48 +02001199 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
tierno36ec8602018-11-02 17:27:11 +01001200 except js_e.SchemaError:
1201 raise ValidationError("Bad json schema {}".format(schema_to_use), http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
delacruzramoc061f562019-04-05 11:00:02 +02001202
1203
1204def is_valid_uuid(x):
1205 """
1206 Test for a valid UUID
1207 :param x: string to test
1208 :return: True if x is a valid uuid, False otherwise
1209 """
1210 try:
1211 if UUID(x):
1212 return True
tiernobdebce92019-07-01 15:36:49 +00001213 except (TypeError, ValueError, AttributeError):
delacruzramoc061f562019-04-05 11:00:02 +02001214 return False