diff options
author | sed-i <82407168+sed-i@users.noreply.github.com> | 2021-11-15 16:27:19 -0500 |
---|---|---|
committer | Marc Cornellà <hello@mcornella.com> | 2022-02-10 11:42:16 +0100 |
commit | f045810697d423d108617ccd48bd7a414cb58734 (patch) | |
tree | 59a9642242e21ea2eb1841b0ed73992b6467c45d /plugins/juju/juju.plugin.zsh | |
parent | c41f2e7a0947139db79ae234b994467ff921f4cb (diff) | |
download | zsh-f045810697d423d108617ccd48bd7a414cb58734.tar.gz zsh-f045810697d423d108617ccd48bd7a414cb58734.tar.bz2 zsh-f045810697d423d108617ccd48bd7a414cb58734.zip |
feat(juju): add `jclean` function to destroy all registered controllers (#10426)
Closes #10426
Diffstat (limited to 'plugins/juju/juju.plugin.zsh')
-rw-r--r-- | plugins/juju/juju.plugin.zsh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh index 07f15b392..cf89418c6 100644 --- a/plugins/juju/juju.plugin.zsh +++ b/plugins/juju/juju.plugin.zsh @@ -95,6 +95,37 @@ jaddr() { fi } +# Destroy all controllers +jclean() { + if (( ! ${+commands[jq]} )); then + echo "jq is required but could not be found." >&2 + return 1 + fi + + local controllers=$(juju controllers --format=json | jq -r '.controllers | keys[]' 2>/dev/null) + if [[ -z "$controllers" ]]; then + echo "No controllers registered" + return 0 + fi + + echo "This will forcefully destroy all storages, models and controllers." + echo "Controllers to be destroyed:" + echo "$controllers" + + if ! read -q '?Are you sure (y/n)? '; then + echo + echo "Aborted." + return 0 + fi + + echo + for controller in ${=controllers}; do + timeout 2m juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y $controller + timeout 2m juju kill-controller -y -t 0 $controller 2>/dev/null + timeout 10s juju unregister $controller 2>/dev/null + done +} + # Display app and unit relation data jreld() { # $1 = relation name @@ -125,3 +156,4 @@ wjst() { shift $(( $# > 0 )) watch -n "$interval" --color juju status --relations --storage --color "$@" } + |