Class: Vagrant::Action::VM::Boot

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/vm/boot.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Boot

Returns a new instance of Boot.



5
6
7
8
# File 'lib/vagrant/action/vm/boot.rb', line 5

def initialize(app, env)
  @app = app
  @env = env
end

Instance Method Details

#bootObject



20
21
22
23
# File 'lib/vagrant/action/vm/boot.rb', line 20

def boot
  @env[:ui].info I18n.t("vagrant.actions.vm.boot.booting")
  @env[:vm].driver.start(@env[:vm].config.vm.boot_mode)
end

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/vagrant/action/vm/boot.rb', line 10

def call(env)
  @env = env

  # Start up the VM and wait for it to boot.
  boot
  raise Errors::VMFailedToBoot if !wait_for_boot

  @app.call(env)
end

#wait_for_bootObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant/action/vm/boot.rb', line 25

def wait_for_boot
  @env[:ui].info I18n.t("vagrant.actions.vm.boot.waiting")

  @env[:vm].config.ssh.max_tries.to_i.times do |i|
    if @env[:vm].channel.ready?
      @env[:ui].info I18n.t("vagrant.actions.vm.boot.ready")
      return true
    end

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

    # If the VM is not starting or running, something went wrong
    # and we need to show a useful error.
    state = @env[:vm].state
    raise Errors::VMFailedToRun if state != :starting && state != :running

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

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