Continue with trigger.
This commit is contained in:
parent
7c169f2d0a
commit
d316089842
3 changed files with 96 additions and 74 deletions
|
|
@ -130,6 +130,25 @@ class Config(object):
|
|||
for host in source:
|
||||
yield host
|
||||
|
||||
@staticmethod
|
||||
def construct_remote_exec_copy_patterns(args):
|
||||
# default remote cmd patterns
|
||||
args.remote_exec_pattern = None
|
||||
args.remote_copy_pattern = None
|
||||
|
||||
args_dict = vars(args)
|
||||
# if remote-exec and/or remote-copy args are None then user
|
||||
# didn't specify command line options nor env vars:
|
||||
# inspect multiplexing options for default cdist.REMOTE_COPY/EXEC
|
||||
if (args_dict['remote_copy'] is None or
|
||||
args_dict['remote_exec'] is None):
|
||||
mux_opts = inspect_ssh_mux_opts()
|
||||
if args_dict['remote_exec'] is None:
|
||||
args.remote_exec_pattern = cdist.REMOTE_EXEC + mux_opts
|
||||
if args_dict['remote_copy'] is None:
|
||||
args.remote_copy_pattern = cdist.REMOTE_COPY + mux_opts
|
||||
|
||||
|
||||
@classmethod
|
||||
def commandline(cls, args):
|
||||
"""Configure remote system"""
|
||||
|
|
@ -166,32 +185,14 @@ class Config(object):
|
|||
failed_hosts = []
|
||||
time_start = time.time()
|
||||
|
||||
# default remote cmd patterns
|
||||
args.remote_exec_pattern = None
|
||||
args.remote_copy_pattern = None
|
||||
|
||||
args_dict = vars(args)
|
||||
# if remote-exec and/or remote-copy args are None then user
|
||||
# didn't specify command line options nor env vars:
|
||||
# inspect multiplexing options for default cdist.REMOTE_COPY/EXEC
|
||||
if (args_dict['remote_copy'] is None or
|
||||
args_dict['remote_exec'] is None):
|
||||
mux_opts = inspect_ssh_mux_opts()
|
||||
if args_dict['remote_exec'] is None:
|
||||
args.remote_exec_pattern = cdist.REMOTE_EXEC + mux_opts
|
||||
if args_dict['remote_copy'] is None:
|
||||
args.remote_copy_pattern = cdist.REMOTE_COPY + mux_opts
|
||||
|
||||
if args.out_path:
|
||||
base_root_path = args.out_path
|
||||
else:
|
||||
base_root_path = tempfile.mkdtemp()
|
||||
cls.construct_remote_exec_copy_patterns(args)
|
||||
base_root_path = cls.create_base_root_path(args.out_path)
|
||||
|
||||
hostcnt = 0
|
||||
for host in itertools.chain(cls.hosts(args.host),
|
||||
cls.hosts(args.hostfile)):
|
||||
hostdir = cdist.str_hash(host)
|
||||
host_base_path = os.path.join(base_root_path, hostdir)
|
||||
host_base_path, hostdir = cls.create_host_base_dirs(
|
||||
host, hostdir)
|
||||
|
||||
log.debug("Base root path for target host \"{}\" is \"{}\"".format(
|
||||
host, host_base_path))
|
||||
|
|
@ -320,13 +321,22 @@ class Config(object):
|
|||
raise
|
||||
|
||||
|
||||
# FIXME begin to cleanup with this method
|
||||
@staticmethod
|
||||
def create_host_tmpdir(host):
|
||||
base_dir = tempfile.mkdtemp()
|
||||
hostdir = cdist.str_hash(host)
|
||||
def create_base_root_path(out_path=None):
|
||||
if out_path:
|
||||
base_root_path = out_path
|
||||
else:
|
||||
base_root_path = tempfile.mkdtemp()
|
||||
|
||||
return (base_dir, hostdir)
|
||||
return base_root_path
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create_host_base_dirs(host, base_root_path):
|
||||
hostdir = cdist.str_hash(host)
|
||||
host_base_path = os.path.join(base_root_path, hostdir)
|
||||
|
||||
return (host_base_path, hostdir)
|
||||
|
||||
|
||||
def run(self):
|
||||
|
|
|
|||
|
|
@ -37,13 +37,14 @@ log = logging.getLogger(__name__)
|
|||
class Trigger():
|
||||
"""cdist trigger handling"""
|
||||
|
||||
def __init__(self, http_port=None, dry_run=False, ipv4only=False):
|
||||
def __init__(self, http_port=None, dry_run=False, ipv4only=False,
|
||||
cdistargs=None):
|
||||
self.log = logging.getLogger("trigger")
|
||||
self.dry_run = dry_run
|
||||
self.http_port = int(http_port)
|
||||
self.ipv4only = ipv4only
|
||||
|
||||
self.args = "fun"
|
||||
self.args = cdistargs
|
||||
|
||||
# can only be set once
|
||||
multiprocessing.set_start_method('forkserver')
|
||||
|
|
@ -68,7 +69,11 @@ class Trigger():
|
|||
|
||||
@staticmethod
|
||||
def commandline(args):
|
||||
t = Trigger(http_port=args.http_port, ipv4only=args.ipv4)
|
||||
http_port = args.http_port
|
||||
ipv4only = args.ipv4
|
||||
del args.http_port
|
||||
del args.ipv4
|
||||
t = Trigger(http_port=http_port, ipv4only=ipv4only, cdistargs=args)
|
||||
t.run()
|
||||
|
||||
class TriggerHttp(BaseHTTPRequestHandler):
|
||||
|
|
@ -78,13 +83,16 @@ class TriggerHttp(BaseHTTPRequestHandler):
|
|||
code = 200
|
||||
mode = None
|
||||
|
||||
print(self.server.cdistargs)
|
||||
self.cdistargs = self.server.cdistargs
|
||||
print(self.cdistargs)
|
||||
print('path: ' + str(self.path))
|
||||
|
||||
m = re.match("^/(?P<mode>config|install)/.*", self.path)
|
||||
if m:
|
||||
mode = m.group('mode')
|
||||
else:
|
||||
code = 404
|
||||
print('mode: ' + str(mode))
|
||||
|
||||
if mode:
|
||||
self.run_cdist(mode, host)
|
||||
|
|
@ -105,8 +113,15 @@ class TriggerHttp(BaseHTTPRequestHandler):
|
|||
module = getattr(cdist, mode)
|
||||
theclass = getattr(module, cname)
|
||||
|
||||
host_base_path, hostdir = theclass.create_host_tmpdir(host)
|
||||
theclass.onehost(host, host_base_path, hostdir, args, parallel=False)
|
||||
if hasattr(self.cdistargs, 'out_path'):
|
||||
out_path = self.cdistargs.out_path
|
||||
else:
|
||||
out_path = None
|
||||
host_base_path, hostdir = theclass.create_host_base_dirs(
|
||||
host, theclass.create_base_root_path(out_path))
|
||||
theclass.construct_remote_exec_copy_patterns(self.cdistargs)
|
||||
theclass.onehost(host, host_base_path, hostdir, self.cdistargs,
|
||||
parallel=False)
|
||||
|
||||
|
||||
class HTTPServerV6(http.server.HTTPServer):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue