diff --git a/cdist/trigger.py b/cdist/trigger.py new file mode 100644 index 00000000..88986dd8 --- /dev/null +++ b/cdist/trigger.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# 2016 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# + +import logging +import os +import sys +import time +import tempfile +from http.server import BaseHTTPRequestHandler, HTTPServer + + +import cdist +from cdist import core + +class Trigger(): + """cdist trigger handling""" + + def __init__(self, dry_run=False): + self.log = logging.getLogger("trigger") + self.dry_run = dry_run + + def run_http(self): + server_address = ('0.0.0.0', 8000) + httpd = HTTPServer(server_address, testHTTPServer_RequestHandler) + print('running server...') + httpd.serve_forever() + + @staticmethod + def commandline(args): + print("all good") + pass + + +class TriggerHttp(BaseHTTPRequestHandler): + def do_GET(self): + pass diff --git a/scripts/cdist b/scripts/cdist index 9f8d326d..2b11827b 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2016 Nico Schottelius (nico-cdist at schottelius.org) # 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. @@ -23,7 +23,7 @@ # list of beta sub-commands -BETA_COMMANDS = ['install', ] +BETA_COMMANDS = ['install', 'trigger' ] # list of beta arguments for sub-commands BETA_ARGS = { 'config': ['jobs', ], @@ -69,6 +69,7 @@ def commandline(): import cdist.config import cdist.install import cdist.shell + import cdist.trigger import shutil import os import multiprocessing @@ -84,6 +85,12 @@ def commandline(): '-v', '--verbose', help='Set log level to info, be more verbose', action='store_true', default=False) + parser['beta'] = argparse.ArgumentParser(add_help=False) + parser['beta'].add_argument( + '-b', '--enable-beta', + help=('Enable beta functionalities.'), + action='store_true', dest='beta', default=False) + # Main subcommand parser parser['main'] = argparse.ArgumentParser( description='cdist ' + cdist.VERSION, parents=[parser['loglevel']]) @@ -168,6 +175,14 @@ def commandline(): ' should be POSIX compatible shell.')) parser['shell'].set_defaults(func=cdist.shell.Shell.commandline) + parser['trigger'] = parser['sub'].add_parser( + 'trigger', parents=[parser['loglevel'], parser['beta']]) + parser['trigger'].add_argument( + '-H', '--http-port', + help=('Create trigger listener via http on specified port'), + action='append') + parser['trigger'].set_defaults(func=cdist.trigger.Trigger.commandline) + # Install parser['install'] = parser['sub'].add_parser('install', add_help=False, parents=[parser['config']])