Files
fedora-infra_ansible/roles/copr/backend/templates/resalloc/vm-delete.j2
2026-02-07 21:08:10 +01:00

58 lines
1.4 KiB
Django/Jinja
Executable File

#! /bin/bash
die(){ echo >&2 "!! $*"; exit 1; }
set -x
test -z "$RESALLOC_NAME" && die "no vm specified, empty \$RESALLOC_NAME variable"
# Detect the IP we should be talking to.
decoded=$(echo "$RESALLOC_RESOURCE_DATA" | base64 --decode)
IP=$(echo "$decoded" | yq .host || :)
if test -z "$IP"; then
set -- $(echo "$decoded")
IP=$1
fi
# Let's give it a shot and do our best to get rid of existing entitlement. No
# point in wasting time on busted machines, though. All we can really do is
# turn them off.
if timeout 30 ssh root@"$IP" "echo machine works"; then
# Don't give-up unregistering after the first attempt
for _ in a b c; do
timeout 180 ssh root@"$IP" "subscription-manager unregister" && break
sleep 5
done
fi
case $RESALLOC_POOL_ID in
*aws*)
# Delegate the rest of the task to an AWS specific script.
exec /usr/bin/resalloc-aws-delete --aws-profile default
exit 1
;;
copr_osuosl_*)
# Delegate the rest of this task to an OpenStack specific script.
set +x
. "{{ provision_directory }}/.rc-osuosl.sh"
exec resalloc-openstack-delete --delete-everything "$RESALLOC_NAME"
exit 1
;;
*s390x*)
exit 0
;;
*copr_hv_x86_64_*)
;;
*copr_hv_ppc64le_*)
;;
vmhost*)
# hypervisors
;;
*) die "unknown RESALLOC_POOL_ID=$RESALLOC_POOL_ID" ;;
esac
# The rest of this script is LibVirt only!
"{{ provision_directory }}/libvirt-delete" "$RESALLOC_NAME"