From 99944a6cce51774171acd66c84627984bb336e35 Mon Sep 17 00:00:00 2001 From: Giovanni Torres Date: Sat, 6 Sep 2025 16:30:46 -0400 Subject: [PATCH] feat: cleanup if domain not created successfully --- kvm-install-vm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kvm-install-vm b/kvm-install-vm index 592865e..00ae0ef 100755 --- a/kvm-install-vm +++ b/kvm-install-vm @@ -559,7 +559,7 @@ _EOF_ CLOUD_INIT_OPTION="$(param --cloud-init user-data=${USER_DATA},meta-data=${META_DATA},disable=on)" # Call virt-install to import the cloud image and create a new VM - run "Installing the domain" \ + if ! run "Installing the domain" \ virt-install --import \ --name=${VMNAME} \ --memory=${MEMORY} \ @@ -573,8 +573,13 @@ _EOF_ --noautoconsole \ ${GRAPHICS_OPTION} \ ${BOOTFLAG} \ - ${VIRT_INSTALL_EXTRA} || + ${VIRT_INSTALL_EXTRA}; then + # Cleanup on failure + red "VM creation failed. Cleaning up..." + popd + delete_vm die "Could not create domain with virt-install." + fi virsh dominfo ${VMNAME} &>> ${VMNAME}.log