MCPcopy
hub / github.com/gpustack/gpustack / delete_cluster

Function delete_cluster

gpustack/routes/clusters.py:590–621  ·  view source on GitHub ↗
(session: SessionDep, ctx: TenantContextDep, id: int)

Source from the content-addressed store, hash-verified

588
589@router.delete("/{id}")
590async 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")

Callers

nothing calls this directly

Calls 3

assert_cluster_writableFunction · 0.90
one_by_idMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected