Sha256: 65b39cdda8e8022797252e39e3a20f35d7379b1028ffb6c9262c3bdbba52a549

Contents?: true

Size: 1.2 KB

Versions: 22

Compression:

Stored size: 1.2 KB

Contents

require "log4r"
require "timeout"

module VagrantPlugins
  module AWS
    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_aws::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_aws.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

22 entries across 22 versions & 7 rubygems

Version Path
vagrant-gecko-aws-0.8.0 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.24 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-detiber-0.7.2.pre.4 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-detiber-0.7.2.pre.3 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-detiber-0.7.2.pre.2 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.22 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.16 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-iam-decoder-0.7.2 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.14 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.11 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.10 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.9 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-mkubenka-0.7.2.pre.8 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-0.7.2 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-0.7.1 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-0.7.0 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-0.6.0 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-0.5.0 lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws_stsmith-0.5.0.dev lib/vagrant-aws/action/wait_for_state.rb
vagrant-aws-stsmith-0.5.0.dev lib/vagrant-aws/action/wait_for_state.rb