def __init__(self, sshhost, username, pwd, port=None, use_log=False):
"""
Constructor for the SSH class.
This constructor connects automatically to sshhost over ssh so manual
calling of the connect function is not necessary.
sshhost -- the host to connect to.
username -- the username to use.
pwd -- the password.
port -- the port to connect to.
use_log -- Whether to log the ssh connection in a logfile. (Default is False)
"""
self.sshhost = sshhost
self.username = username
self.pwd = pwd
self.client = SSHClient()
# only activate when non-agent, as this will throw unhandled prompts
# self.client.set_missing_host_key_policy(WarningPolicy())
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.client.load_system_host_keys()
#this is done because the buyers return before they finish buying a vps, which might connect timeouts
#ToDo make vpsbuyers terminate only once server is online https://github.com/Skynet2-0/Skynet2.0/issues/60
tries = 30
while tries>=0:
try:
self.connect(port=port)
break
except socket.error:
#retry to connect
tries-=1
s = Settings()
if s.enable_global_ssh_logging():
self.use_logfile(True)
else:
self.use_logfile(use_log)
评论列表
文章目录