lib/train/transports/ssh_connection.rb
# Establish an SSH session on the remote host.
#
# @param opts [Hash] retry options
# @option opts [Integer] :retries the number of times to retry before
#   failing
# @option opts [Float] :delay the number of seconds to wait until
#   attempting a retry
# @option opts [String] :message an optional message to be logged on
#   debug (overriding the default) when a rescuable exception is raised
# @return [Net::SSH::Connection::Session] the SSH connection session
# @api private
Establish an SSH session on the remote host.
Establish an SSH session on the remote host .
def establish_connection(opts)
      logger.debug("[SSH] opening connection to #{self}")
      if check_proxy
        require 'net/ssh/proxy/command'
        @options[:proxy] = Net::SSH::Proxy::Command.new(generate_proxy_command)
      end
      Net::SSH.start(@hostname, @username, @options.clone.delete_if { |_key, value| value.nil? })
    rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH => e
      if (opts[:retries] -= 1) <= 0
        logger.warn("[SSH] connection failed, terminating (#{e.inspect})")
        raise Train::Transports::SSHFailed, 'SSH session could not be established'
      end
      if opts[:message]
        logger.debug("[SSH] connection failed (#{e.inspect})")
        message = opts[:message]
      else
        message = "[SSH] connection failed, retrying in #{opts[:delay]}"\
                  " seconds (#{e.inspect})"
      end
      logger.info(message)
      sleep(opts[:delay])
      retry
    end
def establish_connection ( opts ) logger . debug ( "[SSH] opening connection to #{self}" ) if check_proxy require 'net/ssh/proxy/command' @options [ :proxy ] = Net :: SSH :: Proxy :: Command . new ( generate_proxy_command ) end Net :: SSH . start ( @hostname , @username , @options . clone . delete_if { | _key , value | value . nil? } ) rescue * RESCUE_EXCEPTIONS_ON_ESTABLISH => e if ( opts [ :retries ] -= 1 ) <= 0 logger . warn ( "[SSH] connection failed, terminating (#{e.inspect})" ) raise Train :: Transports :: SSHFailed , 'SSH session could not be established' end if opts [ :message ] logger . debug ( "[SSH] connection failed (#{e.inspect})" ) message = opts [ :message ] else message = "[SSH] connection failed, retrying in #{opts[:delay]}" " seconds (#{e.inspect})" end logger . info ( message ) sleep ( opts [ :delay ] ) retry end
Establish an SSH session on the remote host.
Establish an SSH session on the remote host .
the SSH connection session
the SSH connection session
Net::SSH::Connection::Session
opts
:message an optional message to be logged on debug (overriding the default) when a rescuable exception is raised
: message an optional message to be logged on debug ( overriding the default ) when a rescuable exception is raised
api
None