def get_all_log_data(credential): results = { "results": None, "error": None, } try: results["cluster"] = credential.cluster.name ssh = credential.get_ssh_connection() sftp = credential.get_sftp_connection() except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results with ssh, sftp: err = add_fileparser(ssh, sftp) if err: results["error"] = err return results command = "python chemtools/fileparser.py -L -f chemtools/done" _, stdout, stderr = ssh.exec_command(command) if err: results["error"] = err return results results["results"] = stdout.read() return results
def get_log_data(credential, names): results = { "results": None, "error": None, } try: results["cluster"] = credential.cluster.name ssh = credential.get_ssh_connection() sftp = credential.get_sftp_connection() except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results with ssh, sftp: err = add_fileparser(ssh, sftp) if err: results["error"] = err return results # this is partially for security, and partially to not just give the # file parser a massive block of filenames. # TODO: Make this thread safe with sftp.open("chemtools/files", 'w') as f: for filename in names: f.write('chemtools/done/%s.log\n' % filename) command = "python chemtools/fileparser.py -L -i chemtools/files" _, stdout, stderr = ssh.exec_command(command) err = stderr.read() if err: results["error"] = err return results results["results"] = stdout.read() return results