From 32f69c53610209c8b776ac1af4ff993547952b99 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 11 Jun 2021 16:04:10 -0700 Subject: [PATCH] Update HaltDomain action to only forcibly halt domain --- lib/vagrant-libvirt/action/halt_domain.rb | 36 ++--------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/lib/vagrant-libvirt/action/halt_domain.rb b/lib/vagrant-libvirt/action/halt_domain.rb index 57df2bf..117ee0b 100644 --- a/lib/vagrant-libvirt/action/halt_domain.rb +++ b/lib/vagrant-libvirt/action/halt_domain.rb @@ -13,41 +13,9 @@ module VagrantPlugins end def call(env) - env[:ui].info(I18n.t('vagrant_libvirt.halt_domain')) - - timeout = env[:machine].config.vm.graceful_halt_timeout domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) - raise Errors::NoDomainError if domain.nil? - - if env[:force_halt] - domain.poweroff - return @app.call(env) - end - - begin - Timeout.timeout(timeout) do - begin - env[:machine].guest.capability(:halt) - rescue Timeout::Error - raise - rescue - @logger.info('Trying Libvirt graceful shutdown.') - # Read domain object again - dom = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) - if dom.state.to_s == 'running' - dom.shutdown - end - end - - domain.wait_for(timeout) do - !ready? - end - end - rescue Timeout::Error - @logger.info('VM is still running. Calling force poweroff.') - domain.poweroff - rescue - @logger.error('Failed to shutdown cleanly. Calling force poweroff.') + if env[:machine].state.id == :running + env[:ui].info(I18n.t('vagrant_libvirt.halt_domain')) domain.poweroff end