Class: VagrantPlugins::AWS::Action::WaitForState

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-aws/action/wait_for_state.rb

Overview

This action will wait for a machine to reach a specific state or quit by timeout

Instance Method Summary collapse

Constructor Details

#initialize(app, env, state, timeout) ⇒ WaitForState

env will be false in case of timeout.

Parameters:

  • state (Symbol)

    Target machine state.

  • timeout (Number)

    Timeout in seconds.



12
13
14
15
16
17
# File 'lib/vagrant-aws/action/wait_for_state.rb', line 12

def initialize(app, env, state, timeout)
  @app     = app
  @logger  = Log4r::Logger.new("vagrant_aws::action::wait_for_state")
  @state   = state
  @timeout = timeout
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  env[:result] = true
  if env[:machine].state.id == @state
    @logger.info(I18n.t("vagrant_aws.already_status", :status => @state))
  else
    @logger.info("Waiting for machine to reach state #{@state}")
    begin
      Timeout.timeout(@timeout) do
        until env[:machine].state.id == @state
          sleep 2
        end
      end
    rescue Timeout::Error
      env[:result] = false # couldn't reach state in time
    end
  end

  @app.call(env)
end