Sha256: 94a834554a6e2ecf8ba9509435cb562745772e211f5db1167616e9260a855fac

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

# coding: utf-8
require 'log4r'
require 'timeout'

module VagrantPlugins
  module OpenStack
    module Action
      # This action will wait for a machine to reach a specific state or quit by timeout.
      class WaitForState
        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

        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
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
vagrant-openstack-plugin-tom-0.12.0 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.12.0 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.11.1 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.11.0 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.10.0 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.9.1 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.9.0 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.8.0 lib/vagrant-openstack-plugin/action/wait_for_state.rb
vagrant-openstack-plugin-0.7.0 lib/vagrant-openstack-plugin/action/wait_for_state.rb