Sha256: 90113083067d2b94e0a6fd7afe956aec1a4d81eb92bb855839b8dc7e018b75c5

Contents?: true

Size: 1013 Bytes

Versions: 6

Compression:

Stored size: 1013 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?

          begin
            env[:machine].guest.capability(:halt)
          rescue
            @logger.info('Trying Libvirt graceful shutdown.')
            domain.shutdown
          end


          begin
            domain.wait_for(30) do
              !ready?
            end
          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

6 entries across 6 versions & 1 rubygems

Version Path
vagrant-libvirt-0.4.1 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.4.0 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.3.0 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.2.1 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.1.2 lib/vagrant-libvirt/action/halt_domain.rb
vagrant-libvirt-0.1.0 lib/vagrant-libvirt/action/halt_domain.rb