diff --git a/kvm-install-vm b/kvm-install-vm index 592865e..4be434f 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,22 @@ _EOF_ --noautoconsole \ ${GRAPHICS_OPTION} \ ${BOOTFLAG} \ - ${VIRT_INSTALL_EXTRA} || + ${VIRT_INSTALL_EXTRA}; then + + # Cleanup on failure + red "VM creation failed. Cleaning up..." + + if [ "${VERBOSE}" -eq 1 ] && [ -f "${VMNAME}.log" ]; then + yellow "Log contents:" + cat "${VMNAME}.log" + else + yellow "Run with -v flag to see detailed logs" + fi + + popd + delete_vm die "Could not create domain with virt-install." + fi virsh dominfo ${VMNAME} &>> ${VMNAME}.log