Method: Beaker::SshConnection#connect_block
- Defined in:
- lib/beaker/ssh_connection.rb
#connect_block(host, user, ssh_opts, options) ⇒ Net::SSH::Connection::Session
Note:
For more information about Net::SSH library, check out these docs:
Setup and return the ssh connection object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/beaker/ssh_connection.rb', line 64 def connect_block host, user, ssh_opts, try = 1 last_wait = 2 wait = 3 max_connection_tries = [:max_connection_tries] || 11 begin @logger.debug "Attempting ssh connection to #{host}, user: #{user}, opts: #{ssh_opts}" if ssh_opts.include?(:strict_host_key_checking) && (Net::SSH::Version::CURRENT.major > 5) ssh_opts[:paranoid] = ssh_opts.delete(:strict_host_key_checking) end Net::SSH.start(host, user, ssh_opts) rescue *RETRYABLE_EXCEPTIONS => e if try <= max_connection_tries @logger.warn "Try #{try} -- Host #{host} unreachable: #{e.class.name} - #{e.message}" unless [:silent] @logger.warn "Trying again in #{wait} seconds" unless [:silent] sleep wait (last_wait, wait) = wait, last_wait + wait try += 1 retry else @logger.warn "Failed to connect to #{host}, after #{try} attempts" unless [:silent] nil end end end |