Class: VagrantPlugins::OpenStack::Action::WaitForState
- Inherits:
-
Object
- Object
- VagrantPlugins::OpenStack::Action::WaitForState
- Defined in:
- lib/vagrant-openstack-plugin/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
- #call(env) ⇒ Object
-
#initialize(app, env, state, timeout) ⇒ WaitForState
constructor
A new instance of WaitForState.
Constructor Details
#initialize(app, env, state, timeout) ⇒ WaitForState
Returns a new instance of WaitForState.
10 11 12 13 14 15 |
# File 'lib/vagrant-openstack-plugin/action/wait_for_state.rb', line 10 def initialize(app, env, state, timeout) @app = app @logger = Log4r::Logger.new('vagrant_openstack::action::wait_for_state') @state = Array.new(state).flatten @timeout = timeout end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vagrant-openstack-plugin/action/wait_for_state.rb', line 17 def call(env) env[:result] = true state = env[:machine].state.id.to_sym if @state.include?(state) @logger.info("Machine already at status #{ state.to_s }") else @logger.info("Waiting for machine to reach state...") begin Timeout.timeout(@timeout) do sleep 2 until @state.include?(env[:machine].state.id) end rescue Timeout::Error env[:result] = false end @app.call(env) end end |