| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| tierno | d125caf | 2018-11-22 16:05:54 +0000 | [diff] [blame] | 3 | # 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 | |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 16 | from jsonschema import validate as js_v, exceptions as js_e |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 17 | from http import HTTPStatus |
| garciadeblas | daf8cc5 | 2018-11-30 14:17:20 +0100 | [diff] [blame] | 18 | from copy import deepcopy |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 19 | |
| 20 | __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>" |
| 21 | __version__ = "0.1" |
| 22 | version_date = "Mar 2018" |
| 23 | |
| 24 | """ |
| 25 | Validator of input data using JSON schemas for those items that not contains an OSM yang information model |
| 26 | """ |
| 27 | |
| 28 | # Basis schemas |
| 29 | patern_name = "^[ -~]+$" |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 30 | shortname_schema = {"type": "string", "minLength": 1, "maxLength": 60, "pattern": "^[^,;()\\.\\$'\"]+$"} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 31 | passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 32 | name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"} |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 33 | string_schema = {"type": "string", "minLength": 1, "maxLength": 255} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 34 | xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"} |
| 35 | description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"} |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 36 | id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36} |
| 37 | bool_schema = {"type": "boolean"} |
| 38 | null_schema = {"type": "null"} |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 39 | # "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}$" |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 40 | id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"} |
| tierno | f759d82 | 2018-06-11 18:54:54 +0200 | [diff] [blame] | 41 | time_schema = {"type": "string", "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}"} |
| tierno | 8700604 | 2018-10-24 12:50:20 +0200 | [diff] [blame] | 42 | pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$"} |
| tierno | 42fce59 | 2018-11-02 09:23:43 +0100 | [diff] [blame] | 43 | # allows [] for wildcards. For that reason huge length limit is set |
| 44 | pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 45 | http_schema = {"type": "string", "pattern": "^https?://[^'\"=]+$"} |
| 46 | bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"} |
| 47 | memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"} |
| 48 | integer0_schema = {"type": "integer", "minimum": 0} |
| 49 | integer1_schema = {"type": "integer", "minimum": 1} |
| tierno | 8700604 | 2018-10-24 12:50:20 +0200 | [diff] [blame] | 50 | path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 51 | vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095} |
| 52 | vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095} |
| 53 | mac_schema = {"type": "string", |
| 54 | "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"} # must be unicast: LSB bit of MSB byte ==0 |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 55 | dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 56 | # mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"} |
| 57 | ip_schema = {"type": "string", |
| tierno | 8700604 | 2018-10-24 12:50:20 +0200 | [diff] [blame] | 58 | "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]?)$"} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 59 | ip_prefix_schema = {"type": "string", |
| tierno | 8700604 | 2018-10-24 12:50:20 +0200 | [diff] [blame] | 60 | "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" |
| tierno | 2236d20 | 2018-05-16 19:05:16 +0200 | [diff] [blame] | 61 | "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$"} |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 62 | port_schema = {"type": "integer", "minimum": 1, "maximum": 65534} |
| 63 | object_schema = {"type": "object"} |
| 64 | schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2} |
| 65 | # schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]} |
| 66 | log_level_schema = {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]} |
| 67 | checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"} |
| 68 | size_schema = {"type": "integer", "minimum": 1, "maximum": 100} |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 69 | array_edition_schema = { |
| 70 | "type": "object", |
| 71 | "patternProperties": { |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 72 | "^\\$": {} |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 73 | }, |
| 74 | "additionalProperties": False, |
| 75 | "minProperties": 1, |
| 76 | } |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 77 | nameshort_list_schema = { |
| 78 | "type": "array", |
| 79 | "minItems": 1, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 80 | "items": shortname_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 81 | } |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 82 | |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 83 | |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 84 | ns_instantiate_vdu = { |
| 85 | "title": "ns action instantiate input schema for vdu", |
| 86 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 87 | "type": "object", |
| 88 | "properties": { |
| 89 | "id": name_schema, |
| 90 | "volume": { |
| 91 | "type": "array", |
| 92 | "minItems": 1, |
| 93 | "items": { |
| 94 | "type": "object", |
| 95 | "properties": { |
| 96 | "name": name_schema, |
| 97 | "vim-volume-id": name_schema, |
| 98 | }, |
| 99 | "required": ["name", "vim-volume-id"], |
| 100 | "additionalProperties": False |
| 101 | } |
| 102 | }, |
| 103 | "interface": { |
| 104 | "type": "array", |
| 105 | "minItems": 1, |
| 106 | "items": { |
| 107 | "type": "object", |
| 108 | "properties": { |
| 109 | "name": name_schema, |
| 110 | "ip-address": ip_schema, |
| 111 | "mac-address": mac_schema, |
| 112 | "floating-ip-required": bool_schema, |
| 113 | }, |
| 114 | "required": ["name"], |
| 115 | "additionalProperties": False |
| 116 | } |
| 117 | } |
| 118 | }, |
| 119 | "required": ["id"], |
| 120 | "additionalProperties": False |
| 121 | } |
| 122 | |
| 123 | ip_profile_dns_schema = { |
| 124 | "type": "array", |
| 125 | "minItems": 1, |
| 126 | "items": { |
| 127 | "type": "object", |
| 128 | "properties": { |
| 129 | "address": ip_schema, |
| 130 | }, |
| 131 | "required": ["address"], |
| 132 | "additionalProperties": False |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | ip_profile_dhcp_schema = { |
| 137 | "type": "object", |
| 138 | "properties": { |
| 139 | "enabled": {"type": "boolean"}, |
| 140 | "count": integer1_schema, |
| 141 | "start-address": ip_schema |
| 142 | }, |
| 143 | "additionalProperties": False, |
| 144 | } |
| 145 | |
| 146 | ip_profile_schema = { |
| 147 | "title": "ip profile validation schame", |
| 148 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 149 | "type": "object", |
| 150 | "properties": { |
| 151 | "ip-version": {"enum": ["ipv4", "ipv6"]}, |
| 152 | "subnet-address": ip_prefix_schema, |
| 153 | "gateway-address": ip_schema, |
| 154 | "dns-server": ip_profile_dns_schema, |
| 155 | "dhcp-params": ip_profile_dhcp_schema, |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | ip_profile_update_schema = { |
| 160 | "title": "ip profile validation schame", |
| 161 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 162 | "type": "object", |
| 163 | "properties": { |
| 164 | "ip-version": {"enum": ["ipv4", "ipv6"]}, |
| 165 | "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]}, |
| 166 | "gateway-address": {"oneOf": [null_schema, ip_schema]}, |
| 167 | "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]}, |
| 168 | |
| 169 | "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]}, |
| 170 | }, |
| 171 | "additionalProperties": False |
| 172 | } |
| 173 | |
| 174 | ns_instantiate_internal_vld = { |
| 175 | "title": "ns action instantiate input schema for vdu", |
| 176 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 177 | "type": "object", |
| 178 | "properties": { |
| 179 | "name": name_schema, |
| 180 | "vim-network-name": name_schema, |
| gcalvino | 17d5b73 | 2018-12-17 16:26:21 +0100 | [diff] [blame] | 181 | "vim-network-id": name_schema, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 182 | "ip-profile": ip_profile_update_schema, |
| 183 | "internal-connection-point": { |
| 184 | "type": "array", |
| 185 | "minItems": 1, |
| 186 | "items": { |
| 187 | "type": "object", |
| 188 | "properties": { |
| 189 | "id-ref": name_schema, |
| 190 | "ip-address": ip_schema, |
| tierno | b7c6f2a | 2018-09-03 14:32:10 +0200 | [diff] [blame] | 191 | # "mac-address": mac_schema, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 192 | }, |
| tierno | b7c6f2a | 2018-09-03 14:32:10 +0200 | [diff] [blame] | 193 | "required": ["id-ref"], |
| 194 | "minProperties": 2, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 195 | "additionalProperties": False |
| 196 | }, |
| 197 | } |
| 198 | }, |
| 199 | "required": ["name"], |
| 200 | "minProperties": 2, |
| 201 | "additionalProperties": False |
| 202 | } |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 203 | |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 204 | additional_params_for_vnf = { |
| 205 | "type": "array", |
| 206 | "items": { |
| 207 | "type": "object", |
| 208 | "properties": { |
| 209 | "member-vnf-index": name_schema, |
| 210 | "additionalParams": object_schema, |
| 211 | }, |
| 212 | "required": ["member-vnf-index", "additionalParams"], |
| 213 | "additionalProperties": False |
| 214 | } |
| 215 | |
| 216 | } |
| 217 | |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 218 | ns_instantiate = { |
| 219 | "title": "ns action instantiate input schema", |
| 220 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 221 | "type": "object", |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 222 | "properties": { |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 223 | "lcmOperationType": string_schema, |
| 224 | "nsInstanceId": id_schema, |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 225 | "netsliceInstanceId": id_schema, |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 226 | "nsName": name_schema, |
| tierno | 4f9d4ae | 2019-03-20 17:24:11 +0000 | [diff] [blame] | 227 | "nsDescription": {"oneOf": [description_schema, null_schema]}, |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 228 | "nsdId": id_schema, |
| 229 | "vimAccountId": id_schema, |
| tierno | 4f9d4ae | 2019-03-20 17:24:11 +0000 | [diff] [blame] | 230 | "wimAccountId": {"OneOf": [id_schema, bool_schema, null_schema]}, |
| tierno | bee085c | 2018-12-12 17:03:04 +0000 | [diff] [blame] | 231 | "additionalParamsForNs": object_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 232 | "additionalParamsForVnf": additional_params_for_vnf, |
| tierno | fc5089c | 2018-10-31 09:28:11 +0100 | [diff] [blame] | 233 | "ssh_keys": {"type": "array", "items": {"type": "string"}}, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 234 | "nsr_id": id_schema, |
| tierno | cc10343 | 2018-10-19 14:10:35 +0200 | [diff] [blame] | 235 | "vduImage": name_schema, |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 236 | "vnf": { |
| 237 | "type": "array", |
| 238 | "minItems": 1, |
| 239 | "items": { |
| 240 | "type": "object", |
| 241 | "properties": { |
| 242 | "member-vnf-index": name_schema, |
| 243 | "vimAccountId": id_schema, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 244 | "vdu": { |
| 245 | "type": "array", |
| 246 | "minItems": 1, |
| 247 | "items": ns_instantiate_vdu, |
| 248 | }, |
| 249 | "internal-vld": { |
| 250 | "type": "array", |
| 251 | "minItems": 1, |
| 252 | "items": ns_instantiate_internal_vld |
| 253 | } |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 254 | }, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 255 | "required": ["member-vnf-index"], |
| 256 | "minProperties": 2, |
| 257 | "additionalProperties": False |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 258 | } |
| 259 | }, |
| 260 | "vld": { |
| 261 | "type": "array", |
| 262 | "minItems": 1, |
| 263 | "items": { |
| 264 | "type": "object", |
| 265 | "properties": { |
| 266 | "name": string_schema, |
| 267 | "vim-network-name": {"OneOf": [string_schema, object_schema]}, |
| gcalvino | 17d5b73 | 2018-12-17 16:26:21 +0100 | [diff] [blame] | 268 | "vim-network-id": {"OneOf": [string_schema, object_schema]}, |
| Felipe Vicens | 09e6542 | 2019-01-22 15:06:46 +0100 | [diff] [blame] | 269 | "ns-net": object_schema, |
| tierno | 4f9d4ae | 2019-03-20 17:24:11 +0000 | [diff] [blame] | 270 | "wimAccountId": {"OneOf": [id_schema, bool_schema, null_schema]}, |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 271 | "ip-profile": object_schema, |
| tierno | b7c6f2a | 2018-09-03 14:32:10 +0200 | [diff] [blame] | 272 | "vnfd-connection-point-ref": { |
| 273 | "type": "array", |
| 274 | "minItems": 1, |
| 275 | "items": { |
| 276 | "type": "object", |
| 277 | "properties": { |
| 278 | "member-vnf-index-ref": name_schema, |
| 279 | "vnfd-connection-point-ref": name_schema, |
| 280 | "ip-address": ip_schema, |
| 281 | # "mac-address": mac_schema, |
| 282 | }, |
| 283 | "required": ["member-vnf-index-ref", "vnfd-connection-point-ref"], |
| 284 | "minProperties": 3, |
| 285 | "additionalProperties": False |
| 286 | }, |
| 287 | } |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 288 | }, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 289 | "required": ["name"], |
| 290 | "additionalProperties": False |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 291 | } |
| 292 | }, |
| 293 | }, |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 294 | "required": ["nsName", "nsdId", "vimAccountId"], |
| 295 | "additionalProperties": False |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 296 | } |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 297 | |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 298 | ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution |
| tierno | f759d82 | 2018-06-11 18:54:54 +0200 | [diff] [blame] | 299 | "title": "ns action input schema", |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 300 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 301 | "type": "object", |
| 302 | "properties": { |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 303 | "lcmOperationType": string_schema, |
| 304 | "nsInstanceId": id_schema, |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 305 | "member_vnf_index": name_schema, |
| 306 | "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future |
| tierno | 7ce1db9 | 2018-07-25 12:50:52 +0200 | [diff] [blame] | 307 | "vdu_id": name_schema, |
| tierno | f063705 | 2019-03-07 16:26:47 +0000 | [diff] [blame] | 308 | "vdu_count_index": integer0_schema, |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 309 | "primitive": name_schema, |
| 310 | "primitive_params": {"type": "object"}, |
| 311 | }, |
| tierno | f5298be | 2018-05-16 14:43:57 +0200 | [diff] [blame] | 312 | "required": ["primitive", "primitive_params"], # TODO add member_vnf_index |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 313 | "additionalProperties": False |
| 314 | } |
| tierno | f759d82 | 2018-06-11 18:54:54 +0200 | [diff] [blame] | 315 | ns_scale = { # TODO for the moment it is only VDU-scaling |
| 316 | "title": "ns scale input schema", |
| 317 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 318 | "type": "object", |
| 319 | "properties": { |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 320 | "lcmOperationType": string_schema, |
| 321 | "nsInstanceId": id_schema, |
| tierno | f759d82 | 2018-06-11 18:54:54 +0200 | [diff] [blame] | 322 | "scaleType": {"enum": ["SCALE_VNF"]}, |
| 323 | "scaleVnfData": { |
| 324 | "type": "object", |
| 325 | "properties": { |
| 326 | "vnfInstanceId": name_schema, |
| 327 | "scaleVnfType": {"enum": ["SCALE_OUT", 'SCALE_IN']}, |
| 328 | "scaleByStepData": { |
| 329 | "type": "object", |
| 330 | "properties": { |
| 331 | "scaling-group-descriptor": name_schema, |
| 332 | "member-vnf-index": name_schema, |
| 333 | "scaling-policy": name_schema, |
| 334 | }, |
| 335 | "required": ["scaling-group-descriptor", "member-vnf-index"], |
| 336 | "additionalProperties": False |
| 337 | }, |
| 338 | }, |
| 339 | "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId |
| 340 | "additionalProperties": False |
| 341 | }, |
| 342 | "scaleTime": time_schema, |
| 343 | }, |
| 344 | "required": ["scaleType", "scaleVnfData"], |
| 345 | "additionalProperties": False |
| 346 | } |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 347 | |
| 348 | |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 349 | schema_version = {"type": "string", "enum": ["1.0"]} |
| tierno | 55ba2e6 | 2018-12-11 17:22:22 +0000 | [diff] [blame] | 350 | schema_type = {"type": "string"} |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 351 | vim_account_edit_schema = { |
| 352 | "title": "vim_account edit input schema", |
| 353 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 354 | "type": "object", |
| 355 | "properties": { |
| 356 | "name": name_schema, |
| 357 | "description": description_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 358 | "type": shortname_schema, |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 359 | "vim": name_schema, |
| 360 | "datacenter": name_schema, |
| 361 | "vim_url": description_schema, |
| 362 | "vim_url_admin": description_schema, |
| 363 | "vim_tenant": name_schema, |
| 364 | "vim_tenant_name": name_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 365 | "vim_username": shortname_schema, |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 366 | "vim_password": passwd_schema, |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 367 | "config": {"type": "object"} |
| 368 | }, |
| 369 | "additionalProperties": False |
| 370 | } |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 371 | |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 372 | vim_account_new_schema = { |
| 373 | "title": "vim_account creation input schema", |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 374 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 375 | "type": "object", |
| 376 | "properties": { |
| 377 | "schema_version": schema_version, |
| 378 | "schema_type": schema_type, |
| 379 | "name": name_schema, |
| 380 | "description": description_schema, |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 381 | "vim": name_schema, |
| 382 | "datacenter": name_schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 383 | "vim_type": {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws"]}, |
| 384 | "vim_url": description_schema, |
| 385 | # "vim_url_admin": description_schema, |
| 386 | # "vim_tenant": name_schema, |
| 387 | "vim_tenant_name": name_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 388 | "vim_user": shortname_schema, |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 389 | "vim_password": passwd_schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 390 | "config": {"type": "object"} |
| 391 | }, |
| 392 | "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"], |
| 393 | "additionalProperties": False |
| 394 | } |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 395 | |
| tierno | 55ba2e6 | 2018-12-11 17:22:22 +0000 | [diff] [blame] | 396 | wim_account_edit_schema = { |
| 397 | "title": "wim_account edit input schema", |
| 398 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 399 | "type": "object", |
| 400 | "properties": { |
| 401 | "name": name_schema, |
| 402 | "description": description_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 403 | "type": shortname_schema, |
| tierno | 55ba2e6 | 2018-12-11 17:22:22 +0000 | [diff] [blame] | 404 | "wim": name_schema, |
| 405 | "wim_url": description_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 406 | "user": shortname_schema, |
| tierno | 55ba2e6 | 2018-12-11 17:22:22 +0000 | [diff] [blame] | 407 | "password": passwd_schema, |
| 408 | "config": {"type": "object"} |
| 409 | }, |
| 410 | "additionalProperties": False |
| 411 | } |
| 412 | |
| 413 | wim_account_new_schema = { |
| 414 | "title": "wim_account creation input schema", |
| 415 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 416 | "type": "object", |
| 417 | "properties": { |
| 418 | "schema_version": schema_version, |
| 419 | "schema_type": schema_type, |
| 420 | "name": name_schema, |
| 421 | "description": description_schema, |
| 422 | "wim": name_schema, |
| 423 | "wim_type": {"enum": ["tapi", "onos", "odl", "dynpac"]}, |
| 424 | "wim_url": description_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 425 | "user": shortname_schema, |
| tierno | 55ba2e6 | 2018-12-11 17:22:22 +0000 | [diff] [blame] | 426 | "password": passwd_schema, |
| tierno | f063705 | 2019-03-07 16:26:47 +0000 | [diff] [blame] | 427 | "config": { |
| 428 | "type": "object", |
| 429 | "patternProperties": { |
| 430 | ".": {"not": {"type": "null"}} |
| 431 | } |
| 432 | } |
| tierno | 55ba2e6 | 2018-12-11 17:22:22 +0000 | [diff] [blame] | 433 | }, |
| 434 | "required": ["name", "wim_url", "wim_type"], |
| 435 | "additionalProperties": False |
| 436 | } |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 437 | |
| 438 | sdn_properties = { |
| 439 | "name": name_schema, |
| tierno | cfb07c6 | 2018-05-10 18:30:51 +0200 | [diff] [blame] | 440 | "description": description_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 441 | "dpid": dpid_Schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 442 | "ip": ip_schema, |
| 443 | "port": port_schema, |
| 444 | "type": {"type": "string", "enum": ["opendaylight", "floodlight", "onos"]}, |
| 445 | "version": {"type": "string", "minLength": 1, "maxLength": 12}, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 446 | "user": shortname_schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 447 | "password": passwd_schema |
| 448 | } |
| 449 | sdn_new_schema = { |
| 450 | "title": "sdn controller information schema", |
| 451 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 452 | "type": "object", |
| 453 | "properties": sdn_properties, |
| 454 | "required": ["name", "port", 'ip', 'dpid', 'type'], |
| 455 | "additionalProperties": False |
| 456 | } |
| 457 | sdn_edit_schema = { |
| 458 | "title": "sdn controller update information schema", |
| 459 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 460 | "type": "object", |
| 461 | "properties": sdn_properties, |
| tierno | cfb07c6 | 2018-05-10 18:30:51 +0200 | [diff] [blame] | 462 | # "required": ["name", "port", 'ip', 'dpid', 'type'], |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 463 | "additionalProperties": False |
| 464 | } |
| 465 | sdn_port_mapping_schema = { |
| 466 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 467 | "title": "sdn port mapping information schema", |
| 468 | "type": "array", |
| 469 | "items": { |
| 470 | "type": "object", |
| 471 | "properties": { |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 472 | "compute_node": shortname_schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 473 | "ports": { |
| 474 | "type": "array", |
| 475 | "items": { |
| 476 | "type": "object", |
| 477 | "properties": { |
| tierno | 42fce59 | 2018-11-02 09:23:43 +0100 | [diff] [blame] | 478 | "pci": pci_extended_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 479 | "switch_port": shortname_schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 480 | "switch_mac": mac_schema |
| 481 | }, |
| 482 | "required": ["pci"] |
| 483 | } |
| 484 | } |
| 485 | }, |
| 486 | "required": ["compute_node", "ports"] |
| 487 | } |
| 488 | } |
| 489 | sdn_external_port_schema = { |
| 490 | "$schema": "http://json-schema.org/draft-04/schema#", |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 491 | "title": "External port information", |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 492 | "type": "object", |
| 493 | "properties": { |
| 494 | "port": {"type": "string", "minLength": 1, "maxLength": 60}, |
| 495 | "vlan": vlan_schema, |
| 496 | "mac": mac_schema |
| 497 | }, |
| 498 | "required": ["port"] |
| 499 | } |
| 500 | |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 501 | # PDUs |
| 502 | pdu_interface = { |
| 503 | "type": "object", |
| 504 | "properties": { |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 505 | "name": shortname_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 506 | "mgmt": bool_schema, |
| 507 | "type": {"enum": ["overlay", 'underlay']}, |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 508 | "ip-address": ip_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 509 | # TODO, add user, password, ssh-key |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 510 | "mac-address": mac_schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 511 | "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port |
| 512 | "vim-network-id": shortname_schema, |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 513 | # # provide this in case SDN assist must deal with this interface |
| 514 | # "switch-dpid": dpid_Schema, |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 515 | # "switch-port": shortname_schema, |
| 516 | # "switch-mac": shortname_schema, |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 517 | # "switch-vlan": vlan_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 518 | }, |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 519 | "required": ["name", "mgmt", "ip-address"], |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 520 | "additionalProperties": False |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 521 | } |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 522 | pdu_new_schema = { |
| 523 | "title": "pdu creation input schema", |
| 524 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 525 | "type": "object", |
| 526 | "properties": { |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 527 | "name": shortname_schema, |
| 528 | "type": shortname_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 529 | "description": description_schema, |
| 530 | "shared": bool_schema, |
| 531 | "vims": nameshort_list_schema, |
| 532 | "vim_accounts": nameshort_list_schema, |
| 533 | "interfaces": { |
| 534 | "type": "array", |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 535 | "items": pdu_interface, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 536 | "minItems": 1 |
| 537 | } |
| 538 | }, |
| 539 | "required": ["name", "type", "interfaces"], |
| 540 | "additionalProperties": False |
| 541 | } |
| 542 | |
| 543 | pdu_edit_schema = { |
| 544 | "title": "pdu edit input schema", |
| 545 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 546 | "type": "object", |
| 547 | "properties": { |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 548 | "name": shortname_schema, |
| 549 | "type": shortname_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 550 | "description": description_schema, |
| 551 | "shared": bool_schema, |
| garciadeblas | 84bdd55 | 2018-11-30 22:59:45 +0100 | [diff] [blame] | 552 | "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]}, |
| 553 | "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]}, |
| 554 | "interfaces": {"oneOf": [ |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 555 | array_edition_schema, |
| 556 | { |
| 557 | "type": "array", |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 558 | "items": pdu_interface, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 559 | "minItems": 1 |
| 560 | } |
| 561 | ]} |
| 562 | }, |
| 563 | "additionalProperties": False, |
| 564 | "minProperties": 1 |
| 565 | } |
| 566 | |
| 567 | # USERS |
| Eduardo Sousa | 5c01e19 | 2019-05-08 02:35:47 +0100 | [diff] [blame^] | 568 | project_role_mapping = { |
| 569 | "title": "", |
| 570 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 571 | "type": "object", |
| 572 | "properties": { |
| 573 | "project": shortname_schema, |
| 574 | "role": shortname_schema |
| 575 | }, |
| 576 | "required": ["project", "role"], |
| 577 | "additionalProperties": False |
| 578 | } |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 579 | user_new_schema = { |
| 580 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 581 | "title": "New user schema", |
| 582 | "type": "object", |
| 583 | "properties": { |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 584 | "username": shortname_schema, |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 585 | "password": passwd_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 586 | "projects": nameshort_list_schema, |
| Eduardo Sousa | 5c01e19 | 2019-05-08 02:35:47 +0100 | [diff] [blame^] | 587 | "project_role_mappings": { |
| 588 | "type": "array", |
| 589 | "items": project_role_mapping, |
| 590 | "minItems": 1 |
| 591 | }, |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 592 | }, |
| Eduardo Sousa | 5c01e19 | 2019-05-08 02:35:47 +0100 | [diff] [blame^] | 593 | "required": ["username", "password"], |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 594 | "additionalProperties": False |
| 595 | } |
| 596 | user_edit_schema = { |
| 597 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 598 | "title": "User edit schema for administrators", |
| 599 | "type": "object", |
| 600 | "properties": { |
| 601 | "password": passwd_schema, |
| 602 | "projects": { |
| garciadeblas | 84bdd55 | 2018-11-30 22:59:45 +0100 | [diff] [blame] | 603 | "oneOf": [ |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 604 | nameshort_list_schema, |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 605 | array_edition_schema |
| 606 | ] |
| 607 | }, |
| Eduardo Sousa | 5c01e19 | 2019-05-08 02:35:47 +0100 | [diff] [blame^] | 608 | "project_role_mappings": { |
| 609 | "type": "array", |
| 610 | "items": project_role_mapping, |
| 611 | "minItems": 1 |
| 612 | }, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 613 | }, |
| 614 | "minProperties": 1, |
| 615 | "additionalProperties": False |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | # PROJECTS |
| 619 | project_new_schema = { |
| 620 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 621 | "title": "New project schema for administrators", |
| 622 | "type": "object", |
| 623 | "properties": { |
| tierno | fd16057 | 2019-01-21 10:41:37 +0000 | [diff] [blame] | 624 | "name": shortname_schema, |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 625 | "admin": bool_schema, |
| 626 | }, |
| 627 | "required": ["name"], |
| 628 | "additionalProperties": False |
| 629 | } |
| 630 | project_edit_schema = { |
| 631 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 632 | "title": "Project edit schema for administrators", |
| 633 | "type": "object", |
| 634 | "properties": { |
| 635 | "admin": bool_schema, |
| 636 | }, |
| 637 | "additionalProperties": False, |
| 638 | "minProperties": 1 |
| 639 | } |
| 640 | |
| Eduardo Sousa | 5c01e19 | 2019-05-08 02:35:47 +0100 | [diff] [blame^] | 641 | # ROLES |
| 642 | roles_new_schema = { |
| 643 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 644 | "title": "New role schema for administrators", |
| 645 | "type": "object", |
| 646 | "properties": { |
| 647 | "name": shortname_schema, |
| 648 | "definition": object_schema, |
| 649 | }, |
| 650 | "required": ["name"], |
| 651 | "additionalProperties": False |
| 652 | } |
| 653 | roles_edit_schema = { |
| 654 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 655 | "title": "Roles edit schema for administrators", |
| 656 | "type": "object", |
| 657 | "properties": { |
| 658 | "_id": id_schema, |
| 659 | "name": shortname_schema, |
| 660 | "definition": object_schema, |
| 661 | }, |
| 662 | "required": ["_id", "name", "definition"], |
| 663 | "additionalProperties": False, |
| 664 | "minProperties": 1 |
| 665 | } |
| 666 | |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 667 | # GLOBAL SCHEMAS |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 668 | |
| 669 | nbi_new_input_schemas = { |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 670 | "users": user_new_schema, |
| 671 | "projects": project_new_schema, |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 672 | "vim_accounts": vim_account_new_schema, |
| tierno | 65acb4d | 2018-04-06 16:42:40 +0200 | [diff] [blame] | 673 | "sdns": sdn_new_schema, |
| 674 | "ns_instantiate": ns_instantiate, |
| 675 | "ns_action": ns_action, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 676 | "ns_scale": ns_scale, |
| 677 | "pdus": pdu_new_schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | nbi_edit_input_schemas = { |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 681 | "users": user_edit_schema, |
| 682 | "projects": project_edit_schema, |
| tierno | 09c073e | 2018-04-26 13:36:48 +0200 | [diff] [blame] | 683 | "vim_accounts": vim_account_edit_schema, |
| tierno | cb83c94 | 2018-09-24 17:28:13 +0200 | [diff] [blame] | 684 | "sdns": sdn_edit_schema, |
| 685 | "pdus": pdu_edit_schema, |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 686 | } |
| 687 | |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 688 | # NETSLICE SCHEMAS |
| tierno | 032916c | 2019-03-22 13:27:12 +0000 | [diff] [blame] | 689 | nsi_subnet_instantiate = deepcopy(ns_instantiate) |
| 690 | nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema" |
| 691 | nsi_subnet_instantiate["properties"]["id"] = name_schema |
| 692 | del nsi_subnet_instantiate["required"] |
| garciadeblas | daf8cc5 | 2018-11-30 14:17:20 +0100 | [diff] [blame] | 693 | |
| 694 | nsi_vld_instantiate = { |
| 695 | "title": "netslice vld instantiation params input schema", |
| 696 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 697 | "type": "object", |
| 698 | "properties": { |
| 699 | "name": string_schema, |
| 700 | "vim-network-name": {"OneOf": [string_schema, object_schema]}, |
| gcalvino | 17d5b73 | 2018-12-17 16:26:21 +0100 | [diff] [blame] | 701 | "vim-network-id": {"OneOf": [string_schema, object_schema]}, |
| garciadeblas | daf8cc5 | 2018-11-30 14:17:20 +0100 | [diff] [blame] | 702 | "ip-profile": object_schema, |
| 703 | }, |
| 704 | "required": ["name"], |
| 705 | "additionalProperties": False |
| 706 | } |
| 707 | |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 708 | nsi_instantiate = { |
| 709 | "title": "netslice action instantiate input schema", |
| 710 | "$schema": "http://json-schema.org/draft-04/schema#", |
| 711 | "type": "object", |
| 712 | "properties": { |
| 713 | "lcmOperationType": string_schema, |
| 714 | "nsiInstanceId": id_schema, |
| 715 | "nsiName": name_schema, |
| tierno | 4f9d4ae | 2019-03-20 17:24:11 +0000 | [diff] [blame] | 716 | "nsiDescription": {"oneOf": [description_schema, null_schema]}, |
| tierno | 9e5eea3 | 2018-11-29 09:42:09 +0000 | [diff] [blame] | 717 | "nstId": string_schema, |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 718 | "vimAccountId": id_schema, |
| 719 | "ssh_keys": {"type": "string"}, |
| 720 | "nsi_id": id_schema, |
| tierno | 032916c | 2019-03-22 13:27:12 +0000 | [diff] [blame] | 721 | "additionalParamsForNsi": object_schema, |
| garciadeblas | daf8cc5 | 2018-11-30 14:17:20 +0100 | [diff] [blame] | 722 | "netslice-subnet": { |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 723 | "type": "array", |
| 724 | "minItems": 1, |
| tierno | 032916c | 2019-03-22 13:27:12 +0000 | [diff] [blame] | 725 | "items": nsi_subnet_instantiate |
| garciadeblas | daf8cc5 | 2018-11-30 14:17:20 +0100 | [diff] [blame] | 726 | }, |
| 727 | "netslice-vld": { |
| 728 | "type": "array", |
| 729 | "minItems": 1, |
| 730 | "items": nsi_vld_instantiate |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 731 | }, |
| 732 | }, |
| Felipe Vicens | c8bbaaa | 2018-12-01 04:42:40 +0100 | [diff] [blame] | 733 | "required": ["nsiName", "nstId", "vimAccountId"], |
| Felipe Vicens | 07f3172 | 2018-10-29 15:16:44 +0100 | [diff] [blame] | 734 | "additionalProperties": False |
| 735 | } |
| 736 | |
| 737 | nsi_action = { |
| 738 | |
| 739 | } |
| 740 | |
| 741 | nsi_terminate = { |
| 742 | |
| 743 | } |
| 744 | |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 745 | |
| 746 | class ValidationError(Exception): |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 747 | def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY): |
| 748 | self.http_code = http_code |
| 749 | Exception.__init__(self, message) |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 750 | |
| 751 | |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 752 | def validate_input(indata, schema_to_use): |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 753 | """ |
| tierno | cd54a4a | 2018-09-12 16:40:35 +0200 | [diff] [blame] | 754 | Validates input data against json schema |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 755 | :param indata: user input data. Should be a dictionary |
| tierno | b24258a | 2018-10-04 18:39:49 +0200 | [diff] [blame] | 756 | :param schema_to_use: jsonschema to test |
| 757 | :return: None if ok, raises ValidationError exception on error |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 758 | """ |
| 759 | try: |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 760 | if schema_to_use: |
| 761 | js_v(indata, schema_to_use) |
| 762 | return None |
| 763 | except js_e.ValidationError as e: |
| 764 | if e.path: |
| tierno | 0da5225 | 2018-06-27 15:47:22 +0200 | [diff] [blame] | 765 | error_pos = "at '" + ":".join(map(str, e.path)) + "'" |
| tierno | 0f98af5 | 2018-03-19 10:28:22 +0100 | [diff] [blame] | 766 | else: |
| 767 | error_pos = "" |
| tierno | 441dbbf | 2018-07-10 12:52:48 +0200 | [diff] [blame] | 768 | raise ValidationError("Format error {} '{}' ".format(error_pos, e.message)) |
| tierno | 36ec860 | 2018-11-02 17:27:11 +0100 | [diff] [blame] | 769 | except js_e.SchemaError: |
| 770 | raise ValidationError("Bad json schema {}".format(schema_to_use), http_code=HTTPStatus.INTERNAL_SERVER_ERROR) |