(session: SessionDep, ctx: TenantContextDep, id: int)
| 588 | |
| 589 | @router.delete("/{id}") |
| 590 | async def delete_cluster(session: SessionDep, ctx: TenantContextDep, id: int): |
| 591 | existing = await Cluster.one_by_id( |
| 592 | session, |
| 593 | id, |
| 594 | options=[ |
| 595 | selectinload(Cluster.cluster_workers), |
| 596 | selectinload(Cluster.cluster_models), |
| 597 | selectinload(Cluster.cluster_model_instances), |
| 598 | ], |
| 599 | ) |
| 600 | if not existing or existing.deleted_at is not None: |
| 601 | raise NotFoundException(message=f"cluster {id} not found") |
| 602 | assert_cluster_writable(ctx, existing) |
| 603 | # check for workers, if any are present, prevent deletion |
| 604 | if len(existing.cluster_workers) > 0: |
| 605 | raise ConflictException( |
| 606 | message=f"cluster {existing.name}(id: {id}) has workers, cannot be deleted" |
| 607 | ) |
| 608 | # check for models, if any are present, prevent deletion |
| 609 | if len(existing.cluster_models) > 0: |
| 610 | raise ConflictException( |
| 611 | message=f"cluster {existing.name}(id: {id}) has models, cannot be deleted" |
| 612 | ) |
| 613 | # check for model instances, if any are present, prevent deletion |
| 614 | if len(existing.cluster_model_instances) > 0: |
| 615 | raise ConflictException( |
| 616 | message=f"cluster {existing.name}(id: {id}) has model instances, cannot be deleted" |
| 617 | ) |
| 618 | try: |
| 619 | await existing.delete(session=session) |
| 620 | except Exception as e: |
| 621 | raise InternalServerErrorException(message=f"Failed to delete cluster: {e}") |
| 622 | |
| 623 | |
| 624 | @router.post("/{id}/set-default") |
nothing calls this directly
no test coverage detected