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