Python paramiko 模块,ssh_exception() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用paramiko.ssh_exception()

项目: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)