Class: VagrantPlugins::Qubes::Action::WaitForState
- Inherits:
-
Object
- Object
- VagrantPlugins::Qubes::Action::WaitForState
- Defined in:
- lib/vagrant-qubes/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.
11 12 13 14 15 16 |
# File 'lib/vagrant-qubes/action/wait_for_state.rb', line 11 def initialize(app, _env, state, timeout) @app = app @logger = Log4r::Logger.new('vagrant_qubes::action::wait_for_state') @state = state @timeout = timeout 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 |
# File 'lib/vagrant-qubes/action/wait_for_state.rb', line 18 def call(env) env[:result] = 'True' if env[:machine].state.id != @state env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message', message: "Waiting for state \"#{@state}\"") begin Timeout.timeout(@timeout) do until env[:machine].state.id == @state sleep 4 end env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message', message: "Success, state is now \"#{@state}\"") end rescue Timeout::Error env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message', message: "Timeout waiting for \"#{@state}\"") env[:result] = 'False' # couldn't reach state in time end else env[:ui].info I18n.t('vagrant_qubes.vagrant_qubes_message', message: "Success, state is now \"#{@state}\"") end env[:machine].provider_config.saved_ipaddress = nil @app.call(env) end |