|
@@ 473-492 (lines=20) @@
|
| 470 |
|
evc.sync() |
| 471 |
|
return JSONResponse("Operation successful", status_code=201) |
| 472 |
|
|
| 473 |
|
@rest("v2/evc/metadata/{key}", methods=["DELETE"]) |
| 474 |
|
@validate_openapi(spec) |
| 475 |
|
def bulk_delete_metadata(self, request: Request) -> JSONResponse: |
| 476 |
|
"""Delete metada from a bulk of EVCs""" |
| 477 |
|
data = get_json_or_400(request, self.controller.loop) |
| 478 |
|
key = request.path_params["key"] |
| 479 |
|
circuit_ids = data.pop("circuit_ids") |
| 480 |
|
self.mongo_controller.update_evcs(circuit_ids, {key: ""}, "del") |
| 481 |
|
|
| 482 |
|
fail_evcs = [] |
| 483 |
|
for _id in circuit_ids: |
| 484 |
|
try: |
| 485 |
|
evc = self.circuits[_id] |
| 486 |
|
evc.remove_metadata(key) |
| 487 |
|
except KeyError: |
| 488 |
|
fail_evcs.append(_id) |
| 489 |
|
|
| 490 |
|
if fail_evcs: |
| 491 |
|
raise HTTPException(404, detail=fail_evcs) |
| 492 |
|
return JSONResponse("Operation successful") |
| 493 |
|
|
| 494 |
|
@rest("v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"]) |
| 495 |
|
def delete_metadata(self, request: Request) -> JSONResponse: |
|
@@ 432-451 (lines=20) @@
|
| 429 |
|
detail=f"circuit_id {circuit_id} not found." |
| 430 |
|
) from error |
| 431 |
|
|
| 432 |
|
@rest("v2/evc/metadata", methods=["POST"]) |
| 433 |
|
@validate_openapi(spec) |
| 434 |
|
def bulk_add_metadata(self, request: Request) -> JSONResponse: |
| 435 |
|
"""Add metadata to a bulk of EVCs.""" |
| 436 |
|
data = get_json_or_400(request, self.controller.loop) |
| 437 |
|
circuit_ids = data.pop("circuit_ids") |
| 438 |
|
|
| 439 |
|
self.mongo_controller.update_evcs(circuit_ids, data, "add") |
| 440 |
|
|
| 441 |
|
fail_evcs = [] |
| 442 |
|
for _id in circuit_ids: |
| 443 |
|
try: |
| 444 |
|
evc = self.circuits[_id] |
| 445 |
|
evc.extend_metadata(data) |
| 446 |
|
except KeyError: |
| 447 |
|
fail_evcs.append(_id) |
| 448 |
|
|
| 449 |
|
if fail_evcs: |
| 450 |
|
raise HTTPException(404, detail=fail_evcs) |
| 451 |
|
return JSONResponse("Operation successful", status_code=201) |
| 452 |
|
|
| 453 |
|
@rest("v2/evc/{circuit_id}/metadata", methods=["POST"]) |
| 454 |
|
@validate_openapi(spec) |