Coverage for osm_nbi/validation.py: 99%

161 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-10 20:04 +0000

1# -*- coding: utf-8 -*- 

2 

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 

16from jsonschema import validate as js_v, exceptions as js_e 

17from http import HTTPStatus 

18from copy import deepcopy 

19from uuid import UUID # To test for valid UUID 

20 

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 = "^[ -~]+$" 

31shortname_schema = { 

32 "type": "string", 

33 "minLength": 1, 

34 "maxLength": 60, 

35 "pattern": "^[^,;()\\.\\$'\"]+$", 

36} 

37passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60} 

38user_passwd_schema = { 

39 "type": "string", 

40 "pattern": "^.*(?=.{8,})((?=.*[!@#$%^&*()\\-_=+{};:,<.>]){1})(?=.*\\d)((?=.*[a-z]){1})((?=.*[A-Z]){1}).*$", 

41} 

42name_schema = { 

43 "type": "string", 

44 "minLength": 1, 

45 "maxLength": 255, 

46 "pattern": "^[^,;()'\"]+$", 

47} 

48string_schema = {"type": "string", "minLength": 1, "maxLength": 255} 

49email_schema = { 

50 "type": "string", 

51 "minLength": 1, 

52 "maxLength": 320, 

53 "pattern": "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$", 

54} 

55xml_text_schema = { 

56 "type": "string", 

57 "minLength": 1, 

58 "maxLength": 1000, 

59 "pattern": "^[^']+$", 

60} 

61description_schema = { 

62 "type": ["string", "null"], 

63 "maxLength": 255, 

64 "pattern": "^[^'\"]+$", 

65} 

66long_description_schema = { 

67 "type": ["string", "null"], 

68 "maxLength": 3000, 

69 "pattern": "^[^'\"]+$", 

70} 

71id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36} 

72bool_schema = {"type": "boolean"} 

73null_schema = {"type": "null"} 

74# "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}$" 

75id_schema = { 

76 "type": "string", 

77 "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$", 

78} 

79time_schema = { 

80 "type": "string", 

81 "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]([0-5]:){2}", 

82} 

83pci_schema = { 

84 "type": "string", 

85 "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\\.[0-9a-fA-F]$", 

86} 

87# allows [] for wildcards. For that reason huge length limit is set 

88pci_extended_schema = {"type": "string", "pattern": "^[0-9a-fA-F.:-\\[\\]]{12,40}$"} 

89http_schema = {"type": "string", "pattern": "^(https?|http)://[^'\"=]+$"} 

90bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"} 

91memory_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]i?[Bb])?$"} 

92integer0_schema = {"type": "integer", "minimum": 0} 

93integer1_schema = {"type": "integer", "minimum": 1} 

94path_schema = {"type": "string", "pattern": "^(\\.){0,2}(/[^/\"':{}\\(\\)]+)+$"} 

95vlan_schema = {"type": "integer", "minimum": 1, "maximum": 4095} 

96vlan1000_schema = {"type": "integer", "minimum": 1000, "maximum": 4095} 

97mac_schema = { 

98 "type": "string", 

99 "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$", 

100} # must be unicast: LSB bit of MSB byte ==0 

101dpid_Schema = {"type": "string", "pattern": "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$"} 

102# mac_schema={"type":"string", "pattern":"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"} 

103ip_schema = { 

104 "type": "string", 

105 "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]?)$", 

106} 

107ipv6_schema = { 

108 "type": "string", 

109 "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]))", # noqa: W605 

110} 

111ip_prefix_schema = { 

112 "type": "string", 

113 "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" 

114 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(30|[12]?[0-9])$", 

115} 

116port_schema = {"type": "integer", "minimum": 1, "maximum": 65534} 

117object_schema = {"type": "object"} 

118schema_version_2 = {"type": "integer", "minimum": 2, "maximum": 2} 

119# schema_version_string={"type":"string","enum": ["0.1", "2", "0.2", "3", "0.3"]} 

120log_level_schema = { 

121 "type": "string", 

122 "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], 

123} 

124checksum_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{32}$"} 

125size_schema = {"type": "integer", "minimum": 1, "maximum": 100} 

126array_edition_schema = { 

127 "type": "object", 

128 "patternProperties": {"^\\$": {}}, 

129 "additionalProperties": False, 

130 "minProperties": 1, 

131} 

132nameshort_list_schema = { 

133 "type": "array", 

134 "minItems": 1, 

135 "items": shortname_schema, 

136} 

137 

138description_list_schema = { 

139 "type": "array", 

140 "minItems": 1, 

141 "items": description_schema, 

142} 

143 

144profile_type_schema = { 

145 "type": "string", 

146 "enum": [ 

147 "infra_controller_profiles", 

148 "infra_config_profiles", 

149 "app_profiles", 

150 "resource_profiles", 

151 ], 

152} 

153 

154ns_instantiate_vdu = { 

155 "title": "ns action instantiate input schema for vdu", 

156 "$schema": "http://json-schema.org/draft-04/schema#", 

157 "type": "object", 

158 "properties": { 

159 "id": name_schema, 

160 "vim-flavor-id": name_schema, 

161 "instance_name": name_schema, 

162 "vim-flavor-name": name_schema, 

163 "security-group-name": name_schema, 

164 "volume": { 

165 "type": "array", 

166 "minItems": 1, 

167 "items": { 

168 "type": "object", 

169 "properties": { 

170 "name": name_schema, 

171 "vim-volume-id": name_schema, 

172 }, 

173 "required": ["name", "vim-volume-id"], 

174 "additionalProperties": False, 

175 }, 

176 }, 

177 "interface": { 

178 "type": "array", 

179 "minItems": 1, 

180 "items": { 

181 "type": "object", 

182 "properties": { 

183 "name": name_schema, 

184 "ip-address": {"oneOf": [ip_schema, ipv6_schema]}, 

185 "mac-address": mac_schema, 

186 "floating-ip-required": bool_schema, 

187 }, 

188 "required": ["name"], 

189 "additionalProperties": False, 

190 }, 

191 }, 

192 }, 

193 "required": ["id"], 

194 "additionalProperties": False, 

195} 

196 

197ip_profile_dns_schema = { 

198 "type": "array", 

199 "minItems": 1, 

200 "items": { 

201 "type": "object", 

202 "properties": { 

203 "address": {"oneOf": [ip_schema, ipv6_schema]}, 

204 }, 

205 "required": ["address"], 

206 "additionalProperties": False, 

207 }, 

208} 

209 

210ip_profile_dhcp_schema = { 

211 "type": "object", 

212 "properties": { 

213 "enabled": {"type": "boolean"}, 

214 "count": integer1_schema, 

215 "start-address": ip_schema, 

216 }, 

217 "additionalProperties": False, 

218} 

219 

220ip_profile_schema = { 

221 "title": "ip profile validation schema", 

222 "$schema": "http://json-schema.org/draft-04/schema#", 

223 "type": "object", 

224 "properties": { 

225 "ip-version": {"enum": ["ipv4", "ipv6"]}, 

226 "subnet-address": {"oneOf": [null_schema, ip_prefix_schema]}, 

227 "gateway-address": {"oneOf": [null_schema, ip_schema]}, 

228 "dns-server": {"oneOf": [null_schema, ip_profile_dns_schema]}, 

229 "dhcp-params": {"oneOf": [null_schema, ip_profile_dhcp_schema]}, 

230 }, 

231 "additionalProperties": False, 

232} 

233 

