Class: VagrantPlugins::WinAzure::Action::WaitForState
- Inherits:
-
Object
- Object
- VagrantPlugins::WinAzure::Action::WaitForState
- Defined in:
- lib/vagrant-azure/action/wait_for_state.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env, state) ⇒ WaitForState
constructor
A new instance of WaitForState.
Constructor Details
#initialize(app, env, state) ⇒ WaitForState
Returns a new instance of WaitForState.
12 13 14 15 16 |
# File 'lib/vagrant-azure/action/wait_for_state.rb', line 12 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
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 44 45 |
# File 'lib/vagrant-azure/action/wait_for_state.rb', line 18 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[: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 |