Files
fedora-infra_ansible/roles/copr/backend/templates/resalloc/vm-delete.j2

78 lines
2.3 KiB
Django/Jinja
Executable File

#! /bin/bash
die(){ echo >&2 "!! $*"; exit 1; }
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.
. "{{ provision_directory }}/.rc-osuosl.sh"
exec resalloc-openstack-delete --delete-everything "$RESALLOC_NAME"
exit 1
;;
*s390x*)
exit 0
;;
*copr_hv_x86_64_*)
pool_id=${RESALLOC_POOL_ID//copr_hv_x86_64_/}
pool_id=${pool_id//_dev/}
pool_id=${pool_id//_prod/}
pool_id=${pool_id//_stg/}
conn=qemu+ssh://copr@vmhost-x86-copr${pool_id}.rdu-cc.fedoraproject.org/system
;;
*aarch64_01*)
conn=qemu+ssh://copr@virthost-aarch64-os01.fedorainfracloud.org/system
;;
*aarch64_02*)
conn=qemu+ssh://copr@virthost-aarch64-os02.fedorainfracloud.org/system
;;
*copr_hv_ppc64le_*):
pool_id=${RESALLOC_POOL_ID//copr_hv_ppc64le_/}
pool_id=${pool_id//_dev/}
pool_id=${pool_id//_prod/}
pool_id=${pool_id//_stg/}
conn=qemu+ssh://copr@vmhost-p08-copr${pool_id}.rdu-cc.fedoraproject.org/system
;;
copr_p09_01*)
pool_id=${RESALLOC_POOL_ID//copr_p09_/}
pool_id=${pool_id//_dev/}
pool_id=${pool_id//_prod/}
pool_id=${pool_id//_stg/}
conn=qemu+ssh://copr@vmhost-p09-copr${pool_id}.rdu-cc.fedoraproject.org/system
;;
*) die "unknown RESALLOC_POOL_ID=$RESALLOC_POOL_ID" ;;
esac
# The rest of this script is LibVirt only!
{{ provision_directory }}/libvirt-delete --connection "$conn" "$RESALLOC_NAME"