class Beaker::SshConnection
def connect_block host, user, ssh_opts, options
-
(Net::SSH::Connection::Session)
- session returned from Net::SSH.start method
Options Hash:
(**options)
-
:silent
(Boolean
) -- Stops logging attempt failure messages if set to true -
:max_connection_tries
(Integer
) -- Limit the number of connection start
Parameters:
-
options
(Hash{Symbol=>String}
) -- Options hash to control method conditionals -
ssh_opts
(Hash{Symbol=>String}
) -- Options hash passed directly to Net::SSH.start method -
user
(String
) -- username to login to the host as -
host
(String
) -- hostname of the machine to connect to
Other tags:
- Note: - For more information about Net::SSH library, check out these docs:
def connect_block host, user, ssh_opts, options try = 1 last_wait = 2 wait = 3 max_connection_tries = options[:max_connection_tries] || 11 begin @logger.debug "Attempting ssh connection to #{host}, user: #{user}, opts: #{ssh_opts}" # Work around net-ssh 6+ incompatibilities if ssh_opts.include?(:strict_host_key_checking) && (Net::SSH::Version::CURRENT.major > 5) strict_host_key_checking = ssh_opts.delete(:strict_host_key_checking) unless ssh_opts[:verify_host_key].is_a?(Symbol) ssh_opts[:verify_host_key] ||= strict_host_key_checking ? :always : :never end 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 options[:silent] @logger.warn "Trying again in #{wait} seconds" unless options[: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 options[:silent] nil end end end