|
@@ 581-602 (lines=22) @@
|
| 578 |
|
evc.sync() |
| 579 |
|
return JSONResponse("Operation successful", status_code=201) |
| 580 |
|
|
| 581 |
|
@rest("/v2/evc/metadata/{key}", methods=["DELETE"]) |
| 582 |
|
@validate_openapi(spec) |
| 583 |
|
def bulk_delete_metadata(self, request: Request) -> JSONResponse: |
| 584 |
|
"""Delete metada from a bulk of EVCs""" |
| 585 |
|
data = get_json_or_400(request, self.controller.loop) |
| 586 |
|
key = request.path_params["key"] |
| 587 |
|
circuit_ids = data.pop("circuit_ids") |
| 588 |
|
self.mongo_controller.update_evcs_metadata( |
| 589 |
|
circuit_ids, {key: ""}, "del" |
| 590 |
|
) |
| 591 |
|
|
| 592 |
|
fail_evcs = [] |
| 593 |
|
for _id in circuit_ids: |
| 594 |
|
try: |
| 595 |
|
evc = self.circuits[_id] |
| 596 |
|
evc.remove_metadata(key) |
| 597 |
|
except KeyError: |
| 598 |
|
fail_evcs.append(_id) |
| 599 |
|
|
| 600 |
|
if fail_evcs: |
| 601 |
|
raise HTTPException(404, detail=fail_evcs) |
| 602 |
|
return JSONResponse("Operation successful") |
| 603 |
|
|
| 604 |
|
@rest("/v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"]) |
| 605 |
|
def delete_metadata(self, request: Request) -> JSONResponse: |
|
@@ 539-558 (lines=20) @@
|
| 536 |
|
detail=f"circuit_id {circuit_id} not found." |
| 537 |
|
) from error |
| 538 |
|
|
| 539 |
|
@rest("/v2/evc/metadata", methods=["POST"]) |
| 540 |
|
@validate_openapi(spec) |
| 541 |
|
def bulk_add_metadata(self, request: Request) -> JSONResponse: |
| 542 |
|
"""Add metadata to a bulk of EVCs.""" |
| 543 |
|
data = get_json_or_400(request, self.controller.loop) |
| 544 |
|
circuit_ids = data.pop("circuit_ids") |
| 545 |
|
|
| 546 |
|
self.mongo_controller.update_evcs_metadata(circuit_ids, data, "add") |
| 547 |
|
|
| 548 |
|
fail_evcs = [] |
| 549 |
|
for _id in circuit_ids: |
| 550 |
|
try: |
| 551 |
|
evc = self.circuits[_id] |
| 552 |
|
evc.extend_metadata(data) |
| 553 |
|
except KeyError: |
| 554 |
|
fail_evcs.append(_id) |
| 555 |
|
|
| 556 |
|
if fail_evcs: |
| 557 |
|
raise HTTPException(404, detail=fail_evcs) |
| 558 |
|
return JSONResponse("Operation successful", status_code=201) |
| 559 |
|
|
| 560 |
|
@rest("/v2/evc/{circuit_id}/metadata", methods=["POST"]) |
| 561 |
|
@validate_openapi(spec) |