234provider_network_schema = { 

235 "title": "provider network validation schema", 

236 "$schema": "http://json-schema.org/draft-04/schema#", 

237 "type": "object", 

238 "properties": { 

239 "physical-network": name_schema, 

240 "segmentation-id": name_schema, 

241 "sdn-ports": { # external ports to append to the SDN-assist network 

242 "type": "array", 

243 "items": { 

244 "type": "object", 

245 "properties": { 

246 "switch_id": shortname_schema, 

247 "switch_port": shortname_schema, 

248 "mac_address": mac_schema, 

249 "vlan": vlan_schema, 

250 }, 

251 "additionalProperties": True, 

252 }, 

253 }, 

254 "network-type": shortname_schema, 

255 }, 

256 "additionalProperties": True, 

257} 

258 

259ns_instantiate_internal_vld = { 

260 "title": "ns action instantiate input schema for vld", 

261 "$schema": "http://json-schema.org/draft-04/schema#", 

262 "type": "object", 

263 "properties": { 

264 "name": name_schema, 

265 "vim-network-name": name_schema, 

266 "vim-network-id": name_schema, 

267 "ip-profile": ip_profile_schema, 

268 "provider-network": provider_network_schema, 

269 "internal-connection-point": { 

270 "type": "array", 

271 "minItems": 1, 

272 "items": { 

273 "type": "object", 

274 "properties": { 

275 "id-ref": name_schema, 

276 "ip-address": ip_schema, 

277 # "mac-address": mac_schema, 

278 }, 

279 "required": ["id-ref"], 

280 "minProperties": 2, 

281 "additionalProperties": False, 

282 }, 

283 }, 

284 }, 

285 "required": ["name"], 

286 "minProperties": 2, 

287 "additionalProperties": False, 

288} 

289 

290additional_params_for_vnf = { 

291 "type": "array", 

292 "items": { 

293 "type": "object", 

294 "properties": { 

295 "member-vnf-index": name_schema, 

296 "additionalParams": object_schema, 

297 "k8s-namespace": name_schema, 

298 "config-units": integer1_schema, # number of configuration units of this vnf, by default 1 

299 "additionalParamsForVdu": { 

300 "type": "array", 

301 "items": { 

302 "type": "object", 

303 "properties": { 

304 "vdu_id": name_schema, 

305 "additionalParams": object_schema, 

306 "config-units": integer1_schema, # number of configuration units of this vdu, by default 1 

307 }, 

308 "required": ["vdu_id"], 

309 "minProperties": 2, 

310 "additionalProperties": False, 

311 }, 

312 }, 

313 "additionalParamsForKdu": { 

314 "type": "array", 

315 "items": { 

316 "type": "object", 

317 "properties": { 

318 "kdu_name": name_schema, 

319 "additionalParams": object_schema, 

320 "kdu_model": name_schema, 

321 "k8s-namespace": name_schema, 

322 "config-units": integer1_schema, # number of configuration units of this knf, by default 1 

323 "kdu-deployment-name": name_schema, 

324 }, 

325 "required": ["kdu_name"], 

326 "minProperties": 2, 

327 "additionalProperties": False, 

328 }, 

329 }, 

330 "affinity-or-anti-affinity-group": { 

331 "type": "array", 

332 "items": { 

333 "type": "object", 

334 "properties": { 

335 "id": name_schema, 

336 "vim-affinity-group-id": name_schema, 

337 }, 

338 "required": ["id"], 

339 "minProperties": 2, 

340 "additionalProperties": False, 

341 }, 

342 }, 

343 }, 

344 "required": ["member-vnf-index"], 

345 "minProperties": 2, 

346 "additionalProperties": False, 

347 }, 

348} 

349 

350vnf_schema = { 

351 "type": "array", 

352 "minItems": 1, 

353 "items": { 

354 "type": "object", 

355 "properties": { 

356 "member-vnf-index": name_schema, 

357 "vimAccountId": id_schema, 

358 "vdu": { 

359 "type": "array", 

360 "minItems": 1, 

361 "items": ns_instantiate_vdu, 

362 }, 

363 "internal-vld": { 

364 "type": "array", 

365 "minItems": 1, 

366 "items": ns_instantiate_internal_vld, 

367 }, 

368 }, 

369 "required": ["member-vnf-index"], 

370 "minProperties": 2, 

371 "additionalProperties": False, 

372 }, 

373} 

374 

375vld_schema = { 

376 "type": "array", 

377 "minItems": 1, 

378 "items": { 

379 "type": "object", 

380 "properties": { 

381 "name": string_schema, 

382 "vim-network-name": {"oneOf": [string_schema, object_schema]}, 

383 "vim-network-id": {"oneOf": [string_schema, object_schema]}, 

384 "ns-net": object_schema, 

385 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]}, 

386 "ip-profile": ip_profile_schema, 

387 "provider-network": provider_network_schema, 

388 "vnfd-connection-point-ref": { 

389 "type": "array", 

390 "minItems": 1, 

391 "items": { 

392 "type": "object", 

393 "properties": { 

394 "member-vnf-index-ref": name_schema, 

395 "vnfd-connection-point-ref": name_schema, 

396 "ip-address": {"oneOf": [ip_schema, ipv6_schema]}, 

397 # "mac-address": mac_schema, 

398 }, 

399 "required": [ 

400 "member-vnf-index-ref", 

401 "vnfd-connection-point-ref", 

402 ], 

403 "minProperties": 3, 

404 "additionalProperties": False, 

405 }, 

406 }, 

407 }, 

408 "required": ["name"], 

409 "additionalProperties": False, 

410 }, 

411} 

412 

413ns_config_template = { 

414 "title": " ns config template input schema", 

415 "$schema": "http://json-schema.org/draft-04/schema#", 

416 "type": "object", 

417 "properties": { 

418 "name": string_schema, 

419 "nsdId": id_schema, 

420 "config": object_schema, 

421 }, 

422 "required": ["name", "nsdId", "config"], 

423 "additionalProperties": False, 

424} 

425 

426ns_instantiate = { 

427 "title": "ns action instantiate input schema", 

428 "$schema": "http://json-schema.org/draft-04/schema#", 

429 "type": "object", 

430 "properties": { 

431 "lcmOperationType": string_schema, 

432 "nsInstanceId": id_schema, 

433 "netsliceInstanceId": id_schema, 

434 "nsName": name_schema, 

435 "nsDescription": {"oneOf": [description_schema, null_schema]}, 

436 "nsdId": id_schema, 

437 "vimAccountId": id_schema, 

438 "nsConfigTemplateId": id_schema, 

439 "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]}, 

440 "placement-engine": string_schema, 

441 "placement-constraints": object_schema, 

442 "additionalParamsForNs": object_schema, 

443 "additionalParamsForVnf": additional_params_for_vnf, 

444 "config-units": integer1_schema, # number of configuration units of this ns, by default 1 

445 "k8s-namespace": name_schema, 

446 "ssh_keys": {"type": "array", "items": {"type": "string"}}, 

447 "timeout_ns_deploy": integer1_schema, 

448 "nsr_id": id_schema, 

449 "vduImage": name_schema, 

450 "vnf": vnf_schema, 

451 "vld": vld_schema, 

452 }, 

453 "required": ["nsName", "nsdId", "vimAccountId"], 

454 "additionalProperties": False, 

455} 

456 

457ns_terminate = { 

458 "title": "ns terminate input schema", 

459 "$schema": "http://json-schema.org/draft-04/schema#", 

460 "type": "object", 

461 "properties": { 

462 "lcmOperationType": string_schema, 

463 "nsInstanceId": id_schema, 

464 "autoremove": bool_schema, 

465 "timeout_ns_terminate": integer1_schema, 

466 "skip_terminate_primitives": bool_schema, 

467 "netsliceInstanceId": id_schema, 

468 }, 

469 "additionalProperties": False, 

470} 

471 

