Revision e0003509

b/lib/http/server.py
276 276
  READ_TIMEOUT = 10
277 277
  CLOSE_TIMEOUT = 1
278 278

  
279
  def __init__(self, server, sock, client_addr):
279
  def __init__(self, server, handler, sock, client_addr):
280 280
    """Initializes this class.
281 281

  
282 282
    """
283 283
    self.server = server
284
    self.handler = handler
284 285
    self.sock = sock
285 286
    self.client_addr = client_addr
286 287

  
......
324 325

  
325 326
            (self.response_msg.start_line.code, self.response_msg.headers,
326 327
             self.response_msg.body) = \
327
              HandleServerRequest(self.server, self.request_msg)
328
              HandleServerRequest(self.handler, self.request_msg)
328 329

  
329 330
            # Only wait for client to close if we didn't have any exception.
330 331
            force_close = False
......
363 364
    """Sends the response to the client.
364 365

  
365 366
    """
367
    # HttpMessage.start_line can be of different types, pylint: disable=E1103
366 368
    if self.response_msg.start_line.code is None:
367 369
      return
368 370

  
......
443 445
class HttpServer(http.HttpBase, asyncore.dispatcher):
444 446
  """Generic HTTP server class
445 447

  
446
  Users of this class must subclass it and override the HandleRequest function.
447

  
448 448
  """
449 449
  MAX_CHILDREN = 20
450 450

  
451
  def __init__(self, mainloop, local_address, port,
451
  def __init__(self, mainloop, local_address, port, handler,
452 452
               ssl_params=None, ssl_verify_peer=False,
453 453
               request_executor_class=None):
454 454
    """Initializes the HTTP server
......
480 480
    self.mainloop = mainloop
481 481
    self.local_address = local_address
482 482
    self.port = port
483
    self.handler = handler
483 484
    family = netutils.IPAddress.GetAddressFamily(local_address)
484 485
    self.socket = self._CreateSocket(ssl_params, ssl_verify_peer, family)
485 486

  
......
560 561
        # In case the handler code uses temporary files
561 562
        utils.ResetTempfileModule()
562 563

  
563
        self.request_executor(self, connection, client_addr)
564
        self.request_executor(self, self.handler, connection, client_addr)
564 565
      except Exception: # pylint: disable=W0703
565 566
        logging.exception("Error while handling request from %s:%s",
566 567
                          client_addr[0], client_addr[1])
......
569 570
    else:
570 571
      self._children.append(pid)
571 572

  
573

  
574
class HttpServerHandler(object):
575
  """Base class for handling HTTP server requests.
576

  
577
  Users of this class must subclass it and override the L{HandleRequest}
578
  function.
579

  
580
  """
572 581
  def PreHandleRequest(self, req):
573 582
    """Called before handling a request.
574 583

  
b/lib/server/noded.py
121 121
    http.server.HttpServerRequestExecutor.__init__(self, *args, **kwargs)
122 122

  
123 123

  
124
class NodeHttpServer(http.server.HttpServer):
124
class NodeRequestHandler(http.server.HttpServerHandler):
125 125
  """The server implementation.
126 126

  
127 127
  This class holds all methods exposed over the RPC interface.
......
130 130
  # too many public methods, and unused args - all methods get params
131 131
  # due to the API
132 132
  # pylint: disable=R0904,W0613
133
  def __init__(self, *args, **kwargs):
134
    http.server.HttpServer.__init__(self, *args, **kwargs)
133
  def __init__(self):
134
    http.server.HttpServerHandler.__init__(self)
135 135
    self.noded_pid = os.getpid()
136 136

  
137 137
  def HandleRequest(self, req):
......
1051 1051
    # startup of the whole node daemon because of this
1052 1052
    logging.critical("Can't init/verify the queue, proceeding anyway: %s", err)
1053 1053

  
1054
  handler = NodeRequestHandler()
1055

  
1054 1056
  mainloop = daemon.Mainloop()
1055
  server = NodeHttpServer(mainloop, options.bind_address, options.port,
1056
                          ssl_params=ssl_params, ssl_verify_peer=True,
1057
                          request_executor_class=request_executor_class)
1057
  server = \
1058
    http.server.HttpServer(mainloop, options.bind_address, options.port,
1059
      handler, ssl_params=ssl_params, ssl_verify_peer=True,
1060
      request_executor_class=request_executor_class)
1058 1061
  server.Start()
1062

  
1059 1063
  return (mainloop, server)
1060 1064

  
1061 1065

  
b/lib/server/rapi.py
82 82
    return serializer.DumpJson(values)
83 83

  
84 84

  
85
class RemoteApiHttpServer(http.auth.HttpServerRequestAuthentication,
86
                          http.server.HttpServer):
85
class RemoteApiHandler(http.auth.HttpServerRequestAuthentication,
86
                       http.server.HttpServerHandler):
87 87
  """REST Request Handler Class.
88 88

  
89 89
  """
90 90
  AUTH_REALM = "Ganeti Remote API"
91 91

  
92
  def __init__(self, *args, **kwargs):
92
  def __init__(self):
93 93
    # pylint: disable=W0233
94 94
    # it seems pylint doesn't see the second parent class there
95
    http.server.HttpServer.__init__(self, *args, **kwargs)
95
    http.server.HttpServerHandler.__init__(self)
96 96
    http.auth.HttpServerRequestAuthentication.__init__(self)
97 97
    self._resmap = connector.Mapper()
98 98
    self._users = None
......
308 308
  """Prep remote API function, executed with the PID file held.
309 309

  
310 310
  """
311

  
312 311
  mainloop = daemon.Mainloop()
313
  server = RemoteApiHttpServer(mainloop, options.bind_address, options.port,
314
                               ssl_params=options.ssl_params,
315
                               ssl_verify_peer=False,
316
                               request_executor_class=JsonErrorRequestExecutor)
312
  handler = RemoteApiHandler()
317 313

  
318 314
  # Setup file watcher (it'll be driven by asyncore)
319 315
  SetupFileWatcher(constants.RAPI_USERS_FILE,
320
                   compat.partial(server.LoadUsers, constants.RAPI_USERS_FILE))
316
                   compat.partial(handler.LoadUsers, constants.RAPI_USERS_FILE))
321 317

  
322
  server.LoadUsers(constants.RAPI_USERS_FILE)
318
  handler.LoadUsers(constants.RAPI_USERS_FILE)
323 319

  
324
  # pylint: disable=E1101
325
  # it seems pylint doesn't see the second parent class there
320
  server = \
321
    http.server.HttpServer(mainloop, options.bind_address, options.port,
322
      handler, ssl_params=options.ssl_params, ssl_verify_peer=False,
323
      request_executor_class=JsonErrorRequestExecutor)
326 324
  server.Start()
327 325

  
328 326
  return (mainloop, server)

Also available in: Unified diff