Class: VagrantPlugins::WinAzure::Action::WaitForState

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env, state) ⇒ WaitForState

Returns a new instance of WaitForState.



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

def initialize(app, env, state)
  @app = app
  @state = state
  @logger = Log4r::Logger.new("vagrant_azure::action::wait_for_state")
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
38
39
40
41
42
43
44
45
46
# File 'lib/vagrant-azure/action/wait_for_state.rb', line 19

def call(env)
  env[:result] = true

  if env[:machine].state.id == @state
    @logger.info(
      I18n.t('vagrant_azure.already_status', :status => @state)
    )
  else
    timeout = env[:machine].provider_config.state_read_timeout || env[:machine].config.vm.boot_timeout

    env[:ui].info "Waiting for machine to reach state #{@state}"
    @logger.info("Waiting for machine to reach state #{@state}")

    begin
      Timeout.timeout(timeout)  do
        until env[:machine].state.id == @state
          sleep 30
        end
      end
      env[:ui].success "Machine reached state #{@state}"
    rescue Timeout::Error
      env[:ui].error "Machine failed to reached state '#{@state}' in '#{timeout}' seconds."
      env[:result] = false # couldn't reach state in time
    end
  end

  @app.call(env)
end