Sha256: 880547339aeccfb936bbe8d3498dcce40633884c4d55a1b34a27b3c2b0491871

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

# This acts like a backport of Vagrant's built in action from 1.3+ for previous version
#   https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin/wait_for_communicator.rb
module Vagrant
  module Backports
    module Action
      class WaitForCommunicator
        def initialize(app, env)
          @app = app
        end

        def call(env)
          @env = env

          raise Vagrant::Errors::VMFailedToBoot if !wait_for_communicator

          @app.call env
        end

        def wait_for_communicator
          max_tries = @env[:machine].config.ssh.max_tries.to_i
          max_tries.times do |i|
            if @env[:machine].communicate.ready?
              @env[:ui].info 'Machine booted and ready!'
              return true
            end

            # Return true so that the vm_failed_to_boot error doesn't
            # get shown
            return true if @env[:interrupted]

            sleep 1 if !@env["vagrant.test"]
          end

          @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")
          false
        end
      end
    end
  end
end

Vagrant::Action::Builtin.const_set :WaitForCommunicator, Vagrant::Backports::Action::WaitForCommunicator

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vagrant-lxc-1.0.1 lib/vagrant-backports/action/wait_for_communicator.rb
vagrant-lxc-1.0.0 lib/vagrant-backports/action/wait_for_communicator.rb
vagrant-lxc-1.0.0.alpha.3 lib/vagrant-backports/action/wait_for_communicator.rb
vagrant-lxc-1.0.0.alpha.2 lib/vagrant-backports/action/wait_for_communicator.rb
vagrant-lxc-1.0.0.alpha.1 lib/vagrant-backports/action/wait_for_communicator.rb