Class: VagrantPlugins::ESXi::Action::WaitForState
- Inherits:
-
Object
- Object
- VagrantPlugins::ESXi::Action::WaitForState
- Defined in:
- lib/vagrant-vmware-esxi/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
env will be false in case of timeout.
Constructor Details
#initialize(app, _env, state, timeout) ⇒ WaitForState
env will be false in case of timeout.
13 14 15 16 17 18 |
# File 'lib/vagrant-vmware-esxi/action/wait_for_state.rb', line 13 def initialize(app, _env, state, timeout) @app = app @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::wait_for_state') @state = state @timeout = timeout end |
Instance Method Details
#call(env) ⇒ Object
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 47 |
# File 'lib/vagrant-vmware-esxi/action/wait_for_state.rb', line 20 def call(env) env[:result] = 'True' if env[:machine].state.id != @state env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_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_vmware_esxi.vagrant_vmware_esxi_message', message: "Success, state is now \"#{@state}\"") end rescue Timeout::Error if @state.to_s == 'running' raise Errors::GeneralError, message: 'Failed, timeout waiting for "running".' else env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message', message: "Timeout waiting for \"#{@state}\"") env[:result] = 'False' # couldn't reach state in time end end end env[:machine].provider_config.saved_ipaddress = nil @app.call(env) end |