diff --git a/daemons/ganeti-rapi b/daemons/ganeti-rapi index 2e016e9f53f3ee60b6de0798129515e5b8f14dd8..88686db1cf8cbaeab17f93c0a0db65b6d1f40d7e 100755 --- a/daemons/ganeti-rapi +++ b/daemons/ganeti-rapi @@ -32,58 +32,42 @@ from ganeti import logger from ganeti import constants from ganeti import errors from ganeti import http +from ganeti import daemon from ganeti import ssconf from ganeti import utils from ganeti.rapi import connector -class RESTRequestHandler(http.HTTPRequestHandler): +class RemoteApiHttpServer(http.HttpServer): """REST Request Handler Class. """ - def setup(self): - super(RESTRequestHandler, self).setup() + def __init__(self, *args, **kwargs): + http.HttpServer.__init__(self, *args, **kwargs) self._resmap = connector.Mapper() - def HandleRequest(self): - """ Handels a request. + def HandleRequest(self, req): + """Handles a request. """ - (HandlerClass, items, args) = self._resmap.getController(self.path) - handler = HandlerClass(self, items, args, self.post_data) + (HandlerClass, items, args) = self._resmap.getController(req.request_path) + handler = HandlerClass(items, args, req.request_post_data) - command = self.command.upper() + method = req.request_method.upper() try: - fn = getattr(handler, command) + fn = getattr(handler, method) except AttributeError, err: raise http.HTTPBadRequest() try: - try: - result = fn() - except: - logging.exception("Error while handling the %s request", command) - raise - - except errors.OpPrereqError, err: - # TODO: "Not found" is not always the correct error. Ganeti's core must - # differentiate between different error types. - raise http.HTTPNotFound(message=str(err)) + result = fn() + except: + logging.exception("Error while handling the %s request", method) + raise return result -class RESTHttpServer(http.HTTPServer): - def serve_forever(self): - """Handle one request at a time until told to quit.""" - sighandler = utils.SignalHandler([signal.SIGINT, signal.SIGTERM]) - try: - while not sighandler.called: - self.handle_request() - finally: - sighandler.Reset() - - def ParseOptions(): """Parse the command line options. @@ -144,22 +128,16 @@ def main(): stderr_logging=not options.fork) utils.WritePidFile(constants.RAPI_PID) - - log_fd = open(constants.LOG_RAPIACCESS, 'a') try: - apache_log = http.ApacheLogfile(log_fd) - httpd = RESTHttpServer(("", options.port), RESTRequestHandler, - httplog=apache_log) + mainloop = daemon.Mainloop() + server = RemoteApiHttpServer(mainloop, ("", options.port)) + server.Start() try: - httpd.serve_forever() + mainloop.Run() finally: - httpd.server_close() - utils.RemovePidFile(constants.RAPI_PID) - + server.Stop() finally: - log_fd.close() - - sys.exit(0) + utils.RemovePidFile(constants.RAPI_PID) if __name__ == '__main__': diff --git a/lib/constants.py b/lib/constants.py index 9873ca7eb08eb385d00e2a0149004f3a726335aa..296ebde293d74e2ebf174cad09306cef461f54a7 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -127,7 +127,6 @@ LOG_NODESERVER = LOG_DIR + "node-daemon.log" LOG_WATCHER = LOG_DIR + "watcher.log" LOG_MASTERDAEMON = LOG_DIR + "master-daemon.log" LOG_RAPISERVER = LOG_DIR + "rapi-daemon.log" -LOG_RAPIACCESS = LOG_DIR + "rapi-access.log" LOG_COMMANDS = LOG_DIR + "commands.log" LOG_BURNIN = LOG_DIR + "burnin.log" diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py index bb359af6b71d7afd3a7a7f90459928d4b923caa1..fde62c8386c1305af9083eb0f534f7baccfca4f6 100644 --- a/lib/rapi/baserlib.py +++ b/lib/rapi/baserlib.py @@ -126,16 +126,14 @@ class R_Generic(object): """Generic class for resources. """ - def __init__(self, request, items, queryargs, post_data): + def __init__(self, items, queryargs, post_data): """Generic resource constructor. Args: - request: HTTPRequestHandler object items: a list with variables encoded in the URL queryargs: a dictionary with additional options from URL """ - self.request = request self.items = items self.queryargs = queryargs self.post_data = post_data