mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Add ShutdownDomain action and use during halt sequence
This adds in a ShutdownDomain action which allows for the GracefulHalt action to attempt to shutdown the domain. If it does not transition to domain successfully to a shutoff state, the ShutdownDomain action is used to "nicely" shutdown the domain. Likewise, if that action fails to transition the domain, the HaltDomain action will be used to forcibly stop it.
This commit is contained in:
parent
44d7c5526d
commit
9acfd16dfc
@ -145,7 +145,11 @@ module VagrantPlugins
|
||||
# VM is running, halt it.
|
||||
b3.use Call, GracefulHalt, :shutoff, :running do |env3, b4|
|
||||
if !env3[:result]
|
||||
b4.use HaltDomain
|
||||
b4.use Call, ShutdownDomain, :shutoff, :running do |env4, b5|
|
||||
if !env4[:result]
|
||||
b5.use HaltDomain
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -352,6 +356,7 @@ module VagrantPlugins
|
||||
autoload :ForwardPorts, action_root.join('forward_ports')
|
||||
autoload :ClearForwardedPorts, action_root.join('forward_ports')
|
||||
autoload :HaltDomain, action_root.join('halt_domain')
|
||||
autoload :ShutdownDomain, action_root.join('shutdown_domain')
|
||||
autoload :HandleBoxImage, action_root.join('handle_box_image')
|
||||
autoload :HandleStoragePool, action_root.join('handle_storage_pool')
|
||||
autoload :RemoveLibvirtImage, action_root.join('remove_libvirt_image')
|
||||
|
31
lib/vagrant-libvirt/action/shutdown_domain.rb
Normal file
31
lib/vagrant-libvirt/action/shutdown_domain.rb
Normal file
@ -0,0 +1,31 @@
|
||||
require 'log4r'
|
||||
|
||||
module VagrantPlugins
|
||||
module ProviderLibvirt
|
||||
module Action
|
||||
# Shutdown the domain.
|
||||
class ShutdownDomain
|
||||
def initialize(app, _env, target_state, source_state)
|
||||
@logger = Log4r::Logger.new('vagrant_libvirt::action::shutdown_domain')
|
||||
@target_state = target_state
|
||||
@source_state = source_state
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
timeout = env[:machine].config.vm.graceful_halt_timeout
|
||||
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
||||
if env[:machine].state.id == @source_state
|
||||
env[:ui].info(I18n.t('vagrant_libvirt.shutdown_domain'))
|
||||
domain.shutdown
|
||||
domain.wait_for(timeout) { !ready? }
|
||||
end
|
||||
|
||||
env[:result] = env[:machine].state.id == @target_state
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -29,6 +29,8 @@ en:
|
||||
Poweroff domain.
|
||||
destroy_domain: |-
|
||||
Removing domain...
|
||||
shutdown_domain: |-
|
||||
Attempting direct shutdown of domain...
|
||||
halt_domain: |-
|
||||
Halting domain...
|
||||
resuming_domain: |-
|
||||
|
Loading…
Reference in New Issue
Block a user