common.py 文件源码

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

项目:geppetto 作者: datosio 项目源码 文件源码
def is_ssh_ready(ip, username, password=None, key=None):
    """
    Checks if it is possible to connect to the ip using the credentials.
    :param ip: ip to check for ssh connectivity
    :param username: username
    :param password: password
    :param key: pass to *.pem key
    :return: boolean of the connection state
    """
    try:
        private_key = paramiko.RSAKey.from_private_key_file(os.path.expanduser(key))
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(ip, username=username, password=password, pkey=private_key)
        ssh.close()
        return True
    except Exception:
        report("SSH is not responsive for %s:\n%s" % (ip, traceback.format_exc()))
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号