Sha256: 10565ae1e6c41e25344abc7be3d1e7e246d62188a06774394e55f30cad74446a

Contents?: true

Size: 902 Bytes

Versions: 5

Compression:

Stored size: 902 Bytes

Contents

require 'log4r'

module VagrantPlugins
  module ProviderLibvirt
    module Action
      # Halt the domain.
      class HaltDomain
        def initialize(app, env)
          @logger = Log4r::Logger.new("vagrant_libvirt::action::halt_domain")
          @app = app
        end

        def call(env)
          env[:ui].info(I18n.t("vagrant_libvirt.halt_domain"))

          domain = env[:machine].provider.driver.connection.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
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vagrant-libvirt-0.0.36 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.0.35 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.0.33 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.0.32 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.0.31 lib/vagrant-libvirt/action/halt_domain.rb