@@ -728,7 +728,7 @@ async def cancel_jobs( # noqa: C901, PLR0912
728728
729729
730730async def trigger_cluster_termination (
731- state : AppState , user_id : int , wallet_id : int , * , force : bool
731+ state : AppState , user_id : int , wallet_id : int | None , * , force : bool
732732) -> None :
733733 assert state .ec2_resource_clusters_keeper
734734 computational_instances = await ec2 .list_computational_instances_from_ec2 (
@@ -746,6 +746,7 @@ async def trigger_cluster_termination(
746746 computational_clusters ,
747747 state .environment ,
748748 state .ec2_resource_clusters_keeper .meta .client .meta .region_name ,
749+ output = None ,
749750 )
750751 if (force is True ) or typer .confirm (
751752 "Are you sure you want to trigger termination of that cluster?"
@@ -775,3 +776,31 @@ async def trigger_cluster_termination(
775776
776777async def check_database_connection (state : AppState ) -> None :
777778 await db .check_db_connection (state )
779+
780+
781+ async def terminate_instances (
782+ state : AppState , user_id : int | None , wallet_id : int | None , * , force : bool
783+ ) -> None :
784+ assert state .ec2_resource_autoscaling
785+ dynamic_instances = await ec2 .list_dynamic_instances_from_ec2 (
786+ state , user_id , wallet_id
787+ )
788+ dynamic_autoscaled_instances = await _parse_dynamic_instances (
789+ state , dynamic_instances , state .ssh_key_path , user_id , wallet_id
790+ )
791+
792+ if not dynamic_autoscaled_instances :
793+ rich .print ("no instances found" )
794+ raise typer .Exit (0 )
795+
796+ for instance in dynamic_autoscaled_instances :
797+ rich .print (
798+ f"terminating instance { instance .ec2_instance .instance_id } with name { utils .get_instance_name (instance )} "
799+ )
800+ if force is True or typer .confirm (
801+ f"Are you sure you want to terminate instance { instance .ec2_instance .instance_id } ?"
802+ ):
803+ instance .ec2_instance .terminate ()
804+ rich .print (f"terminated instance { instance .ec2_instance .instance_id } " )
805+ else :
806+ rich .print ("not terminating anything" )
0 commit comments