Sha256: 061d202293211be9e4929b8f477c1a7b2de61f603d81f0d81c2c1ac6779647ef

Contents?: true

Size: 689 Bytes

Versions: 7

Compression:

Stored size: 689 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], paranoid: false) { |ssh| ssh.exec 'echo boo!' }
        rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Timeout::Error => 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

7 entries across 7 versions & 1 rubygems

Version Path
ami_spec-1.2.0 lib/ami_spec/wait_for_ssh.rb
ami_spec-1.1.0 lib/ami_spec/wait_for_ssh.rb
ami_spec-1.0.1 lib/ami_spec/wait_for_ssh.rb
ami_spec-1.0.0 lib/ami_spec/wait_for_ssh.rb
ami_spec-0.3.0 lib/ami_spec/wait_for_ssh.rb
ami_spec-0.2.0 lib/ami_spec/wait_for_ssh.rb
ami_spec-0.1.0 lib/ami_spec/wait_for_ssh.rb