Created
April 5, 2024 02:47
-
-
Save ellisbrown/67e143d79dc4f114ed0d39b04d0d2328 to your computer and use it in GitHub Desktop.
Delete all suspended TPUs in a GCP project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PROJECT=my-project | |
ZONE=us-central2-b | |
# Print the list of TPU resources in any state | |
gcloud alpha compute tpus queued-resources list \ | |
--project $PROJECT \ | |
--zone $ZONE | |
echo # Add a blank line for readability | |
# List all TPU resources in suspended or failed state and extract their names | |
SUSPENDED=$(gcloud alpha compute tpus queued-resources list \ | |
--project $PROJECT \ | |
--zone $ZONE | awk '$NF=="SUSPENDED" || $NF=="FAILED"{print $1}') | |
# If no resources are in suspended state, exit | |
if [ -z "$SUSPENDED" ]; then | |
echo "No TPU VMs in suspended state." | |
exit 0 | |
fi | |
# Loop through each suspended resource and delete it | |
for NAME in $SUSPENDED; do | |
echo "Deleting TPU VM: $NAME" | |
gcloud alpha compute tpus queued-resources delete $NAME --project $PROJECT --zone $ZONE --quiet | |
done | |
echo "Deletion process completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment