Skip to content

Instantly share code, notes, and snippets.

@MiniXC
Created November 13, 2023 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiniXC/75d1697be455b5f3a9a10e5797ca97f0 to your computer and use it in GitHub Desktop.
Save MiniXC/75d1697be455b5f3a9a10e5797ca97f0 to your computer and use it in GitHub Desktop.
update_tpus.sh
#!/bin/bash
if ! test -f /etc/hosts.bak; then
sudo cp /etc/hosts /etc/hosts.bak
fi
sudo cp /etc/hosts.bak /etc/hosts
YAML_INFO="
`gcloud compute tpus tpu-vm list --zone=us-central1-f --format=yaml`
`gcloud compute tpus tpu-vm list --zone=europe-west4-a --format=yaml`
"
NAMES=(`echo "$YAML_INFO" | yq eval ".name" | cut -d "/" -f6 | grep -v "\-\-\-"`)
EXTERNAL_IPS=(`echo "$YAML_INFO" | yq eval ".networkEndpoints[0].accessConfig.externalIp" | grep -v "\-\-\-"`)
for index in ${!NAMES[*]}; do
echo "${EXTERNAL_IPS[$index]} ${NAMES[$index]}" | sudo tee -a /etc/hosts
ssh-keygen -R ${NAMES[$index]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment