Sha256: 6eb5317feaae87f83c3d2f4fb2133a736da10551330d04217927d6f0883a3c3a

Contents?: true

Size: 721 Bytes

Versions: 4

Compression:

Stored size: 721 Bytes

Contents

require 'net/ssh'

module AmiSpec
  class WaitForSSH
    def self.wait(ip_address, user, key, max_retries)
      last_error = nil
      retries = 0

      while retries < max_retries
        begin
          Net::SSH.start(ip_address, user, keys: [key], :verify_host_key => :never) { |ssh| ssh.exec 'echo boo!' }
        rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Timeout::Error, Net::SSH::Exception => error
          last_error = error
          sleep 1
        else
          break
        end

        retries = retries + 1
      end

      if retries > max_retries - 1
        raise AmiSpec::InstanceConnectionTimeout.new("Timed out waiting for SSH to become available: #{last_error}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ami_spec-1.8.2 lib/ami_spec/wait_for_ssh.rb
ami_spec-1.8.1 lib/ami_spec/wait_for_ssh.rb
ami_spec-1.8.0 lib/ami_spec/wait_for_ssh.rb
ami_spec-1.7.0 lib/ami_spec/wait_for_ssh.rb