@@ 512-533 (lines=22) @@ | ||
509 | evc.sync() |
|
510 | return JSONResponse("Operation successful", status_code=201) |
|
511 | ||
512 | @rest("/v2/evc/metadata/{key}", methods=["DELETE"]) |
|
513 | @validate_openapi(spec) |
|
514 | def bulk_delete_metadata(self, request: Request) -> JSONResponse: |
|
515 | """Delete metada from a bulk of EVCs""" |
|
516 | data = get_json_or_400(request, self.controller.loop) |
|
517 | key = request.path_params["key"] |
|
518 | circuit_ids = data.pop("circuit_ids") |
|
519 | self.mongo_controller.update_evcs_metadata( |
|
520 | circuit_ids, {key: ""}, "del" |
|
521 | ) |
|
522 | ||
523 | fail_evcs = [] |
|
524 | for _id in circuit_ids: |
|
525 | try: |
|
526 | evc = self.circuits[_id] |
|
527 | evc.remove_metadata(key) |
|
528 | except KeyError: |
|
529 | fail_evcs.append(_id) |
|
530 | ||
531 | if fail_evcs: |
|
532 | raise HTTPException(404, detail=fail_evcs) |
|
533 | return JSONResponse("Operation successful") |
|
534 | ||
535 | @rest("/v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"]) |
|
536 | def delete_metadata(self, request: Request) -> JSONResponse: |
|
@@ 471-490 (lines=20) @@ | ||
468 | detail=f"circuit_id {circuit_id} not found." |
|
469 | ) from error |
|
470 | ||
471 | @rest("/v2/evc/metadata", methods=["POST"]) |
|
472 | @validate_openapi(spec) |
|
473 | def bulk_add_metadata(self, request: Request) -> JSONResponse: |
|
474 | """Add metadata to a bulk of EVCs.""" |
|
475 | data = get_json_or_400(request, self.controller.loop) |
|
476 | circuit_ids = data.pop("circuit_ids") |
|
477 | ||
478 | self.mongo_controller.update_evcs_metadata(circuit_ids, data, "add") |
|
479 | ||
480 | fail_evcs = [] |
|
481 | for _id in circuit_ids: |
|
482 | try: |
|
483 | evc = self.circuits[_id] |
|
484 | evc.extend_metadata(data) |
|
485 | except KeyError: |
|
486 | fail_evcs.append(_id) |
|
487 | ||
488 | if fail_evcs: |
|
489 | raise HTTPException(404, detail=fail_evcs) |
|
490 | return JSONResponse("Operation successful", status_code=201) |
|
491 | ||
492 | @rest("/v2/evc/{circuit_id}/metadata", methods=["POST"]) |
|
493 | @validate_openapi(spec) |