forked from ungleich-public/cdist
Merge remote-tracking branch 'ungleich/feature/trigger' into feature/trigger
This commit is contained in:
commit
7c169f2d0a
3 changed files with 41 additions and 12 deletions
|
@ -136,7 +136,7 @@ class Config(object):
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
# FIXME: Refactor relict - remove later
|
# FIXME: Refactor relict - remove later
|
||||||
log = logging.getLogger("cdist")
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
if args.manifest == '-' and args.hostfile == '-':
|
if args.manifest == '-' and args.hostfile == '-':
|
||||||
raise cdist.Error(("Cannot read both, manifest and host file, "
|
raise cdist.Error(("Cannot read both, manifest and host file, "
|
||||||
|
@ -227,6 +227,8 @@ class Config(object):
|
||||||
raise cdist.Error("Failed to configure the following hosts: " +
|
raise cdist.Error("Failed to configure the following hosts: " +
|
||||||
" ".join(failed_hosts))
|
" ".join(failed_hosts))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def onehost(cls, host, host_base_path, host_dir_name, args, parallel):
|
def onehost(cls, host, host_base_path, host_dir_name, args, parallel):
|
||||||
"""Configure ONE system"""
|
"""Configure ONE system"""
|
||||||
|
@ -317,6 +319,16 @@ class Config(object):
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME begin to cleanup with this method
|
||||||
|
@staticmethod
|
||||||
|
def create_host_tmpdir(host):
|
||||||
|
base_dir = tempfile.mkdtemp()
|
||||||
|
hostdir = cdist.str_hash(host)
|
||||||
|
|
||||||
|
return (base_dir, hostdir)
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Do what is most often done: deploy & cleanup"""
|
"""Do what is most often done: deploy & cleanup"""
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
|
@ -29,7 +29,8 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
import cdist
|
import cdist.config
|
||||||
|
import cdist.install
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -42,16 +43,22 @@ class Trigger():
|
||||||
self.http_port = int(http_port)
|
self.http_port = int(http_port)
|
||||||
self.ipv4only = ipv4only
|
self.ipv4only = ipv4only
|
||||||
|
|
||||||
|
self.args = "fun"
|
||||||
|
|
||||||
# can only be set once
|
# can only be set once
|
||||||
multiprocessing.set_start_method('forkserver')
|
multiprocessing.set_start_method('forkserver')
|
||||||
|
|
||||||
|
# Create pool suitable for passing objects
|
||||||
|
def __init_pool(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def run_httpd(self):
|
def run_httpd(self):
|
||||||
server_address = ('', self.http_port)
|
server_address = ('', self.http_port)
|
||||||
|
|
||||||
if self.ipv4only:
|
if self.ipv4only:
|
||||||
httpd = HTTPServerV4(server_address, TriggerHttp)
|
httpd = HTTPServerV4(self.args, server_address, TriggerHttp)
|
||||||
else:
|
else:
|
||||||
httpd = HTTPServerV6(server_address, TriggerHttp)
|
httpd = HTTPServerV6(self.args, server_address, TriggerHttp)
|
||||||
|
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
@ -65,15 +72,14 @@ class Trigger():
|
||||||
t.run()
|
t.run()
|
||||||
|
|
||||||
class TriggerHttp(BaseHTTPRequestHandler):
|
class TriggerHttp(BaseHTTPRequestHandler):
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
http.server.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
|
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
# FIXME: dispatch to pool instead of single process
|
# FIXME: dispatch to pool instead of single process
|
||||||
host = self.client_address[0]
|
host = self.client_address[0]
|
||||||
code = 200
|
code = 200
|
||||||
mode = None
|
mode = None
|
||||||
|
|
||||||
|
print(self.server.cdistargs)
|
||||||
|
|
||||||
m = re.match("^/(?P<mode>config|install)/.*", self.path)
|
m = re.match("^/(?P<mode>config|install)/.*", self.path)
|
||||||
if m:
|
if m:
|
||||||
mode = m.group('mode')
|
mode = m.group('mode')
|
||||||
|
@ -95,12 +101,12 @@ class TriggerHttp(BaseHTTPRequestHandler):
|
||||||
def run_cdist(self, mode, host):
|
def run_cdist(self, mode, host):
|
||||||
log.debug("Running cdist {} {}".format(mode, host))
|
log.debug("Running cdist {} {}".format(mode, host))
|
||||||
|
|
||||||
|
cname = mode.title()
|
||||||
|
module = getattr(cdist, mode)
|
||||||
|
theclass = getattr(module, cname)
|
||||||
|
|
||||||
class HTTPServerV4(http.server.HTTPServer):
|
host_base_path, hostdir = theclass.create_host_tmpdir(host)
|
||||||
"""
|
theclass.onehost(host, host_base_path, hostdir, args, parallel=False)
|
||||||
Server that listens only to IPv4 requests.
|
|
||||||
"""
|
|
||||||
address_family = socket.AF_INET
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPServerV6(http.server.HTTPServer):
|
class HTTPServerV6(http.server.HTTPServer):
|
||||||
|
@ -108,3 +114,13 @@ class HTTPServerV6(http.server.HTTPServer):
|
||||||
Server that listens both to IPv4 and IPv6 requests.
|
Server that listens both to IPv4 and IPv6 requests.
|
||||||
"""
|
"""
|
||||||
address_family = socket.AF_INET6
|
address_family = socket.AF_INET6
|
||||||
|
|
||||||
|
def __init__(self, cdistargs, *args, **kwargs):
|
||||||
|
self.cdistargs = cdistargs
|
||||||
|
http.server.HTTPServer.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
class HTTPServerV4(HTTPServerV6):
|
||||||
|
"""
|
||||||
|
Server that listens to IPv4 requests
|
||||||
|
"""
|
||||||
|
address_family = socket.AF_INET
|
||||||
|
|
|
@ -150,6 +150,7 @@ def commandline():
|
||||||
'-s', '--sequential',
|
'-s', '--sequential',
|
||||||
help='Operate on multiple hosts sequentially (default)',
|
help='Operate on multiple hosts sequentially (default)',
|
||||||
action='store_false', dest='parallel')
|
action='store_false', dest='parallel')
|
||||||
|
|
||||||
# remote-copy and remote-exec defaults are environment variables
|
# remote-copy and remote-exec defaults are environment variables
|
||||||
# if set; if not then None - these will be futher handled after
|
# if set; if not then None - these will be futher handled after
|
||||||
# parsing to determine implementation default
|
# parsing to determine implementation default
|
||||||
|
|
Loading…
Reference in a new issue