def set_password(self, host_id): reader = pxssh.pxssh() host = self.hosts[host_id] try: reader.login(host['address'], host['user'], password=self.passwords[0], port=host['port']) except Exception, e: print "Failed to ssh to station '%s'" % host_id return
def run(self): try: while 1: #pxssh.pxssh() # .login( # address, # username, # password=, # original_prompt=, # login_timeout=, # port=, # quiet=, # sync_multiplier=, # check_local_ip= # ) # self.conn = pxssh.pxssh() self.log("Connectiong to %s:%d ..." % (self.host,self.port)) self.conn.login(self.host, self.username, password=self.password, port=self.port) self.log("Connected.") self.conn.sendline("ls") self.conn.prompt() self.log("Proof:" + self.conn.before) self.log("Adding forwards:") self.log(" Testing, so nothing yet.") self.log("All forwards added.") self.log("Connected. Entering the keep-alive loop ...") while open: time.sleep(self.delay) self.conn.sendline() if not self.conn.prompt(timeout=5.0): self.log("Connection to %s:%d dropped. Will re-open" % (self.host,self.port)) self.conn.logout() break self.log("Connection is up.") except KeyboardInterrupt: pass self.log_thread.halt()