472ns_update = { 

473 "title": "ns update input schema", 

474 "$schema": "http://json-schema.org/draft-04/schema#", 

475 "type": "object", 

476 "properties": { 

477 "lcmOperationType": string_schema, 

478 "nsInstanceId": id_schema, 

479 "timeout_ns_update": integer1_schema, 

480 "updateType": { 

481 "enum": [ 

482 "CHANGE_VNFPKG", 

483 "REMOVE_VNF", 

484 "MODIFY_VNF_INFORMATION", 

485 "OPERATE_VNF", 

486 "VERTICAL_SCALE", 

487 ] 

488 }, 

489 "modifyVnfInfoData": { 

490 "type": "object", 

491 "properties": { 

492 "vnfInstanceId": id_schema, 

493 "vnfdId": id_schema, 

494 }, 

495 "required": ["vnfInstanceId", "vnfdId"], 

496 }, 

497 "removeVnfInstanceId": id_schema, 

498 "changeVnfPackageData": { 

499 "type": "object", 

500 "properties": { 

501 "vnfInstanceId": id_schema, 

502 "vnfdId": id_schema, 

503 }, 

504 "required": ["vnfInstanceId", "vnfdId"], 

505 }, 

506 "operateVnfData": { 

507 "type": "object", 

508 "properties": { 

509 "vnfInstanceId": id_schema, 

510 "changeStateTo": name_schema, 

511 "additionalParam": { 

512 "type": "object", 

513 "properties": { 

514 "run-day1": bool_schema, 

515 "vdu_id": name_schema, 

516 "count-index": integer0_schema, 

517 }, 

518 "required": ["vdu_id", "count-index"], 

519 "additionalProperties": False, 

520 }, 

521 }, 

522 "required": ["vnfInstanceId", "changeStateTo"], 

523 }, 

524 "verticalScaleVnf": { 

525 "type": "object", 

526 "properties": { 

527 "vnfInstanceId": id_schema, 

528 "vnfdId": id_schema, 

529 "vduId": name_schema, 

530 "countIndex": integer0_schema, 

531 }, 

532 "required": ["vnfInstanceId", "vnfdId", "vduId"], 

533 }, 

534 }, 

535 "required": ["updateType"], 

536 "additionalProperties": False, 

537} 

538 

539ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution 

540 "title": "ns action input schema", 

541 "$schema": "http://json-schema.org/draft-04/schema#", 

542 "type": "object", 

543 "properties": { 

544 "lcmOperationType": string_schema, 

545 "nsInstanceId": id_schema, 

546 "member_vnf_index": name_schema, 

547 "vnf_member_index": name_schema, # TODO for backward compatibility. To remove in future 

548 "vdu_id": name_schema, 

549 "vdu_count_index": integer0_schema, 

550 "kdu_name": name_schema, 

551 "primitive": name_schema, 

552 "timeout_ns_action": integer1_schema, 

553 "primitive_params": {"type": "object"}, 

554 }, 

555 "required": ["primitive", "primitive_params"], # TODO add member_vnf_index 

556 "additionalProperties": False, 

557} 

558 

559ns_scale = { # TODO for the moment it is only VDU-scaling 

560 "title": "ns scale input schema", 

561 "$schema": "http://json-schema.org/draft-04/schema#", 

562 "type": "object", 

563 "properties": { 

564 "lcmOperationType": string_schema, 

565 "nsInstanceId": id_schema, 

566 "scaleType": {"enum": ["SCALE_VNF"]}, 

567 "timeout_ns_scale": integer1_schema, 

568 "scaleVnfData": { 

569 "type": "object", 

570 "properties": { 

571 "vnfInstanceId": name_schema, 

572 "scaleVnfType": {"enum": ["SCALE_OUT", "SCALE_IN"]}, 

573 "scaleByStepData": { 

574 "type": "object", 

575 "properties": { 

576 "scaling-group-descriptor": name_schema, 

577 "member-vnf-index": name_schema, 

578 "scaling-policy": name_schema, 

579 }, 

580 "required": ["scaling-group-descriptor", "member-vnf-index"], 

581 "additionalProperties": False, 

582 }, 

583 }, 

584 "required": ["scaleVnfType", "scaleByStepData"], # vnfInstanceId 

585 "additionalProperties": False, 

586 }, 

587 "scaleTime": time_schema, 

588 }, 

589 "required": ["scaleType", "scaleVnfData"], 

590 "additionalProperties": False, 

591} 

592 

593ns_migrate = { 

594 "title": "ns migrate input schema", 

595 "$schema": "http://json-schema.org/draft-04/schema#", 

596 "type": "object", 

597 "properties": { 

598 "lcmOperationType": string_schema, 

599 "nsInstanceId": id_schema, 

600 "vnfInstanceId": id_schema, 

601 "migrateToHost": string_schema, 

602 "targetHostK8sLabels": object_schema, 

603 "vdu": { 

604 "type": "object", 

605 "properties": { 

606 "vduId": name_schema, 

607 "vduCountIndex": integer0_schema, 

608 }, 

609 "required": ["vduId"], 

610 "additionalProperties": False, 

611 }, 

612 }, 

613 "required": ["vnfInstanceId"], 

614 "additionalProperties": False, 

615} 

616 

617ns_heal = { 

618 "title": "ns heal input schema", 

619 "$schema": "http://json-schema.org/draft-04/schema#", 

620 "type": "object", 

621 "properties": { 

622 "lcmOperationType": string_schema, 

623 "nsInstanceId": id_schema, 

624 "timeout_ns_heal": integer1_schema, 

625 "healVnfData": { 

626 "type": "array", 

627 "items": { 

628 "type": "object", 

629 "properties": { 

630 "vnfInstanceId": id_schema, 

631 "cause": description_schema, 

632 "additionalParams": { 

633 "type": "object", 

634 "properties": { 

635 "run-day1": bool_schema, 

636 "vdu": { 

637 "type": "array", 

638 "items": { 

639 "type": "object", 

640 "properties": { 

641 "run-day1": bool_schema, 

642 "vdu-id": name_schema, 

643 "count-index": integer0_schema, 

644 }, 

645 "required": ["vdu-id"], 

646 "additionalProperties": False, 

647 }, 

648 }, 

649 }, 

650 "additionalProperties": False, 

651 }, 

652 }, 

653 "required": ["vnfInstanceId"], 

654 "additionalProperties": False, 

655 }, 

656 }, 

657 }, 

658 "required": ["healVnfData"], 

659 "additionalProperties": False, 

660} 

661 

662nslcmop_cancel = { 

663 "title": "Cancel nslcmop input schema", 

664 "$schema": "http://json-schema.org/draft-04/schema#", 

665 "type": "object", 

666 "properties": { 

667 "nsLcmOpOccId": id_schema, 

668 "cancelMode": { 

669 "enum": [ 

670 "GRACEFUL", 

671 "FORCEFUL", 

672 ] 

673 }, 

674 }, 

675 "required": ["cancelMode"], 

676 "additionalProperties": False, 

677} 

678 

679schema_version = {"type": "string", "enum": ["1.0"]} 

680schema_type = {"type": "string"} 

681vim_type = shortname_schema # {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws", "azure", "fos"]} 

682 

683vim_account_edit_schema = { 

684 "title": "vim_account edit input schema", 

685 "$schema": "http://json-schema.org/draft-04/schema#", 

686 "type": "object", 

687 "properties": { 

688 "name": name_schema, 

689 "description": description_schema, 

690 "vim": name_schema, 

691 "datacenter": name_schema, 

692 "vim_type": vim_type, 

693 "vim_url": description_schema, 

694 # "vim_url_admin": description_schema, 

695 # "vim_tenant": name_schema, 

696 "vim_tenant_name": name_schema, 

697 "vim_user": string_schema, 

698 "vim_password": passwd_schema, 

699 "vca": id_schema, 

700 "config": {"type": "object"}, 

701 "prometheus-config": {"type": "object"}, 

702 }, 

703 "additionalProperties": False, 

704} 

