Example #1
0
def PrepRapi(options, _):
    """Prep remote API function, executed with the PID file held.

  """
    mainloop = daemon.Mainloop()

    users = RapiUsers()

    handler = RemoteApiHandler(users.Get, options.reqauth)

    # Setup file watcher (it'll be driven by asyncore)
    SetupFileWatcher(pathutils.RAPI_USERS_FILE,
                     compat.partial(users.Load, pathutils.RAPI_USERS_FILE))

    users.Load(pathutils.RAPI_USERS_FILE)

    server = http.server.HttpServer(mainloop,
                                    options.bind_address,
                                    options.port,
                                    options.max_clients,
                                    handler,
                                    ssl_params=options.ssl_params,
                                    ssl_verify_peer=False)
    server.Start()

    return (mainloop, server)
Example #2
0
 def setUp(self):
     self.mainloop = daemon.Mainloop()
     self.server = _MyAsyncUDPSocket(self.family)
     self.client = _MyAsyncUDPSocket(self.family)
     self.server.bind((self.address, 0))
     self.port = self.server.getsockname()[1]
     # Save utils.IgnoreSignals so we can do evil things to it...
     self.saved_utils_ignoresignals = utils.IgnoreSignals
Example #3
0
def PrepMasterd(options, _):
    """Prep master daemon function, executed with the PID file held.

  """
    # This is safe to do as the pid file guarantees against
    # concurrent execution.
    utils.RemoveFile(pathutils.MASTER_SOCKET)

    mainloop = daemon.Mainloop()
    master = MasterServer(pathutils.MASTER_SOCKET, options.uid, options.gid)
    return (mainloop, master)
 def setUp(self):
   testutils.GanetiTestCase.setUp(self)
   self.mainloop = daemon.Mainloop()
   self.chk_files = [self._CreateTempFile() for i in self.NOTIFIERS]
   self.notified = [False for i in self.NOTIFIERS]
   # We need one watch manager per notifier, as those contain the file
   # descriptor which is monitored by asyncore
   self.wms = [pyinotify.WatchManager() for i in self.NOTIFIERS]
   self.cbk = [self.OnInotifyCallback(self, i) for i in self.NOTIFIERS]
   self.ihandler = [asyncnotifier.SingleFileEventHandler(wm, cb, cf)
                    for (wm, cb, cf) in
                    zip(self.wms, self.cbk, self.chk_files)]
   self.notifiers = [_MyErrorLoggingAsyncNotifier(wm, ih)
                     for (wm, ih) in zip(self.wms, self.ihandler)]
   # TERM notifier is enabled by default, as we use it to get out of the loop
   self.ihandler[self.NOTIFIER_TERM].enable()
Example #5
0
def PrepNoded(options, _):
    """Preparation node daemon function, executed with the PID file held.

  """
    if options.mlock:
        request_executor_class = MlockallRequestExecutor
        try:
            utils.Mlockall()
        except errors.NoCtypesError:
            logging.warning("Cannot set memory lock, ctypes module not found")
            request_executor_class = http.server.HttpServerRequestExecutor
    else:
        request_executor_class = http.server.HttpServerRequestExecutor

    # Read SSL certificate
    if options.ssl:
        ssl_params = http.HttpSslParams(ssl_key_path=options.ssl_key,
                                        ssl_cert_path=options.ssl_cert)
    else:
        ssl_params = None

    err = _PrepareQueueLock()
    if err is not None:
        # this might be some kind of file-system/permission error; while
        # this breaks the job queue functionality, we shouldn't prevent
        # startup of the whole node daemon because of this
        logging.critical("Can't init/verify the queue, proceeding anyway: %s",
                         err)

    handler = NodeRequestHandler()

    mainloop = daemon.Mainloop()
    server = http.server.HttpServer(
        mainloop,
        options.bind_address,
        options.port,
        options.max_clients,
        handler,
        ssl_params=ssl_params,
        ssl_verify_peer=True,
        request_executor_class=request_executor_class,
        ssl_verify_callback=SSLVerifyPeer)
    server.Start()

    return (mainloop, server)
Example #6
0
 def setUp(self):
     testutils.GanetiTestCase.setUp(self)
     self.mainloop = daemon.Mainloop()
     self.address = self.getAddress()
     self.server = _MyAsyncStreamServer(self.family, self.address,
                                        self.handle_connection)
     self.client_handler = _MyMessageStreamHandler
     self.unhandled_limit = None
     self.terminator = "\3"
     self.address = self.server.getsockname()
     self.clients = []
     self.connections = []
     self.messages = {}
     self.connect_terminate_count = 0
     self.message_terminate_count = 0
     self.next_client_id = 0
     # Save utils.IgnoreSignals so we can do evil things to it...
     self.saved_utils_ignoresignals = utils.IgnoreSignals
Example #7
0
File: rapi.py Project: azet/ganeti
def PrepRapi(options, _):
  """Prep remote API function, executed with the PID file held.

  """
  mainloop = daemon.Mainloop()

  if options.pamauth:
    options.reqauth = True
    authenticator = pam.PamAuthenticator()
  else:
    authenticator = basic_auth.BasicAuthenticator()

  handler = RemoteApiHandler(authenticator, options.reqauth)

  server = \
    http.server.HttpServer(mainloop, options.bind_address, options.port,
                           handler,
                           ssl_params=options.ssl_params, ssl_verify_peer=False)
  server.Start()

  return (mainloop, server)
Example #8
0
 def setUp(self):
     testutils.GanetiTestCase.setUp(self)
     self.mainloop = daemon.Mainloop()
     self.awaker = daemon.AsyncAwaker(signal_fn=self.handle_signal)
     self.signal_count = 0
     self.signal_terminate_count = 1
Example #9
0
 def setUp(self):
     testutils.GanetiTestCase.setUp(self)
     self.mainloop = daemon.Mainloop()
     self.sendsig_events = []
     self.onsignal_events = []