Class: VagrantPlugins::ProviderZone::Action::WaitTillUp

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

Overview

This is used wait till the zone is booted

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ WaitTillUp

Returns a new instance of WaitTillUp.



14
15
16
17
# File 'lib/vagrant-zones/action/wait_till_up.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
56
57
58
59
60
61
# File 'lib/vagrant-zones/action/wait_till_up.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_ssh_time'] = Util::Timer.time do
    retryable(on: Errors::TimeoutError, tries: 60) do
      # If we're interrupted don't worry about waiting
      next if env[:interrupted]

      loop do
        break if env[:interrupted]
        break if env[:machine].communicate.ready?
      end
    end
  end
  # if interrupted above, just terminate immediately
  return terminate(env) if env[:interrupted]

  ui.info(I18n.t('vagrant_zones.ssh_ready') + " in #{env[:metrics]['instance_ssh_time']} Seconds")
  @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_up.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