Sha256: 9242dd28c798eeaed8e4a7964ab142178fb708050e45adc9496a4f5a2a6fa1c7

Contents?: true

Size: 1.22 KB

Versions: 17

Compression:

Stored size: 1.22 KB

Contents

require "log4r"
require "timeout"

module VagrantPlugins
  module Cloudstack
    module Action
      # This action will wait for a machine to reach a specific state or quit by timeout
      class WaitForState
        # env[:result] will be false in case of timeout.
        # @param [Symbol] state Target machine state.
        # @param [Number] timeout Timeout in seconds.
        def initialize(app, env, state, timeout)
          @app     = app
          @logger  = Log4r::Logger.new("vagrant_cloudstack::action::wait_for_state")
          @state   = state
          @timeout = timeout
        end

        def call(env)
          env[:result] = true
          if env[:machine].state.id == @state
            @logger.info(I18n.t("vagrant_cloudstack.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
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
vagrant-cloudstack-1.5.2 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-1.5.1 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-1.5.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-1.4.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-1.1.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-1.0.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.10.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.9.1 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.9.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.8.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.7.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.6.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.5.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.4.1 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.4.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.2.0 lib/vagrant-cloudstack/action/wait_for_state.rb
vagrant-cloudstack-0.1.0 lib/vagrant-cloudstack/action/wait_for_state.rb