705 

706vim_account_new_schema = { 

707 "title": "vim_account creation input schema", 

708 "$schema": "http://json-schema.org/draft-04/schema#", 

709 "type": "object", 

710 "properties": { 

711 "schema_version": schema_version, 

712 "schema_type": schema_type, 

713 "name": name_schema, 

714 "description": description_schema, 

715 "vim": name_schema, 

716 "datacenter": name_schema, 

717 "vim_type": vim_type, 

718 "vim_url": description_schema, 

719 # "vim_url_admin": description_schema, 

720 # "vim_tenant": name_schema, 

721 "vim_tenant_name": name_schema, 

722 "vim_user": string_schema, 

723 "vim_password": passwd_schema, 

724 "vca": id_schema, 

725 "config": {"type": "object"}, 

726 "prometheus-config": {"type": "object"}, 

727 }, 

728 "required": [ 

729 "name", 

730 "vim_url", 

731 "vim_type", 

732 "vim_user", 

733 "vim_password", 

734 "vim_tenant_name", 

735 ], 

736 "additionalProperties": False, 

737} 

738 

739wim_type = shortname_schema # {"enum": ["ietfl2vpn", "onos", "odl", "dynpac", "fake"]} 

740 

741wim_account_edit_schema = { 

742 "title": "wim_account edit input schema", 

743 "$schema": "http://json-schema.org/draft-04/schema#", 

744 "type": "object", 

745 "properties": { 

746 "name": name_schema, 

747 "description": description_schema, 

748 "wim": name_schema, 

749 "wim_type": wim_type, 

750 "wim_url": description_schema, 

751 "user": string_schema, 

752 "password": passwd_schema, 

753 "config": {"type": "object"}, 

754 }, 

755 "additionalProperties": False, 

756} 

757 

758wim_account_new_schema = { 

759 "title": "wim_account creation input schema", 

760 "$schema": "http://json-schema.org/draft-04/schema#", 

761 "type": "object", 

762 "properties": { 

763 "schema_version": schema_version, 

764 "schema_type": schema_type, 

765 "name": name_schema, 

766 "description": description_schema, 

767 "wim": name_schema, 

768 "wim_type": wim_type, 

769 "wim_url": description_schema, 

770 "user": string_schema, 

771 "password": passwd_schema, 

772 "config": { 

773 "type": "object", 

774 "patternProperties": {".": {"not": {"type": "null"}}}, 

775 }, 

776 }, 

777 "required": ["name", "wim_url", "wim_type"], 

778 "additionalProperties": False, 

779} 

780 

781sdn_properties = { 

782 "name": name_schema, 

783 "type": {"type": "string"}, 

784 "url": {"type": "string"}, 

785 "user": string_schema, 

786 "password": passwd_schema, 

787 "config": {"type": "object"}, 

788 "description": description_schema, 

789 # The folowing are deprecated. Maintanied for backward compatibility 

790 "dpid": dpid_Schema, 

791 "ip": ip_schema, 

792 "port": port_schema, 

793 "version": {"type": "string", "minLength": 1, "maxLength": 12}, 

794} 

795sdn_new_schema = { 

796 "title": "sdn controller information schema", 

797 "$schema": "http://json-schema.org/draft-04/schema#", 

798 "type": "object", 

799 "properties": sdn_properties, 

800 "required": ["name", "type"], 

801 "additionalProperties": False, 

802} 

803sdn_edit_schema = { 

804 "title": "sdn controller update information schema", 

805 "$schema": "http://json-schema.org/draft-04/schema#", 

806 "type": "object", 

807 "properties": sdn_properties, 

808 # "required": ["name", "port", 'ip', 'dpid', 'type'], 

809 "additionalProperties": False, 

810} 

811sdn_port_mapping_schema = { 

812 "$schema": "http://json-schema.org/draft-04/schema#", 

813 "title": "sdn port mapping information schema", 

814 "type": "array", 

815 "items": { 

816 "type": "object", 

817 "properties": { 

818 "compute_node": shortname_schema, 

819 "ports": { 

820 "type": "array", 

821 "items": { 

822 "type": "object", 

823 "properties": { 

824 "pci": pci_extended_schema, 

825 "switch_port": shortname_schema, 

826 "switch_mac": mac_schema, 

827 }, 

828 "required": ["pci"], 

829 }, 

830 }, 

831 }, 

832 "required": ["compute_node", "ports"], 

833 }, 

834} 

835sdn_external_port_schema = { 

836 "$schema": "http://json-schema.org/draft-04/schema#", 

837 "title": "External port information", 

838 "type": "object", 

839 "properties": { 

840 "port": {"type": "string", "minLength": 1, "maxLength": 60}, 

841 "vlan": vlan_schema, 

842 "mac": mac_schema, 

843 }, 

844 "required": ["port"], 

845} 

846 

847# K8s Clusters 

848k8scluster_deploy_method_schema = { 

849 "$schema": "http://json-schema.org/draft-04/schema#", 

850 "title": "Deployment methods for K8s cluster", 

851 "type": "object", 

852 "properties": { 

853 "juju-bundle": {"type": "boolean"}, 

854 "helm-chart-v3": {"type": "boolean"}, 

855 }, 

856 "additionalProperties": False, 

857 "minProperties": 2, 

858} 

859k8scluster_nets_schema = { 

860 "title": "k8scluster nets input schema", 

861 "$schema": "http://json-schema.org/draft-04/schema#", 

862 "type": "object", 

863 "patternProperties": {".": {"oneOf": [name_schema, null_schema]}}, 

864 "minProperties": 1, 

865 "additionalProperties": False, 

866} 

867k8scluster_new_schema = { 

868 "title": "k8scluster creation input schema", 

869 "$schema": "http://json-schema.org/draft-04/schema#", 

870 "type": "object", 

871 "properties": { 

872 "schema_version": schema_version, 

873 "schema_type": schema_type, 

874 "name": name_schema, 

875 "description": description_schema, 

876 "credentials": object_schema, 

877 "vim_account": id_schema, 

878 "vca_id": id_schema, 

879 "k8s_version": string_schema, 

880 "nets": k8scluster_nets_schema, 

881 "deployment_methods": k8scluster_deploy_method_schema, 

882 "namespace": name_schema, 

883 "cni": nameshort_list_schema, 

884 }, 

885 "required": ["name", "credentials", "vim_account", "k8s_version", "nets"], 

886 "additionalProperties": False, 

887} 

888k8scluster_edit_schema = { 

889 "title": "vim_account edit input schema", 

890 "$schema": "http://json-schema.org/draft-04/schema#", 

891 "type": "object", 

892 "properties": { 

893 "name": name_schema, 

894 "description": description_schema, 

895 "credentials": object_schema, 

896 "vim_account": id_schema, 

897 "vca_id": id_schema, 

898 "k8s_version": string_schema, 

899 "nets": k8scluster_nets_schema, 

900 "namespace": name_schema, 

901 "cni": nameshort_list_schema, 

902 }, 

903 "additionalProperties": False, 

904} 

905 

906# VCA 

907vca_new_schema = { 

908 "title": "vca creation input schema", 

909 "$schema": "http://json-schema.org/draft-04/schema#", 

910 "type": "object", 

911 "properties": { 

912 "schema_version": schema_version, 

913 "schema_type": schema_type, 

914 "name": name_schema, 

915 "description": description_schema, 

916 "endpoints": description_list_schema, 

917 "user": string_schema, 

918 "secret": passwd_schema, 

919 "cacert": long_description_schema, 

920 "lxd-cloud": shortname_schema, 

921 "lxd-credentials": shortname_schema, 

922 "k8s-cloud": shortname_schema, 

923 "k8s-credentials": shortname_schema, 

924 "model-config": object_schema, 

925 }, 

926 "required": [ 

927 "name", 

928 "endpoints", 

929 "user", 

930 "secret", 

931 "cacert", 

932 "lxd-cloud", 

933 "lxd-credentials", 

934 "k8s-cloud", 

935 "k8s-credentials", 

936 ], 

937 "additionalProperties": False, 

938} 

