Class: VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain
- Defined in:
- lib/vagrant-libvirt/action/shutdown_domain.rb
Overview
Shutdown the domain.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _env, target_state, source_state) ⇒ ShutdownDomain
constructor
A new instance of ShutdownDomain.
Constructor Details
#initialize(app, _env, target_state, source_state) ⇒ ShutdownDomain
Returns a new instance of ShutdownDomain.
27 28 29 30 31 32 |
# File 'lib/vagrant-libvirt/action/shutdown_domain.rb', line 27 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 |
Instance Method Details
#call(env) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vagrant-libvirt/action/shutdown_domain.rb', line 34 def call(env) timeout = env[:machine].config.vm.graceful_halt_timeout start_time = env[:shutdown_start_time] if start_time.nil? # this really shouldn't happen raise Errors::CallChainError, require_action: StartShutdownTimer.name, current_action: ShutdownDomain.name end # return if successful, otherwise will ensure result is set to false env[:result] = env[:machine].state.id == @target_state return @app.call(env) if env[:result] current_time = Time.now # if we've already exceeded the timeout return @app.call(env) if current_time - start_time >= timeout # otherwise construct a new timeout. timeout = timeout - (current_time - start_time) 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 |