def _connect_ssh(self):
"""Open a new SSH connection using Paramiko."""
try:
self.printer.verbose("[SSH] Connecting ({}:{})...".format(self._ip, self._port))
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self._ip, port=self._port, username=self._username, password=self._password,
allow_agent=self._pub_key_auth, look_for_keys=self._pub_key_auth)
self.printer.notify("[SSH] Connected ({}:{})".format(self._ip, self._port))
return ssh
except paramiko.AuthenticationException as e:
raise Exception('Authentication failed when connecting to %s. %s: %s' % (self._ip, type(e).__name__, e.message))
except paramiko.SSHException as e:
raise Exception('Connection dropped. Please check your connection with the device, '
'and reload the module. %s: %s' % (type(e).__name__, e.message))
except Exception as e:
raise Exception('Could not open a connection to %s. %s - %s' % (self._ip, type(e).__name__, e.message))
评论列表
文章目录