def __init__(self, host, log=None, ssh_log=None, username=None,
password=None, look_for_keys=True, key_filename=None):
paramiko.SSHClient.__init__(self)
self.host = host
self.log = log
self.ssh_log = ssh_log
if ssh_log is not None:
paramiko.util.log_to_file(ssh_log)
elif log is not None:
if self.log.get_level() == Logger.DEBUG:
ssh_log = FILE_PATH[:FILE_PATH.rfind('/')]
ssh_log += '/ssh_paramiko.log'
paramiko.util.log_to_file(ssh_log)
if key_filename is None:
self.load_system_host_keys()
self.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
self.connect(
host,
username=username,
password=password,
look_for_keys=look_for_keys,
key_filename=key_filename)
except (
paramiko.BadHostKeyException,
paramiko.AuthenticationException,
paramiko.SSHException,
socket.error,
BaseException) as exc:
if log is not None:
self.log.error('%s: %s' % (host, str(exc)))
else:
print('%s: %s' % (host, str(exc)))
raise SSH_Exception('Connection Failure - {}'.format(exc))
ssh.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录