Class: VagrantPlugins::ProviderBhyve::Action::WaitUntilUP

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-bhyve/action/wait_until_up.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ WaitUntilUP

Returns a new instance of WaitUntilUP.



10
11
12
13
# File 'lib/vagrant-bhyve/action/wait_until_up.rb', line 10

def initialize(app, env)
  @logger = Log4r::Logger.new("vagrant_bhyve::action::wait_until_up")
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant-bhyve/action/wait_until_up.rb', line 15

def call(env)
  @driver = env[:machine].provider.driver
  env[:ui].info I18n.t('vagrant_bhyve.action.vm.boot.wait_until_up')

  vm_name = @driver.get_attr('vm_name')
  # Check whether ip is assigned
  env[:uncleaned] = false
  while !env[:uncleaned]
    sleep 1
    env[:uncleaned] = true if @driver.state(vm_name) == :uncleaned
    if @driver.ip_ready?
      sleep 2
      env[:uncleaned] = true if @driver.state(vm_name) == :uncleaned
      break
    end
  end
  
  # Check whether we have ssh access
  while !env[:uncleaned]
    sleep 1
    env[:uncleaned] = true if @driver.state(vm_name) == :uncleaned
    if @driver.ssh_ready?(env[:machine].provider.ssh_info)
      sleep 2
      env[:uncleaned] = true if @driver.state(vm_name) == :uncleaned
      break
    end
  end
  @app.call(env)
end