in cstar/remote_paramiko.py [0:0]
def _connect(self):
if self.client:
# Ensure underlying client is still a valid open connection
try:
stdin, stdout, stderr = self.client.exec_command(PING_COMMAND)
except (ConnectionResetError, paramiko.ssh_exception.SSHException):
# ConnectionResetError is raised when a connection was established but then broken
# paramiko.ssh_exception.SSHException is raised if the connection was known to be broken
self.client = None
if not self.client:
try:
self.client = paramiko.client.SSHClient()
pkey = None
if self.ssh_identity_file != None:
pkey = paramiko.RSAKey.from_private_key_file(self.ssh_identity_file, None)
debug("Username : ", self.ssh_username)
debug("Id file: ", self.ssh_identity_file)
self.client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
self.client.connect(self.hostname, compress=True, username=self.ssh_username, password=self.ssh_password, pkey=pkey)
# Enable keepalive to improve connection stability when running commands that return no output for
# long periods of time.
transport = self.client.get_transport()
transport.set_keepalive(5)
except:
self.client = None
raise BadSSHHost("Could not establish an SSH connection to host %s" % (self.hostname,))