ssh_transport.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:bastion-ssh 作者: wcc526 项目源码 文件源码
def __init__(self, context):
        self.context = context
        self.connection_attempts = 20
        self.transport = None
        self.client = paramiko.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        for tries in range(self.connection_attempts):
            try:
                self.client.connect(hostname=self.context.hostname,
                                    username=self.context.username,
                                    port=self.context.port,
                                    allow_agent=True,
                                    look_for_keys=True)
                break
            except paramiko.ssh_exception.AuthenticationException, paramiko.ssh_exception.SSHException:
                LOG.warning("Unable to authenticate with remote server")
                raise bastion_ssh.errors.ConnectionError(
                    "Unable to authenticate with remote server")
            except (socket.error, EOFError):
                LOG.warning("connection refused. retrying.")
                time.sleep(tries + 1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号