From e87084169df4cc8e50ca6b37905feb41b5bc3e17 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 14 Jul 2020 11:34:41 -0400 Subject: [PATCH] simplify vultr scripts for deleting instances by label --- bin/vultr/vultr_delete_instance_with_label.sh | 16 ++++++++++++++++ ...ce.sh => vultr_delete_instance_with_subid.sh} | 0 bin/vultr/vultr_list_instances.sh | 7 +++---- bin/vultr/vultr_subid_for_instance.sh | 9 +++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100755 bin/vultr/vultr_delete_instance_with_label.sh rename bin/vultr/{vultr_delete_instance.sh => vultr_delete_instance_with_subid.sh} (100%) create mode 100755 bin/vultr/vultr_subid_for_instance.sh diff --git a/bin/vultr/vultr_delete_instance_with_label.sh b/bin/vultr/vultr_delete_instance_with_label.sh new file mode 100755 index 00000000..c93fccd2 --- /dev/null +++ b/bin/vultr/vultr_delete_instance_with_label.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ +# +LABEL=${1:?no label provided} +THISDIR=$(cd $(dirname ${0}) && pwd) +VCURL=${THISDIR}/vcurl + +SUBID=$(${THISDIR}/vultr_subid_for_instance.sh ${LABEL}) +if [[ -z "${SUBID}" ]] ; then + echo "No instance found with label ${LABEL}" + exit 1 +fi + +echo "Deleting instance: ${SUBID}" +${VCURL} server/destroy -X POST -d "SUBID=${SUBID}" || echo "Error deleting instance: ${SUBID}" diff --git a/bin/vultr/vultr_delete_instance.sh b/bin/vultr/vultr_delete_instance_with_subid.sh similarity index 100% rename from bin/vultr/vultr_delete_instance.sh rename to bin/vultr/vultr_delete_instance_with_subid.sh diff --git a/bin/vultr/vultr_list_instances.sh b/bin/vultr/vultr_list_instances.sh index 752875ce..5968eea4 100755 --- a/bin/vultr/vultr_list_instances.sh +++ b/bin/vultr/vultr_list_instances.sh @@ -4,11 +4,10 @@ # THISDIR=$(cd $(dirname ${0}) && pwd) VCURL=${THISDIR}/vcurl +LABEL=${1} -VULTR_OUTPUT=${1} - -if [[ -z "${VULTR_OUTPUT}" ]] ; then +if [[ -z "${LABEL}" ]] ; then ${VCURL} server/list | jq . else - ${VCURL} server/list | jq -r .[].${VULTR_OUTPUT} + ${VCURL} server/list?label=${LABEL} | jq . fi diff --git a/bin/vultr/vultr_subid_for_instance.sh b/bin/vultr/vultr_subid_for_instance.sh new file mode 100755 index 00000000..94b051e1 --- /dev/null +++ b/bin/vultr/vultr_subid_for_instance.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ +# +THISDIR=$(cd $(dirname ${0}) && pwd) +VCURL=${THISDIR}/vcurl +LABEL=${1?no label provided} + +${VCURL} server/list?label=${LABEL} | jq -r '.[].SUBID'