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
评论列表
文章目录