939vca_edit_schema = { 

940 "title": "vca creation input schema", 

941 "$schema": "http://json-schema.org/draft-04/schema#", 

942 "type": "object", 

943 "properties": { 

944 "name": name_schema, 

945 "description": description_schema, 

946 "endpoints": description_list_schema, 

947 "port": integer1_schema, 

948 "user": string_schema, 

949 "secret": passwd_schema, 

950 "cacert": long_description_schema, 

951 "lxd-cloud": shortname_schema, 

952 "lxd-credentials": shortname_schema, 

953 "k8s-cloud": shortname_schema, 

954 "k8s-credentials": shortname_schema, 

955 "model-config": object_schema, 

956 }, 

957 "additionalProperties": False, 

958} 

959 

960# K8s Repos 

961k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]} 

962k8srepo_properties = { 

963 "name": name_schema, 

964 "description": description_schema, 

965 "type": k8srepo_types, 

966 "url": description_schema, 

967 "cacert": long_description_schema, 

968 "user": string_schema, 

969 "password": passwd_schema, 

970 "oci": bool_schema, 

971} 

972k8srepo_new_schema = { 

973 "title": "k8scluster creation input schema", 

974 "$schema": "http://json-schema.org/draft-04/schema#", 

975 "type": "object", 

976 "properties": k8srepo_properties, 

977 "required": ["name", "type", "url"], 

978 "additionalProperties": False, 

979} 

980k8srepo_edit_schema = { 

981 "title": "vim_account edit input schema", 

982 "$schema": "http://json-schema.org/draft-04/schema#", 

983 "type": "object", 

984 "properties": k8srepo_properties, 

985 "additionalProperties": False, 

986} 

987 

988# OSM Repos 

989osmrepo_types = {"enum": ["osm"]} 

990osmrepo_properties = { 

991 "name": name_schema, 

992 "description": description_schema, 

993 "type": osmrepo_types, 

994 "url": description_schema, 

995 # "user": string_schema, 

996 # "password": passwd_schema 

997} 

998osmrepo_new_schema = { 

999 "title": "osm repo creation input schema", 

1000 "$schema": "http://json-schema.org/draft-04/schema#", 

1001 "type": "object", 

1002 "properties": osmrepo_properties, 

1003 "required": ["name", "type", "url"], 

1004 "additionalProperties": False, 

1005} 

1006osmrepo_edit_schema = { 

1007 "title": "osm repo edit input schema", 

1008 "$schema": "http://json-schema.org/draft-04/schema#", 

1009 "type": "object", 

1010 "properties": osmrepo_properties, 

1011 "additionalProperties": False, 

1012} 

1013 

1014# PDUs 

1015pdu_interface = { 

1016 "type": "object", 

1017 "properties": { 

1018 "name": shortname_schema, 

1019 "mgmt": bool_schema, 

1020 "type": {"enum": ["overlay", "underlay"]}, 

1021 "ip-address": {"oneOf": [ip_schema, ipv6_schema]}, 

1022 # TODO, add user, password, ssh-key 

1023 "mac-address": mac_schema, 

1024 "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port 

1025 "vim-network-id": shortname_schema, 

1026 # # provide this in case SDN assist must deal with this interface 

1027 # "switch-dpid": dpid_Schema, 

1028 # "switch-port": shortname_schema, 

1029 # "switch-mac": shortname_schema, 

1030 # "switch-vlan": vlan_schema, 

1031 }, 

1032 "required": ["name", "mgmt", "ip-address"], 

1033 "additionalProperties": False, 

1034} 

1035pdu_new_schema = { 

1036 "title": "pdu creation input schema", 

1037 "$schema": "http://json-schema.org/draft-04/schema#", 

1038 "type": "object", 

1039 "properties": { 

1040 "name": shortname_schema, 

1041 "type": shortname_schema, 

1042 "description": description_schema, 

1043 "shared": bool_schema, 

1044 "vims": nameshort_list_schema, 

1045 "vim_accounts": nameshort_list_schema, 

1046 "interfaces": {"type": "array", "items": pdu_interface, "minItems": 1}, 

1047 }, 

1048 "required": ["name", "type", "interfaces"], 

1049 "additionalProperties": False, 

1050} 

1051pdu_edit_schema = { 

1052 "title": "pdu edit input schema", 

1053 "$schema": "http://json-schema.org/draft-04/schema#", 

1054 "type": "object", 

1055 "properties": { 

1056 "name": shortname_schema, 

1057 "type": shortname_schema, 

1058 "description": description_schema, 

1059 "shared": bool_schema, 

1060 "vims": {"oneOf": [array_edition_schema, nameshort_list_schema]}, 

1061 "vim_accounts": {"oneOf": [array_edition_schema, nameshort_list_schema]}, 

1062 "interfaces": { 

1063 "oneOf": [ 

1064 array_edition_schema, 

1065 {"type": "array", "items": pdu_interface, "minItems": 1}, 

1066 ] 

1067 }, 

1068 }, 

1069 "additionalProperties": False, 

1070 "minProperties": 1, 

1071} 

1072 

1073# VNF PKG OPERATIONS 

1074vnfpkgop_new_schema = { 

1075 "title": "VNF PKG operation creation input schema", 

1076 "$schema": "http://json-schema.org/draft-04/schema#", 

1077 "type": "object", 

1078 "properties": { 

1079 "lcmOperationType": string_schema, 

1080 "vnfPkgId": id_schema, 

1081 "kdu_name": name_schema, 

1082 "primitive": name_schema, 

1083 "primitive_params": {"type": "object"}, 

1084 }, 

1085 "required": [ 

1086 "lcmOperationType", 

1087 "vnfPkgId", 

1088 "kdu_name", 

1089 "primitive", 

1090 "primitive_params", 

1091 ], 

1092 "additionalProperties": False, 

1093} 

1094 

1095clustercreation_new_schema = { 

1096 "title": "cluster creation operation input schema", 

1097 "$schema": "http://json-schema.org/draft-04/schema#", 

1098 "type": "object", 

1099 "properties": { 

1100 "name": name_schema, 

1101 "vim_account": string_schema, 

1102 "k8s_version": string_schema, 

1103 "node_size": string_schema, 

1104 "node_count": integer0_schema, 

1105 "description": description_schema, 

1106 "region_name": string_schema, 

1107 "resource_group": string_schema, 

1108 "infra_controller_profiles": shortname_schema, 

1109 "infra_config_profiles": shortname_schema, 

1110 "resource_profiles": shortname_schema, 

1111 "app_profiles": shortname_schema, 

1112 "created": string_schema, 

1113 "state": string_schema, 

1114 "operatingState": string_schema, 

1115 "git_name": string_schema, 

1116 "resourceState": string_schema, 

1117 "bootstrap": bool_schema, 

1118 }, 

1119 "required": [ 

1120 "name", 

1121 "vim_account", 

1122 "k8s_version", 

1123 "node_size", 

1124 "node_count", 

1125 ], 

1126 "additionalProperties": False, 

1127} 

1128clusterregistration_new_schema = { 

1129 "title": "cluster registration input schema", 

1130 "$schema": "http://json-schema.org/draft-04/schema#", 

1131 "type": "object", 

1132 "properties": { 

1133 "schema_version": schema_version, 

1134 "schema_type": schema_type, 

1135 "name": name_schema, 

1136 "description": description_schema, 

1137 "credentials": object_schema, 

1138 "vim_account": string_schema, 

1139 "bootstrap": bool_schema, 

1140 }, 

1141 "required": ["name", "credentials", "vim_account"], 

1142 "additionalProperties": False, 

1143} 

1144 

1145cluster_edit_schema = { 

1146 "title": "cluster edit schema", 

1147 "$schema": "http://json-schema.org/draft-04/schema#", 

1148 "type": "object", 

1149 "properties": { 

1150 "name": name_schema, 

1151 "description": string_schema, 

1152 }, 

1153 "additionalProperties": False, 

1154} 

1155 

1156cluster_update_schema = { 

1157 "title": "cluster update schema", 

1158 "$schema": "http://json-schema.org/draft-04/schema#", 

1159 "type": "object", 

1160 "properties": { 

1161 "k8s_version": string_schema, 

1162 "node_size": string_schema, 

1163 "node_count": integer0_schema, 

1164 }, 

1165 "additionalProperties": True, 

1166} 

1167 

1168infra_controller_profile_create_new_schema = { 

1169 "title": "infra profile creation operation input schema", 

1170 "$schema": "http://json-schema.org/draft-04/schema#", 

1171 "type": "object", 

1172 "properties": { 

1173 "name": name_schema, 

1174 "description": string_schema, 

1175 }, 

1176 "additionalProperties": False, 

1177} 

1178 

1179infra_controller_profile_create_edit_schema = { 

1180 "title": "infra profile creation operation input schema", 

1181 "$schema": "http://json-schema.org/draft-04/schema#", 

1182 "type": "object", 

1183 "properties": { 

1184 "name": name_schema, 

1185 "description": string_schema, 

1186 }, 

1187 "additionalProperties": False, 

1188} 

1189 

1190infra_config_profile_create_new_schema = { 

1191 "title": "infra profile creation operation input schema", 

1192 "$schema": "http://json-schema.org/draft-04/schema#", 

1193 "type": "object", 

1194 "properties": { 

1195 "name": name_schema, 

1196 "description": string_schema, 

1197 }, 

1198 "additionalProperties": False, 

1199} 

1200 

1201infra_config_profile_create_edit_schema = { 

1202 "title": "infra profile creation operation input schema", 

1203 "$schema": "http://json-schema.org/draft-04/schema#", 

1204 "type": "object", 

1205 "properties": { 

1206 "name": name_schema, 

1207 "description": string_schema, 

1208 }, 

1209 "additionalProperties": False, 

1210} 

1211 

1212app_profile_create_new_schema = { 

1213 "title": "app profile creation operation input schema", 

1214 "$schema": "http://json-schema.org/draft-04/schema#", 

1215 "type": "object", 

1216 "properties": { 

1217 "name": name_schema, 

1218 "description": string_schema, 

1219 }, 

1220 "additionalProperties": False, 

1221} 

1222app_profile_create_edit_schema = { 

1223 "title": "app profile creation operation input schema", 

1224 "$schema": "http://json-schema.org/draft-04/schema#", 

1225 "type": "object", 

1226 "properties": { 

1227 "name": name_schema, 

1228 "description": string_schema, 

1229 }, 

1230 "additionalProperties": False, 

1231} 

1232 

1233resource_profile_create_new_schema = { 

1234 "title": "resource profile creation operation input schema", 

1235 "$schema": "http://json-schema.org/draft-04/schema#", 

1236 "type": "object", 

1237 "properties": { 

1238 "name": name_schema, 

1239 "description": string_schema, 

1240 }, 

1241 "additionalProperties": False, 

1242} 

1243resource_profile_create_edit_schema = { 

1244 "title": "resource profile creation operation input schema", 

1245 "$schema": "http://json-schema.org/draft-04/schema#", 

1246 "type": "object", 

1247 "properties": { 

1248 "name": name_schema, 

1249 "description": string_schema, 

1250 }, 

1251 "additionalProperties": False, 

1252} 

1253 

1254attach_profile = { 

1255 "type": "array", 

1256 "items": { 

1257 "type": "object", 

1258 "properties": {"id": id_schema}, 

1259 "additionalProperties": False, 

1260 }, 

1261} 

1262remove_profile = { 

1263 "type": "array", 

1264 "items": { 

1265 "type": "object", 

1266 "properties": {"id": id_schema}, 

1267 "additionalProperties": False, 

1268 }, 

1269} 

1270attach_dettach_profile_schema = { 

1271 "title": "attach/dettach profiles", 

1272 "$schema": "http://json-schema.org/draft-04/schema#", 

1273 "type": "object", 

1274 "properties": { 

1275 "add_profile": attach_profile, 

1276 "remove_profile": remove_profile, 

1277 }, 

1278 "additionalProperties": False, 

1279} 

1280# USERS 

1281project_role_mappings = { 

1282 "title": "list pf projects/roles", 

1283 "$schema": "http://json-schema.org/draft-04/schema#", 

1284 "type": "array", 

1285 "items": { 

1286 "type": "object", 

1287 "properties": {"project": shortname_schema, "role": shortname_schema}, 

1288 "required": ["project", "role"], 

1289 "additionalProperties": False, 

1290 }, 

1291 "minItems": 1, 

1292} 

1293 

1294project_role_mappings_optional = { 

1295 "title": "list of projects/roles or projects only", 

1296 "$schema": "http://json-schema.org/draft-04/schema#", 

1297 "type": "array", 

1298 "items": { 

1299 "type": "object", 

1300 "properties": {"project": shortname_schema, "role": shortname_schema}, 

1301 "required": ["project"], 

1302 "additionalProperties": False, 

1303 }, 

1304 "minItems": 1, 

1305} 

1306 

1307user_new_schema = { 

1308 "$schema": "http://json-schema.org/draft-04/schema#", 

1309 "title": "New user schema", 

1310 "type": "object", 

1311 "properties": { 

1312 "username": string_schema, 

1313 "email_id": email_schema, 

1314 "domain_name": shortname_schema, 

1315 "password": user_passwd_schema, 

1316 "projects": nameshort_list_schema, 

1317 "project_role_mappings": project_role_mappings, 

1318 }, 

1319 "required": ["username", "password"], 

1320 "additionalProperties": False, 

1321} 

1322user_edit_schema = { 

1323 "$schema": "http://json-schema.org/draft-04/schema#", 

1324 "title": "User edit schema for administrators", 

1325 "type": "object", 

1326 "properties": { 

1327 "password": user_passwd_schema, 

1328 "email_id": email_schema, 

1329 "old_password": passwd_schema, 

1330 "username": string_schema, # To allow User Name modification 

1331 "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]}, 

1332 "project_role_mappings": project_role_mappings, 

1333 "add_project_role_mappings": project_role_mappings, 

1334 "remove_project_role_mappings": project_role_mappings_optional, 

1335 "system_admin_id": id_schema, 

1336 "unlock": bool_schema, 

1337 "renew": bool_schema, 

1338 }, 

1339 "minProperties": 1, 

1340 "additionalProperties": False, 

1341} 

1342 

1343# PROJECTS 

1344topics_with_quota = [ 

1345 "vnfds", 

1346 "nsds", 

1347 "slice_templates", 

1348 "pduds", 

1349 "ns_instances", 

1350 "slice_instances", 

1351 "vim_accounts", 

1352 "wim_accounts", 

1353 "sdn_controllers", 

1354 "k8sclusters", 

1355 "vca", 

1356 "k8srepos", 

1357 "osmrepos", 

1358 "ns_subscriptions", 

1359] 

