utils.py 文件源码

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

项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码
def get_ssh(host, user, password, look_for_keys=True):
    ssh = SSHClient()
    ssh.set_missing_host_key_policy(AutoAddPolicy())
    try:
        try:
            ssh.connect(host, username=user, password=password, timeout=5,
                        look_for_keys=look_for_keys)
        except AuthenticationException as err:
            LOG.error("{0} for host={1} username={2} password={3}".format(
                repr(err), host, user, password
            ))
            raise
        except Exception as e:
            LOG.error(str(e))
            if 'timed out' in str(e) or 'Connection refused' in str(e):
                raise Exception('Connection error: timed out or refused.')
            raise e
        yield ssh
    finally:
        ssh.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号