diff --git a/bin/do/do_delete_image.sh b/bin/do/do_delete_image.sh new file mode 100755 index 00000000..a3f451da --- /dev/null +++ b/bin/do/do_delete_image.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +IMAGEID=${1:?no IMAGEID provided} +THISDIR=$(cd $(dirname ${0}) && pwd) +DOCURL=${THISDIR}/docurl + +if [[ ${IMAGEID} == "-n" ]] ; then + IMAGE_NAME=${2:?no image name provided} + echo "Deleting image named: ${IMAGE_NAME}" + ${0} $(${DOCURL} "images?private=true" | jq -r '.images[] | select(.name=="'${IMAGE_NAME}'") | .id') || echo "Error deleting image named: ${IMAGE_NAME}" + +else + echo "Deleting image: ${IMAGEID}" + ${DOCURL} images/${IMAGEID} -X DELETE || echo "Error deleting image: ${IMAGEID}" +fi diff --git a/bin/do/do_delete_instance.sh b/bin/do/do_delete_instance.sh new file mode 100755 index 00000000..6036efab --- /dev/null +++ b/bin/do/do_delete_instance.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +DROPLETID=${1:?no DROPLETID provided} +THISDIR=$(cd $(dirname ${0}) && pwd) +DOCURL=${THISDIR}/docurl + +if [[ ${DROPLETID} == "-n" ]] ; then + DROPLET_NAME=${2:?no droplet name provided} + echo "Deleting droplet named: ${DROPLET_NAME}" + ${0} $(${DOCURL} droplets | jq -r '.droplets[] | select(.name=="'${DROPLET_NAME}'") | .id') || echo "Error deleting droplet named: ${DROPLET_NAME}" + +else + echo "Deleting instance: ${DROPLETID}" + ${DOCURL} droplets/${DROPLETID} -X DELETE || echo "Error deleting instance: ${DROPLETID}" +fi diff --git a/bin/do/do_list_images.sh b/bin/do/do_list_images.sh new file mode 100755 index 00000000..44033e18 --- /dev/null +++ b/bin/do/do_list_images.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +THISDIR=$(cd $(dirname ${0}) && pwd) +DOCURL=${THISDIR}/docurl + +DO_OUTPUT=${1} + +if [[ -z "${DO_OUTPUT}" ]] ; then + ${DOCURL} "images?private=true" | jq . +else + ${DOCURL} "images?private=true" | jq -r .images[].${DO_OUTPUT} +fi diff --git a/bin/do/do_list_instances.sh b/bin/do/do_list_instances.sh new file mode 100755 index 00000000..52071f3f --- /dev/null +++ b/bin/do/do_list_instances.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +THISDIR=$(cd $(dirname ${0}) && pwd) +DOCURL=${THISDIR}/docurl + +DO_OUTPUT=${1} + +if [[ -z "${DO_OUTPUT}" ]] ; then + ${DOCURL} droplets | jq . +else + ${DOCURL} droplets | jq -r .droplets[].${DO_OUTPUT} +fi diff --git a/bin/do/docurl b/bin/do/docurl new file mode 100755 index 00000000..b3667304 --- /dev/null +++ b/bin/do/docurl @@ -0,0 +1,11 @@ +#!/bin/bash + +if [[ -z "${DIGITALOCEAN_API_KEY}" ]] ; then + echo "DIGITALOCEAN_API_KEY not defined in environment" + exit 1 +fi + +path=${1:?no path provided} +shift + +curl ${@} -s -H "Authorization: Bearer ${DIGITALOCEAN_API_KEY}" 'https://api.digitalocean.com/v2/'"${path}"'' diff --git a/bin/vultr/vultr_delete_snapshot.sh b/bin/vultr/vultr_delete_snapshot.sh index 5cc9d88b..25cbc8d8 100755 --- a/bin/vultr/vultr_delete_snapshot.sh +++ b/bin/vultr/vultr_delete_snapshot.sh @@ -4,5 +4,12 @@ SNAPSHOTID=${1:?no SNAPSHOTID provided} THISDIR=$(cd $(dirname ${0}) && pwd) VCURL=${THISDIR}/vcurl -echo "Deleting snapshot: ${SNAPSHOTID}" -${VCURL} snapshot/destroy -X POST -d "SNAPSHOTID=${SNAPSHOTID}" || echo "Error deleting snapshot: ${SNAPSHOTID}" +if [[ ${SNAPSHOTID} == "-n" ]] ; then + SNAPSHOT_NAME=${2:?no snapshot name provided} + echo "Deleting snapshot named: ${SNAPSHOT_NAME}" + ${0} $(${VCURL} snapshot/list | jq -r 'to_entries | .[] | select(.value.description=="'${SNAPSHOT_NAME}'") | .value.SNAPSHOTID') || echo "Error deleting snapshot named: ${SNAPSHOT_NAME}" + +else + echo "Deleting snapshot: ${SNAPSHOTID}" + ${VCURL} snapshot/destroy -X POST -d "SNAPSHOTID=${SNAPSHOTID}" || echo "Error deleting snapshot: ${SNAPSHOTID}" +fi