Skip to content

Instantly share code, notes, and snippets.

@johnlettman
Last active July 29, 2021 21:03
Show Gist options
  • Save johnlettman/ea3bc59e15ca6cc37b1c6017d1983fd7 to your computer and use it in GitHub Desktop.
Save johnlettman/ea3bc59e15ca6cc37b1c6017d1983fd7 to your computer and use it in GitHub Desktop.
Canonical Engineering Onboarding -- handy utilities
#!/usr/bin/env bash
confirm_prompt() {
while true
do
read -p "${*:-"Are you certain you would like to continue?"} [y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
}
watch_juju_status() {
watch -c -n3 juju status --color=true
}
destroy_zaza() {
echo "This function will destroy all zaza models, servers, and volumes."
confirm_prompt
echo "Grab a coffee or a tea -- this will take a very long time..."
echo "=> Destroying Juju models..."
for m in $(juju list-models --format json | jq --raw-output '.models | .[]."short-name" | match("^zaza-[[:alnum:]]+").string')
do
echo "-> Destroy model: ${m}"
juju destroy-model --destroy-storage -y "${m}"
done
echo "=> Destroying servers..."
for s in $(openstack server list | grep zaza | awk '{print $4}')
do
echo "-> Destroy server: ${s}"
openstack server delete "${s}"
done
echo "=> Destroying volumes..."
for v in $(cinder list | grep zaza | awk '{print $6}')
do
echo "-> Destroy volume: ${v}"
cinder delete "${v}"
done
}
destroy_bastion_leftovers() {
echo "This function will destroy all leftover servers and volumes in the Juju default model."
confirm_prompt
echo "=> Destroying servers..."
for s in $(openstack server list | grep -E "juju-[[:alnum:]]+-default" | awk '{print $4}')
do
echo "-> Destroy server: ${s}"
openstack server delete "${s}"
done
echo "=> Destroying volumes..."
for v in $(cinder list | grep -E "juju-[[:alnum:]]+-default" | awk '{print $6}')
do
echo "-> Destroy volume: ${v}"
cinder delete "${v}"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment