def __init__(self, reporting, name, address, configData): Thread.__init__(self) self.state = SimpleIssue("Remote run on %s" % name, address) self.conn = None self.cfg = getConfigBits(configData) self.reporting = reporting self.name = name self.address = address
class RemoteTask(Thread): def __init__(self, reporting, name, address, configData): Thread.__init__(self) self.state = SimpleIssue("Remote run on %s" % name, address) self.conn = None self.cfg = getConfigBits(configData) self.reporting = reporting self.name = name self.address = address def run(self): running = True self.reporting.issue(issue=self.state, level=FIRSTAIDKIT, origin=self) self.conn = subprocess.Popen( ["ssh", "-q", "-T", self.address, "firstaidkit-shell"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, close_fds=True) welcomeLine = self.conn.stdout.readline() # start wasn't successful if not welcomeLine.startswith("[firstaidkit-shell] Ready"): self.state.set(checked=True, happened=True, reporting=self.reporting, origin=self) if welcomeLine.startswith( "The autenticity "): # ssh waiting for the fingerprint (report_file, stderr) = self.conn.communicate("no\n") else: (report_file, stderr) = self.conn.communicate() return self.cfg.write(self.conn.stdin) self.conn.stdin.write("\n[commit]\n") welcomeLine = self.conn.stdout.readline() # config wasn't successful if not welcomeLine.startswith("[firstaidkit-shell] Starting"): self.state.set(checked=True, happened=True, reporting=self.reporting, origin=self) (report_file, stderr) = self.conn.communicate("[abort]\n") return else: self.state.set(checked=True, happened=False, reporting=self.reporting, origin=self) while running: try: msg = pickle.load(self.conn.stdout) except pickle.UnpicklingError, e: print e raise if msg["level"] == FIRSTAIDKIT and msg["action"] == END: running = False # set issue origin if it comes from this machine if not msg["remote"] and msg["action"] == ISSUE: msg["message"].remote_name = self.name msg["message"].remote_address = self.address # set message origin and remote state so nobody changes the origin again if not msg["remote"]: msg["remote"] = True msg["remote_name"] = self.name msg["remote_address"] = self.address self.reporting.put_raw(msg) report_file = self.conn.stdout.read() stderr = self.conn.stderr.read() Info.attachRaw(report_file, "remote_report_%s.zip" % self.name) self.conn.wait()
class RemoteTask(Thread): def __init__(self, reporting, name, address, configData): Thread.__init__(self) self.state = SimpleIssue("Remote run on %s" % name, address) self.conn = None self.cfg = getConfigBits(configData) self.reporting = reporting self.name = name self.address = address def run(self): running = True self.reporting.issue(issue = self.state, level = FIRSTAIDKIT, origin = self) self.conn = subprocess.Popen(["ssh", "-q", "-T", self.address, "firstaidkit-shell"], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, bufsize = 1, close_fds = True) welcomeLine = self.conn.stdout.readline() # start wasn't successful if not welcomeLine.startswith("[firstaidkit-shell] Ready"): self.state.set(checked = True, happened = True, reporting = self.reporting, origin = self) if welcomeLine.startswith("The autenticity "): # ssh waiting for the fingerprint (report_file, stderr) = self.conn.communicate("no\n") else: (report_file, stderr) = self.conn.communicate() return self.cfg.write(self.conn.stdin) self.conn.stdin.write("\n[commit]\n") welcomeLine = self.conn.stdout.readline() # config wasn't successful if not welcomeLine.startswith("[firstaidkit-shell] Starting"): self.state.set(checked = True, happened = True, reporting = self.reporting, origin = self) (report_file, stderr) = self.conn.communicate("[abort]\n") return else: self.state.set(checked = True, happened = False, reporting = self.reporting, origin = self) while running: try: msg = pickle.load(self.conn.stdout) except pickle.UnpicklingError, e: print e raise if msg["level"]==FIRSTAIDKIT and msg["action"]==END: running = False # set issue origin if it comes from this machine if not msg["remote"] and msg["action"] == ISSUE: msg["message"].remote_name = self.name msg["message"].remote_address = self.address # set message origin and remote state so nobody changes the origin again if not msg["remote"]: msg["remote"] = True msg["remote_name"] = self.name msg["remote_address"] = self.address self.reporting.put_raw(msg) report_file = self.conn.stdout.read() stderr = self.conn.stderr.read() Info.attachRaw(report_file, "remote_report_%s.zip" % self.name) self.conn.wait()