Fix dry_run and logging.
This commit is contained in:
parent
05cf492744
commit
686a484b03
1 changed files with 12 additions and 8 deletions
|
@ -43,7 +43,7 @@ class Trigger():
|
||||||
self.http_port = int(http_port)
|
self.http_port = int(http_port)
|
||||||
self.ipv6 = ipv6
|
self.ipv6 = ipv6
|
||||||
self.args = cdistargs
|
self.args = cdistargs
|
||||||
log.debug("IPv6: {0}", self.ipv6)
|
log.debug("IPv6: %s", self.ipv6)
|
||||||
|
|
||||||
def run_httpd(self):
|
def run_httpd(self):
|
||||||
server_address = ('', self.http_port)
|
server_address = ('', self.http_port)
|
||||||
|
@ -54,7 +54,9 @@ class Trigger():
|
||||||
httpdcls = HTTPServerV4
|
httpdcls = HTTPServerV4
|
||||||
httpd = httpdcls(self.args, server_address, TriggerHttp)
|
httpd = httpdcls(self.args, server_address, TriggerHttp)
|
||||||
|
|
||||||
log.debug("Starting server at port {}", self.http_port)
|
log.debug("Starting server at port %d", self.http_port)
|
||||||
|
if self.dry_run:
|
||||||
|
log.debug("Running in dry run mode")
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -67,7 +69,8 @@ class Trigger():
|
||||||
ipv6 = args.ipv6
|
ipv6 = args.ipv6
|
||||||
del args.http_port
|
del args.http_port
|
||||||
del args.ipv6
|
del args.ipv6
|
||||||
t = Trigger(http_port=http_port, ipv6=ipv6, cdistargs=args)
|
t = Trigger(http_port=http_port, dry_run=args.dry_run, ipv6=ipv6,
|
||||||
|
cdistargs=args)
|
||||||
t.run()
|
t.run()
|
||||||
|
|
||||||
class TriggerHttp(http.server.BaseHTTPRequestHandler):
|
class TriggerHttp(http.server.BaseHTTPRequestHandler):
|
||||||
|
@ -84,13 +87,13 @@ class TriggerHttp(http.server.BaseHTTPRequestHandler):
|
||||||
else:
|
else:
|
||||||
code = 404
|
code = 404
|
||||||
if mode:
|
if mode:
|
||||||
log.debug("Running cdist for {0} in mode {1}", host, mode)
|
log.debug("Running cdist for %s in mode %s", host, mode)
|
||||||
if self.dry_run:
|
if self.server.dry_run:
|
||||||
log.info("Dry run, skipping cdist execution")
|
log.info("Dry run, skipping cdist execution")
|
||||||
else:
|
else:
|
||||||
self.run_cdist(mode, host)
|
self.run_cdist(mode, host)
|
||||||
else:
|
else:
|
||||||
log.info("Unsupported path {1}, ignoring", mode, self.path)
|
log.info("Unsupported mode in path %s, ignoring", self.path)
|
||||||
|
|
||||||
self.send_response(code)
|
self.send_response(code)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
@ -102,7 +105,7 @@ class TriggerHttp(http.server.BaseHTTPRequestHandler):
|
||||||
self.do_GET()
|
self.do_GET()
|
||||||
|
|
||||||
def run_cdist(self, mode, host):
|
def run_cdist(self, mode, host):
|
||||||
log.debug("Running cdist {} {}".format(mode, host))
|
log.debug("Running cdist {%s} {%s}", mode, host)
|
||||||
|
|
||||||
cname = mode.title()
|
cname = mode.title()
|
||||||
module = getattr(cdist, mode)
|
module = getattr(cdist, mode)
|
||||||
|
@ -115,7 +118,7 @@ class TriggerHttp(http.server.BaseHTTPRequestHandler):
|
||||||
host_base_path, hostdir = theclass.create_host_base_dirs(
|
host_base_path, hostdir = theclass.create_host_base_dirs(
|
||||||
host, theclass.create_base_root_path(out_path))
|
host, theclass.create_base_root_path(out_path))
|
||||||
theclass.construct_remote_exec_copy_patterns(self.cdistargs)
|
theclass.construct_remote_exec_copy_patterns(self.cdistargs)
|
||||||
log.debug("Executing cdist onehost with params: {0}, {1}, {2}, {3}, ",
|
log.debug("Executing cdist onehost with params: %s, %s, %s, %s, ",
|
||||||
host, host_base_path, hostdir, self.cdistargs)
|
host, host_base_path, hostdir, self.cdistargs)
|
||||||
theclass.onehost(host, host_base_path, hostdir, self.cdistargs,
|
theclass.onehost(host, host_base_path, hostdir, self.cdistargs,
|
||||||
parallel=False)
|
parallel=False)
|
||||||
|
@ -129,6 +132,7 @@ class HTTPServerV6(socketserver.ForkingMixIn, http.server.HTTPServer):
|
||||||
|
|
||||||
def __init__(self, cdistargs, *args, **kwargs):
|
def __init__(self, cdistargs, *args, **kwargs):
|
||||||
self.cdistargs = cdistargs
|
self.cdistargs = cdistargs
|
||||||
|
self.dry_run = cdistargs.dry_run
|
||||||
http.server.HTTPServer.__init__(self, *args, **kwargs)
|
http.server.HTTPServer.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
class HTTPServerV4(HTTPServerV6):
|
class HTTPServerV4(HTTPServerV6):
|
||||||
|
|
Loading…
Reference in a new issue