conductor-worker-python/pyexec.py

48 lines
1.8 KiB
Python
Raw Normal View History

2020-06-19 10:50:02 +02:00
from conductor.ConductorWorker import ConductorWorker
import configparser
2020-07-06 12:22:52 +02:00
import sys
import os
2020-06-19 10:50:02 +02:00
from pyexecplugins.pyexecplugins import *
2020-10-02 14:56:45 +02:00
from pyexecplugins.Ansible import Ansible
2020-06-19 10:50:02 +02:00
def pyexec(task):
try:
2020-07-06 12:22:52 +02:00
print("Executing task {} of type {}[{}] from wkf {}[{}]".format(task["workflowTask"]["taskReferenceName"], task["taskDefName"], task["taskId"], task["workflowType"], task["workflowInstanceId"]))
2020-06-19 10:50:02 +02:00
2020-07-06 12:22:52 +02:00
operation = task["inputData"].get("operation") or "Nop"
2020-06-19 10:50:02 +02:00
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"]}
2020-07-06 12:22:52 +02:00
except Exception as exc:
2020-06-19 10:50:02 +02:00
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)
2020-07-06 12:22:52 +02:00
return { "status" : "FAILED", "output" : { "message" : "Internal error: {}".format(exc)}, "logs" : ["one","two"]}
2020-06-19 10:50:02 +02:00
def main():
print("Started PyExec with plugins:", PyExecPlugin.getPlugins())
2020-07-06 12:22:52 +02:00
2020-06-19 10:50:02 +02:00
cfg = configparser.ConfigParser()
cfg.read("config.cfg")
threads = cfg["pyexec"].getint("threads")
pollrate = cfg["pyexec"].getfloat("pollrate")
2020-07-15 09:34:49 +02:00
server = os.environ.get('CONDUCTOR_SERVER', cfg["common"]["server"])
2020-10-08 14:43:35 +02:00
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")
2020-07-15 09:34:49 +02:00
cc = ConductorWorker(server, threads, pollrate, "pyexec")
2020-10-08 14:43:35 +02:00
cc.start('pyexec', pyexec, True, domain)
2020-06-19 10:50:02 +02:00
if __name__ == '__main__':
main()