from conductor.ConductorWorker import ConductorWorker import configparser import sys import os from pyexecplugins.pyexecplugins import * from pyexecplugins.Ansible import Ansible def pyexec(task): try: print("Executing task {} of type {}[{}] from wkf {}[{}]".format(task["workflowTask"]["taskReferenceName"], task["taskDefName"], task["taskId"], task["workflowType"], task["workflowInstanceId"])) operation = task["inputData"].get("operation") or "Nop" p = PyExecPlugin.get(operation) if p != None: pi = p(task["inputData"]) ret = pi.execute() else: raise Exception("Operation {} not found.".format(operation)) return { "status" : "COMPLETED", "output" : ret, "logs" : ["one","two"]} except Exception as exc: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno) return { "status" : "FAILED", "output" : { "message" : "Internal error: {}".format(exc)}, "logs" : ["one","two"]} def main(): print("Started PyExec with plugins:", PyExecPlugin.getPlugins()) cfg = configparser.ConfigParser() cfg.read("config.cfg") threads = cfg["pyexec"].getint("threads") pollrate = cfg["pyexec"].getfloat("pollrate") server = os.environ.get('CONDUCTOR_SERVER', cfg["common"]["server"]) domain = cfg["pyexec"].get("domain") if domain is None: domain = cfg["common"].get("domain") elif cfg["common"].get("domain") is not None: domain = domain + "," + cfg["common"].get("domain") cc = ConductorWorker(server, threads, pollrate, "pyexec") cc.start('pyexec', pyexec, True, domain) if __name__ == '__main__': main()