diff --git a/cdist/trigger.py b/cdist/trigger.py index e781f8ef..9ebd92a5 100644 --- a/cdist/trigger.py +++ b/cdist/trigger.py @@ -36,13 +36,20 @@ log = logging.getLogger(__name__) class Trigger(): """cdist trigger handling""" + # Arguments that are only trigger specific + triggers_args = [ "http_port", "ipv6", "directory", "content" ] + def __init__(self, http_port=None, dry_run=False, ipv6=False, - cdistargs=None): + directory=None, content=None, cdistargs=None): self.log = logging.getLogger("trigger") self.dry_run = dry_run self.http_port = int(http_port) self.ipv6 = ipv6 self.args = cdistargs + + self.directory = directory + self.content = content + log.debug("IPv6: %s", self.ipv6) def run_httpd(self): @@ -63,14 +70,19 @@ class Trigger(): if self.http_port: self.run_httpd() - @staticmethod - def commandline(args): + @classmethod + def commandline(cls, args): http_port = args.http_port ipv6 = args.ipv6 - del args.http_port - del args.ipv6 - t = Trigger(http_port=http_port, dry_run=args.dry_run, ipv6=ipv6, - cdistargs=args) + + ownargs = {} + for targ in cls.triggers_args: + arg = getattr(args, targ) + ownargs[targ] = arg + + del arg + + t = cls(**ownargs, dry_run=args.dry_run, cdistargs=args) t.run() class TriggerHttp(http.server.BaseHTTPRequestHandler): @@ -81,11 +93,14 @@ class TriggerHttp(http.server.BaseHTTPRequestHandler): self.cdistargs = self.server.cdistargs - m = re.match("^/(?Pconfig|install)/.*", self.path) + m = re.match("^/(?Pcdist|file)/(?Pcreate|delete|config|install)/", "/cdist/install/").group('subsystem') + if m: - mode = m.group('mode') + subsystem = m.group('subsystem') + action = m.group('action') else: code = 404 + if mode: log.debug("Running cdist for %s in mode %s", host, mode) if self.server.dry_run: diff --git a/scripts/cdist b/scripts/cdist index 271a2704..25423076 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -191,6 +191,15 @@ def commandline(): parser['trigger'].add_argument( '-H', '--http-port', action='store', default=3000, required=False, help=('Create trigger listener via http on specified port')) + + parser['trigger'].add_argument( + '-D', '--directory', action='store', required=False, + help=('Where to create local files')) + + parser['trigger'].add_argument( + '-C', '--content', action='store', required=False, + help=('What to store in created files')) + parser['trigger'].set_defaults(func=cdist.trigger.Trigger.commandline) # Install