Dont worry about machine state when waiting for communicator [GH-142] [GH-146]

This commit is contained in:
Fabio Rehm 2013-09-27 12:27:25 -03:00
parent 6b823e8dcb
commit 2116737989
2 changed files with 10 additions and 15 deletions

View file

@ -56,7 +56,7 @@ module Vagrant
b.use Vagrant::Action::Builtin::SetHostname b.use Vagrant::Action::Builtin::SetHostname
b.use ForwardPorts b.use ForwardPorts
b.use Boot b.use Boot
b.use Vagrant::Action::Builtin::WaitForCommunicator, [:starting, :running] b.use Vagrant::Action::Builtin::WaitForCommunicator
end end
end end

View file

@ -1,25 +1,25 @@
# This acts like a backport of Vagrant's built in action from 1.3+ for older versions # This acts like a backport of Vagrant's built in action from 1.3+ for older versions
# and will probably be deprecated on 0.8+
# https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin/wait_for_communicator.rb # https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin/wait_for_communicator.rb
module Vagrant module Vagrant
module LXC module LXC
module Action module Action
class WaitForCommunicator class WaitForCommunicator
def initialize(app, env, states = []) def initialize(app, env)
@app = app @app = app
@states = states
end end
def call(env) def call(env)
@env = env @env = env
raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot
raise Vagrant::Errors::VMFailedToBoot if !wait_for_communicator
@app.call env @app.call env
end end
# Stolen from the an old version of VagrantPlugins::ProviderVirtualBox::Action::Boot def wait_for_communicator
def wait_for_boot max_tries = @env[:machine].config.ssh.max_tries.to_i
@env[:ui].info I18n.t("vagrant_lxc.messages.waiting_for_start") max_tries.times do |i|
@env[:machine].config.ssh.max_tries.to_i.times do |i|
if @env[:machine].communicate.ready? if @env[:machine].communicate.ready?
@env[:ui].info I18n.t("vagrant_lxc.messages.container_ready") @env[:ui].info I18n.t("vagrant_lxc.messages.container_ready")
return true return true
@ -29,12 +29,7 @@ module Vagrant
# get shown # get shown
return true if @env[:interrupted] return true if @env[:interrupted]
# If the VM is not starting or running, something went wrong sleep 1 if !@env["vagrant.test"]
# and we need to show a useful error.
state = @env[:machine].provider.state.id
raise Vagrant::Errors::VMFailedToRun unless @states.include?(state)
sleep 2 if !@env["vagrant.test"]
end end
@env[:ui].error I18n.t("vagrant.actions.vm.boot.failed") @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")