Class: VagrantPlugins::ProviderLibvirt::Action::HaltDomain
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::HaltDomain
- Defined in:
- lib/vagrant-libvirt/action/halt_domain.rb
Overview
Halt the domain.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ HaltDomain
constructor
A new instance of HaltDomain.
Constructor Details
#initialize(app, env) ⇒ HaltDomain
Returns a new instance of HaltDomain.
8 9 10 11 |
# File 'lib/vagrant-libvirt/action/halt_domain.rb', line 8 def initialize(app, env) @logger = Log4r::Logger.new("vagrant_libvirt::action::halt_domain") @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-libvirt/action/halt_domain.rb', line 13 def call(env) env[:ui].info(I18n.t("vagrant_libvirt.halt_domain")) domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s) raise Errors::NoDomainError if domain == nil @logger.info("Trying gracefull shutdown.") domain.shutdown begin domain.wait_for(30) { !ready? } rescue Fog::Errors::TimeoutError @logger.info("VM is still running. Calling force poweroff.") domain.poweroff end @app.call(env) end |