Class: VagrantPlugins::ProviderZone::Action::WaitTillBoot

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

Overview

This is used wait till the zone is booted

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ WaitTillBoot

Returns a new instance of WaitTillBoot.



14
15
16
17
# File 'lib/vagrant-zones/action/wait_till_boot.rb', line 14

def initialize(app, _env)
  @logger = Log4r::Logger.new('vagrant_zones::action::import')
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vagrant-zones/action/wait_till_boot.rb', line 39

def call(env)
  @machine = env[:machine]
  @driver  = @machine.provider.driver
  ui = env[:ui]
  # Initialize metrics if they haven't been
  env[:metrics] ||= {}
  env[:metrics]['instance_boot_time'] = Util::Timer.time do
    next if env[:interrupted]

    breakwait = @driver.waitforboot(ui, env[:metrics], env[:interrupted])
    ui.info(I18n.t('vagrant_zones.boot_ready') + " in #{env[:metrics]['instance_boot_time']} Seconds") if breakwait
    break if breakwait
  end
  return terminate(env) if env[:interrupted]

  @app.call(env)
end

#terminate(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vagrant-zones/action/wait_till_boot.rb', line 19

def terminate(env)
  return unless env[:machine].state.id != :not_created

  # If we're not supposed to destroy on error then just return
  return unless env[:destroy_on_error]

  if env[:halt_on_error]
    halt_env = env.dup
    halt_env.delete(:interrupted)
    halt_env[:config_validate] = false
    env[:action_runner].run(Action.action_halt, halt_env)
  else
    destroy_env = env.dup
    destroy_env.delete(:interrupted)
    destroy_env[:config_validate] = false
    destroy_env[:force_confirm_destroy] = true
    env[:action_runner].run(Action.action_destroy, destroy_env)
  end
end