1360project_new_schema = { 

1361 "$schema": "http://json-schema.org/draft-04/schema#", 

1362 "title": "New project schema for administrators", 

1363 "type": "object", 

1364 "properties": { 

1365 "name": shortname_schema, 

1366 "admin": bool_schema, 

1367 "domain_name": shortname_schema, 

1368 "quotas": { 

1369 "type": "object", 

1370 "properties": {topic: integer0_schema for topic in topics_with_quota}, 

1371 "additionalProperties": False, 

1372 }, 

1373 }, 

1374 "required": ["name"], 

1375 "additionalProperties": False, 

1376} 

1377project_edit_schema = { 

1378 "$schema": "http://json-schema.org/draft-04/schema#", 

1379 "title": "Project edit schema for administrators", 

1380 "type": "object", 

1381 "properties": { 

1382 "admin": bool_schema, 

1383 "name": shortname_schema, # To allow Project Name modification 

1384 "quotas": { 

1385 "type": "object", 

1386 "properties": { 

1387 topic: {"oneOf": [integer0_schema, null_schema]} 

1388 for topic in topics_with_quota 

1389 }, 

1390 "additionalProperties": False, 

1391 }, 

1392 }, 

1393 "additionalProperties": False, 

1394 "minProperties": 1, 

1395} 

1396 

1397# ROLES 

1398roles_new_schema = { 

1399 "$schema": "http://json-schema.org/draft-04/schema#", 

1400 "title": "New role schema for administrators", 

1401 "type": "object", 

1402 "properties": { 

1403 "name": shortname_schema, 

1404 "permissions": { 

1405 "type": "object", 

1406 "patternProperties": { 

1407 ".": bool_schema, 

1408 }, 

1409 # "minProperties": 1, 

1410 }, 

1411 }, 

1412 "required": ["name"], 

1413 "additionalProperties": False, 

1414} 

1415roles_edit_schema = { 

1416 "$schema": "http://json-schema.org/draft-04/schema#", 

1417 "title": "Roles edit schema for administrators", 

1418 "type": "object", 

1419 "properties": { 

1420 "name": shortname_schema, 

1421 "permissions": { 

1422 "type": "object", 

1423 "patternProperties": {".": {"oneOf": [bool_schema, null_schema]}}, 

1424 # "minProperties": 1, 

1425 }, 

1426 }, 

1427 "additionalProperties": False, 

1428 "minProperties": 1, 

1429} 

1430 

1431# GLOBAL SCHEMAS 

1432 

1433nbi_new_input_schemas = { 

1434 "users": user_new_schema, 

1435 "projects": project_new_schema, 

1436 "vim_accounts": vim_account_new_schema, 

1437 "sdns": sdn_new_schema, 

1438 "ns_instantiate": ns_instantiate, 

1439 "ns_action": ns_action, 

1440 "ns_scale": ns_scale, 

1441 "ns_update": ns_update, 

1442 "ns_heal": ns_heal, 

1443 "pdus": pdu_new_schema, 

1444} 

1445 

1446nbi_edit_input_schemas = { 

1447 "users": user_edit_schema, 

1448 "projects": project_edit_schema, 

1449 "vim_accounts": vim_account_edit_schema, 

1450 "sdns": sdn_edit_schema, 

1451 "pdus": pdu_edit_schema, 

1452 "vnf": vnf_schema, 

1453 "vld": vld_schema, 

1454 "additionalParamsForVnf": additional_params_for_vnf, 

1455} 

1456 

1457# NETSLICE SCHEMAS 

1458nsi_subnet_instantiate = deepcopy(ns_instantiate) 

1459nsi_subnet_instantiate["title"] = "netslice subnet instantiation params input schema" 

1460nsi_subnet_instantiate["properties"]["id"] = name_schema 

1461del nsi_subnet_instantiate["required"] 

1462 

1463nsi_vld_instantiate = { 

1464 "title": "netslice vld instantiation params input schema", 

1465 "$schema": "http://json-schema.org/draft-04/schema#", 

1466 "type": "object", 

1467 "properties": { 

1468 "name": string_schema, 

1469 "vim-network-name": {"oneOf": [string_schema, object_schema]}, 

1470 "vim-network-id": {"oneOf": [string_schema, object_schema]}, 

1471 "ip-profile": object_schema, 

1472 }, 

1473 "required": ["name"], 

1474 "additionalProperties": False, 

1475} 

1476 

1477nsi_instantiate = { 

1478 "title": "netslice action instantiate input schema", 

1479 "$schema": "http://json-schema.org/draft-04/schema#", 

1480 "type": "object", 

1481 "properties": { 

1482 "lcmOperationType": string_schema, 

1483 "netsliceInstanceId": id_schema, 

1484 "nsiName": name_schema, 

1485 "nsiDescription": {"oneOf": [description_schema, null_schema]}, 

1486 "nstId": string_schema, 

1487 "vimAccountId": id_schema, 

1488 "timeout_nsi_deploy": integer1_schema, 

1489 "ssh_keys": {"type": "array", "items": {"type": "string"}}, 

1490 "nsi_id": id_schema, 

1491 "additionalParamsForNsi": object_schema, 

1492 "netslice-subnet": { 

1493 "type": "array", 

1494 "minItems": 1, 

1495 "items": nsi_subnet_instantiate, 

1496 }, 

1497 "netslice-vld": {"type": "array", "minItems": 1, "items": nsi_vld_instantiate}, 

1498 }, 

1499 "required": ["nsiName", "nstId", "vimAccountId"], 

1500 "additionalProperties": False, 

1501} 

1502 

1503nsi_action = {} 

1504 

1505nsi_terminate = {} 

1506 

1507nsinstancesubscriptionfilter_schema = { 

1508 "title": "instance identifier schema", 

1509 "$schema": "http://json-schema.org/draft-07/schema#", 

1510 "type": "object", 

1511 "properties": { 

1512 "nsdIds": {"type": "array"}, 

1513 "vnfdIds": {"type": "array"}, 

1514 "pnfdIds": {"type": "array"}, 

1515 "nsInstanceIds": {"type": "array"}, 

1516 "nsInstanceNames": {"type": "array"}, 

1517 }, 

1518} 

1519 

1520nslcmsub_schema = { 

1521 "title": "nslcmsubscription input schema", 

1522 "$schema": "http://json-schema.org/draft-07/schema#", 

1523 "type": "object", 

1524 "properties": { 

1525 "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema, 

1526 "notificationTypes": { 

1527 "type": "array", 

1528 "items": { 

1529 "enum": [ 

1530 "NsLcmOperationOccurrenceNotification", 

1531 "NsChangeNotification", 

1532 "NsIdentifierCreationNotification", 

1533 "NsIdentifierDeletionNotification", 

1534 ] 

1535 }, 

1536 }, 

1537 "operationTypes": { 

1538 "type": "array", 

1539 "items": {"enum": ["INSTANTIATE", "SCALE", "TERMINATE", "UPDATE", "HEAL"]}, 

1540 }, 

1541 "operationStates": { 

1542 "type": "array", 

1543 "items": { 

1544 "enum": [ 

1545 "PROCESSING", 

1546 "COMPLETED", 

1547 "PARTIALLY_COMPLETED", 

1548 "FAILED", 

1549 "FAILED_TEMP", 

1550 "ROLLING_BACK", 

1551 "ROLLED_BACK", 

1552 ] 

1553 }, 

1554 }, 

1555 "nsComponentTypes": {"type": "array", "items": {"enum": ["VNF", "NS", "PNF"]}}, 

1556 "lcmOpNameImpactingNsComponent": { 

1557 "type": "array", 

1558 "items": { 

1559 "enum": [ 

1560 "VNF_INSTANTIATE", 

1561 "VNF_SCALE", 

1562 "VNF_SCALE_TO_LEVEL", 

1563 "VNF_CHANGE_FLAVOUR", 

1564 "VNF_TERMINATE", 

1565 "VNF_HEAL", 

1566 "VNF_OPERATE", 

1567 "VNF_CHANGE_EXT_CONN", 

1568 "VNF_MODIFY_INFO", 

1569 "NS_INSTANTIATE", 

1570 "NS_SCALE", 

1571 "NS_UPDATE", 

1572 "NS_TERMINATE", 

1573 "NS_HEAL", 

1574 ] 

1575 }, 

1576 }, 

1577 "lcmOpOccStatusImpactingNsComponent": { 

1578 "type": "array", 

1579 "items": { 

1580 "enum": [ 

1581 "START", 

1582 "COMPLETED", 

1583 "PARTIALLY_COMPLETED", 

1584 "FAILED", 

1585 "ROLLED_BACK", 

1586 ] 

1587 }, 

1588 }, 

1589 }, 

1590 "allOf": [ 

1591 { 

1592 "if": { 

1593 "properties": { 

1594 "notificationTypes": { 

1595 "contains": {"const": "NsLcmOperationOccurrenceNotification"} 

1596 } 

1597 }, 

1598 }, 

1599 "then": { 

1600 "anyOf": [ 

1601 {"required": ["operationTypes"]}, 

1602 {"required": ["operationStates"]}, 

1603 ] 

1604 }, 

1605 }, 

1606 { 

1607 "if": { 

1608 "properties": { 

1609 "notificationTypes": {"contains": {"const": "NsChangeNotification"}} 

1610 }, 

1611 }, 

1612 "then": { 

1613 "anyOf": [ 

1614 {"required": ["nsComponentTypes"]}, 

1615 {"required": ["lcmOpNameImpactingNsComponent"]}, 

1616 {"required": ["lcmOpOccStatusImpactingNsComponent"]}, 

1617 ] 

1618 }, 

1619 }, 

1620 ], 

1621} 

