Browse Source

feat: cleanup if domain not created successfully (#98)

* feat: cleanup if domain not created successfully

* feat: output logs in verbose mode before cleanup
pull/100/head 1.3.1
Giovanni Torres 6 months ago committed by GitHub
parent
commit
274937e5a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      kvm-install-vm

18
kvm-install-vm

@ -559,7 +559,7 @@ _EOF_
CLOUD_INIT_OPTION="$(param --cloud-init user-data=${USER_DATA},meta-data=${META_DATA},disable=on)" 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 # 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 \ virt-install --import \
--name=${VMNAME} \ --name=${VMNAME} \
--memory=${MEMORY} \ --memory=${MEMORY} \
@ -573,8 +573,22 @@ _EOF_
--noautoconsole \ --noautoconsole \
${GRAPHICS_OPTION} \ ${GRAPHICS_OPTION} \
${BOOTFLAG} \ ${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." die "Could not create domain with virt-install."
fi
virsh dominfo ${VMNAME} &>> ${VMNAME}.log virsh dominfo ${VMNAME} &>> ${VMNAME}.log

Loading…
Cancel
Save