Class: VagrantPlugins::Azure::Action::WaitForState
- Inherits:
-
Object
- Object
- VagrantPlugins::Azure::Action::WaitForState
- Defined in:
- lib/vagrant-azure/action/wait_for_state.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env, state, timeout) ⇒ WaitForState
constructor
env will be false in case of timeout.
Constructor Details
#initialize(app, env, state, timeout) ⇒ WaitForState
env will be false in case of timeout.
15 16 17 18 19 20 21 |
# File 'lib/vagrant-azure/action/wait_for_state.rb', line 15 def initialize(app, env, state, timeout) @app = app @logger = Log4r::Logger.new('vagrant_azure::action::wait_for_state') @state = state @timeout = timeout @env = env end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vagrant-azure/action/wait_for_state.rb', line 23 def call(env) env[:result] = true if env[:machine].state.id == @state @logger.info(I18n.t('vagrant_azure.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 |