Sha256: ad420766c8ce03060cc5a4fdfef82b4dc45fa660bde3e4ecd3cbce18c0b19adb

Contents?: true

Size: 1.63 KB

Versions: 22

Compression:

Stored size: 1.63 KB

Contents

require 'vagrant-vbguest/helpers/vm_compatible'

module VagrantVbguest
  module Helpers
    module Rebootable
      include VmCompatible

      def self.included(base)
        base.extend(ClassMethods)
      end

      @@rebooted = {}

      def rebooted?(vm)
        !!@@rebooted[ self.class.vm_id(vm) ]
      end

      def reboot?(vm, options)
        if rebooted?(vm)
          vm.env.ui.error(I18n.t("vagrant_vbguest.restart_loop_guard_activated"))
          false
        elsif options[:auto_reboot]
          vm.env.ui.warn(I18n.t("vagrant_vbguest.restart_vm"))
          @@rebooted[ self.class.vm_id(vm) ] = true
        else
          vm.env.ui.warn(I18n.t("vagrant_vbguest.suggest_restart", :name => vm.name))
          false
        end
      end

      def reboot(vm, options)
        if reboot? vm, options
          simple_reboot = Vagrant::Action::Builder.new.tap do |b|
            b.use Vagrant::Action::Builtin::Call, Vagrant::Action::Builtin::GracefulHalt, :poweroff, :running do |env2, b2|
              if !env2[:result]
                b2.use VagrantPlugins::ProviderVirtualBox::Action::ForcedHalt
              end
            end
            b.use VagrantPlugins::ProviderVirtualBox::Action::Boot
            if defined?(Vagrant::Action::Builtin::WaitForCommunicator)
              b.use Vagrant::Action::Builtin::WaitForCommunicator, [:starting, :running]
            end
          end
          @env[:action_runner].run(simple_reboot, @env)
        end
      end

      # executes the whole reboot process
      def reboot!(vm, options)
        if reboot? vm, options
          vm.action(:reload, options)
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
vagrant-vbguest-0.32.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.31.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.30.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.29.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.28.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.27.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.26.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.25.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.24.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.24.0.beta1 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.23.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.22.1 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.22.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.21.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.20.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.19.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.18.0 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.17.2 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.17.1 lib/vagrant-vbguest/helpers/rebootable.rb
vagrant-vbguest-0.17.0 lib/vagrant-vbguest/helpers/rebootable.rb