From 34aba98fb9f7b0daca856a93aa9e7f421fd43bca Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Tue, 26 May 2020 16:09:39 +0200 Subject: [PATCH] copr-be: delete unsuccessfully spawned AWS VM .. rightaway. Don't wait for garbage collector hit. --- .../copr/backend/templates/resalloc/vm-aws-new | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/roles/copr/backend/templates/resalloc/vm-aws-new b/roles/copr/backend/templates/resalloc/vm-aws-new index 705e2c9264..dc36a5ec62 100755 --- a/roles/copr/backend/templates/resalloc/vm-aws-new +++ b/roles/copr/backend/templates/resalloc/vm-aws-new @@ -2,6 +2,8 @@ set -e +delete_script=$(readlink -f "$(dirname "$0")")/vm-aws-delete + show_help() { cat <&2 @@ -24,6 +26,8 @@ test -z "$1" || exit "$1" # handle no arguments test $# -eq 0 && show_help 1 +test -n "$RESALLOC_NAME" || show_help 1 + ARGS=$(getopt -o "h" -l "arch:,help" -n "getopt" -- "$@") \ || show_help 1 eval set -- "$ARGS" @@ -53,6 +57,17 @@ case $opt_arch in esac test -n "$opt_arch" || show_help 1 +cleanup_vm=true +cleanup_actions() +{ + if $cleanup_vm; then + # it is safe to ask for removal of non-existeng VM (in case the playbook + # below was shut-down before the VM was even created) + $delete_script + fi +} +trap cleanup_actions EXIT + # TODO: We should call aws-cli directly here, instead of parsing output of # ansible playbook. But at the time of writing this script we had the playbook # available, so parsing the output is the easiest way to start. @@ -67,3 +82,6 @@ playbook=/var/lib/resallocserver/provision/builderpb-aws-"$opt_arch".yml echo "$vm_ip" test -n "$vm_ip" + +# successfuly created, disable cleanup action +cleanup_vm=false