improved command line args
This commit is contained in:
parent
c6b4b0569b
commit
a9dbc1c1ff
15
PyExec.py
15
PyExec.py
|
@ -4,14 +4,15 @@ import logging
|
|||
import sys
|
||||
import os
|
||||
import random
|
||||
import argparse
|
||||
from pyexecplugins.pyexecplugins import *
|
||||
from conductor.ConductorWorker import ConductorWorker
|
||||
|
||||
class PyExec():
|
||||
errors = { "info" : logging.INFO, "error" : logging.ERROR, "debug" : logging.DEBUG}
|
||||
|
||||
def __init__(self, pluginlist):
|
||||
self.init(pluginlist)
|
||||
def __init__(self, args):
|
||||
self.init(args.config, args.commands)
|
||||
|
||||
def computeDomain(self, plg):
|
||||
domain = self.getDomain(plg)
|
||||
|
@ -28,9 +29,9 @@ class PyExec():
|
|||
else:
|
||||
return None
|
||||
|
||||
def init(self, pluginlist):
|
||||
def init(self, config, pluginlist):
|
||||
self.cfg = configparser.ConfigParser()
|
||||
self.cfg.read("config.cfg")
|
||||
self.cfg.read(config)
|
||||
self.workerid = self.cfg["common"].get("workerid", "pythonworker-" + str(random.randint(1000,10000)))
|
||||
logging.basicConfig()
|
||||
self.logger = logging.getLogger("pyexec")
|
||||
|
@ -99,5 +100,9 @@ class PyExec():
|
|||
return { "status" : "FAILED", "output" : { "message" : str(exc) }, "logs" : ["one","two"]}
|
||||
|
||||
if __name__ == '__main__':
|
||||
pyexec = PyExec(sys.argv[1:])
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-c', '--config', nargs="?", const='config.cfg', help='Specify a config file. Default is config.cfg')
|
||||
parser.add_argument('commands', nargs='+', help='Use Ansible, Packer, Http, Eval for declaring the tasks to poll for')
|
||||
args = parser.parse_args()
|
||||
pyexec = PyExec(args)
|
||||
pyexec.start()
|
||||
|
|
Loading…
Reference in New Issue