diff options
author | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-01-07 21:33:08 +0000 |
---|---|---|
committer | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-01-07 21:33:08 +0000 |
commit | 0b4e1a9496c14ee0440f1b17d0aca9f5a4bca2a3 (patch) | |
tree | 79cc2a4be882680d0b3ecfb2a11fc0fb024c951a /scheduler/status_server.py | |
parent | 01df7df14150eacb0f7345c35edb580fa5e3a3aa (diff) |
* move some scheduler config options into a separate module, scheduler_config
* add a little embedded HTTP server to the scheduler, defined in status_server.py, running in a separate thread. this displays loaded config values and allows reloading of those config values at runtime. in the future we can extend this to do much more.
* make global_config handles empty values as nonexistent values by default. otherwise, we would have to both pass a default= and check for value == '' separately. Now, we just pass default= and it's all taken care of.
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@2608 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'scheduler/status_server.py')
-rw-r--r-- | scheduler/status_server.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/scheduler/status_server.py b/scheduler/status_server.py new file mode 100644 index 00000000..2444f8df --- /dev/null +++ b/scheduler/status_server.py @@ -0,0 +1,84 @@ +import os, BaseHTTPServer, cgi, threading +import common +from autotest_lib.scheduler import scheduler_config + +_PORT = 13467 + +_HEADER = """ +<html> +<head><title>Scheduler status</title></head> +<body> +Actions:<br> +<a href="?reparse_config=1">Reparse global config values</a><br> +<br> +""" + +_FOOTER = """ +</body> +</html> +""" + +class StatusServerRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + def _send_headers(self): + self.send_response(200, 'OK') + self.send_header('Content-Type', 'text/html') + self.end_headers() + + + def _parse_arguments(self): + path_parts = self.path.split('?', 1) + if len(path_parts) == 1: + return {} + + encoded_args = path_parts[1] + return cgi.parse_qs(encoded_args) + + + def _write_line(self, line=''): + self.wfile.write(line + '<br>\n') + + + def _write_field(self, field, value): + self._write_line('%s=%s' % (field, value)) + + + def _write_all_fields(self): + self._write_line('Config values:') + for field in scheduler_config.SchedulerConfig.FIELDS: + self._write_field(field, getattr(scheduler_config.config, field)) + self._write_line() + + + def _execute_actions(self, arguments): + if 'reparse_config' in arguments: + scheduler_config.config.read_config() + self._write_line('Updated config!') + self._write_line() + + + def do_GET(self): + self._send_headers() + self.wfile.write(_HEADER) + + arguments = self._parse_arguments() + self._execute_actions(arguments) + self._write_all_fields() + + self.wfile.write(_FOOTER) + + +class StatusServer(object): + def __init__(self): + self._address = ('', _PORT) + self._httpd = BaseHTTPServer.HTTPServer(self._address, + StatusServerRequestHandler) + + + def _run(self): + print 'Status server running on', self._address + self._httpd.serve_forever() + + + def start(self): + self._thread = threading.Thread(target=self._run, name='status_server') + self._thread.start() |