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