1622 

1623authentication_schema = { 

1624 "title": "authentication schema for subscription", 

1625 "$schema": "http://json-schema.org/draft-07/schema#", 

1626 "type": "object", 

1627 "properties": { 

1628 "authType": {"enum": ["basic"]}, 

1629 "paramsBasic": { 

1630 "type": "object", 

1631 "properties": { 

1632 "userName": string_schema, 

1633 "password": passwd_schema, 

1634 }, 

1635 }, 

1636 }, 

1637} 

1638 

1639subscription = { 

1640 "title": "subscription input schema", 

1641 "$schema": "http://json-schema.org/draft-07/schema#", 

1642 "type": "object", 

1643 "properties": { 

1644 "filter": nslcmsub_schema, 

1645 "CallbackUri": description_schema, 

1646 "authentication": authentication_schema, 

1647 }, 

1648 "required": ["CallbackUri"], 

1649} 

1650 

1651vnflcmsub_schema = { 

1652 "title": "vnflcmsubscription input schema", 

1653 "$schema": "http://json-schema.org/draft-07/schema#", 

1654 "type": "object", 

1655 "properties": { 

1656 "VnfInstanceSubscriptionFilter": { 

1657 "type": "object", 

1658 "properties": { 

1659 "vnfdIds": {"type": "array"}, 

1660 "vnfInstanceIds": {"type": "array"}, 

1661 }, 

1662 }, 

1663 "notificationTypes": { 

1664 "type": "array", 

1665 "items": { 

1666 "enum": [ 

1667 "VnfIdentifierCreationNotification", 

1668 "VnfLcmOperationOccurrenceNotification", 

1669 "VnfIdentifierDeletionNotification", 

1670 ] 

1671 }, 

1672 }, 

1673 "operationTypes": { 

1674 "type": "array", 

1675 "items": { 

1676 "enum": [ 

1677 "INSTANTIATE", 

1678 "SCALE", 

1679 "SCALE_TO_LEVEL", 

1680 "CHANGE_FLAVOUR", 

1681 "TERMINATE", 

1682 "HEAL", 

1683 "OPERATE", 

1684 "CHANGE_EXT_CONN", 

1685 "MODIFY_INFO", 

1686 "CREATE_SNAPSHOT", 

1687 "REVERT_TO_SNAPSHOT", 

1688 "CHANGE_VNFPKG", 

1689 ] 

1690 }, 

1691 }, 

1692 "operationStates": { 

1693 "type": "array", 

1694 "items": { 

1695 "enum": [ 

1696 "STARTING", 

1697 "PROCESSING", 

1698 "COMPLETED", 

1699 "FAILED_TEMP", 

1700 "FAILED", 

1701 "ROLLING_BACK", 

1702 "ROLLED_BACK", 

1703 ] 

1704 }, 

1705 }, 

1706 }, 

1707 "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"], 

1708} 

1709 

1710vnf_subscription = { 

1711 "title": "vnf subscription input schema", 

1712 "$schema": "http://json-schema.org/draft-07/schema#", 

1713 "type": "object", 

1714 "properties": { 

1715 "filter": vnflcmsub_schema, 

1716 "CallbackUri": description_schema, 

1717 "authentication": authentication_schema, 

1718 }, 

1719 "required": ["filter", "CallbackUri"], 

1720} 

1721 

1722oka_schema = { 

1723 "title": "Create OKA package input schema", 

1724 "$schema": "http://json-schema.org/draft-07/schema#", 

1725 "type": "object", 

1726 "properties": { 

1727 "name": name_schema, 

1728 "description": description_schema, 

1729 "profile_type": profile_type_schema, 

1730 }, 

1731 "additionalProperties": False, 

1732} 

1733 

1734ksu_schema = { 

1735 "title": "ksu schema", 

1736 "$schema": "http://json-schema.org/draft-07/schema#", 

1737 "type": "object", 

1738 "properties": { 

1739 "name": name_schema, 

1740 "description": description_schema, 

1741 "profile": { 

1742 "type": "object", 

1743 "properties": { 

1744 "profile_type": profile_type_schema, 

1745 "_id": id_schema, 

1746 }, 

1747 "additionalProperties": False, 

1748 }, 

1749 "oka": { 

1750 "type": "array", 

1751 "items": { 

1752 "type": "object", 

1753 "properties": { 

1754 "_id": id_schema, 

1755 "sw_catalog_path": string_schema, 

1756 "transformation": object_schema, 

1757 }, 

1758 "additionalProperties": False, 

1759 }, 

1760 }, 

1761 }, 

1762 "additionalProperties": False, 

1763} 

1764 

1765 

1766class ValidationError(Exception): 

1767 def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY): 

1768 self.http_code = http_code 

1769 Exception.__init__(self, message) 

1770 

1771 

1772def validate_input(indata, schema_to_use): 

1773 """ 

1774 Validates input data against json schema 

1775 :param indata: user input data. Should be a dictionary 

1776 :param schema_to_use: jsonschema to test 

1777 :return: None if ok, raises ValidationError exception on error 

1778 """ 

1779 try: 

1780 if schema_to_use: 

1781 js_v(indata, schema_to_use) 

1782 return None 

1783 except js_e.ValidationError as e: 

1784 if e.path: 

1785 error_pos = "at '" + ":".join(map(str, e.path)) + "'" 

1786 else: 

1787 error_pos = "" 

1788 raise ValidationError("Format error {} '{}' ".format(error_pos, e.message)) 

1789 except js_e.SchemaError: 

1790 raise ValidationError( 

1791 "Bad json schema {}".format(schema_to_use), 

1792 http_code=HTTPStatus.INTERNAL_SERVER_ERROR, 

1793 ) 

1794 

1795 

1796def is_valid_uuid(x): 

1797 """ 

1798 Test for a valid UUID 

1799 :param x: string to test 

1800 :return: True if x is a valid uuid, False otherwise 

1801 """ 

1802 try: 

1803 if UUID(x): 

1804 return True 

1805 except (TypeError, ValueError, AttributeError): 

1806 return False