Package ganeti :: Module daemon
[hide private]
[frames] | no frames]

Module daemon

source code

Module with helper classes and functions for daemons

Classes [hide private]
  SchedulerBreakout
Exception used to get out of the scheduler loop
  AsyncoreScheduler
Event scheduler integrated with asyncore
  GanetiBaseAsyncoreDispatcher
Base Ganeti Asyncore Dispacher
  AsyncStreamServer
A stream server to use with asyncore.
  AsyncTerminatedMessageStream
A terminator separated message stream asyncore module.
  AsyncUDPSocket
An improved asyncore udp socket.
  AsyncAwaker
A way to notify the asyncore loop that something is going on.
  Mainloop
Generic mainloop for daemons
Functions [hide private]
 
AsyncoreDelayFunction(timeout)
Asyncore-compatible scheduler delay function.
source code
 
FormatAddress(family, address)
Format a client's address
source code
 
GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn, multithreaded=False, console_logging=False, default_ssl_cert=None, default_ssl_key=None, user=_DEFAULT_RUN_USER, group=_DEFAULT_RUN_GROUP)
Shared main function for daemons.
source code
Variables [hide private]
  _DEFAULT_RUN_USER = "root"
  _DEFAULT_RUN_GROUP = "root"

Imports: asyncore, asynchat, collections, grp, os, pwd, signal, logging, sched, time, socket, select, sys, utils, constants, errors, netutils


Function Details [hide private]

AsyncoreDelayFunction(timeout)

source code 

Asyncore-compatible scheduler delay function.

This is a delay function for sched that, rather than actually sleeping, executes asyncore events happening in the meantime.

After an event has occurred, rather than returning, it raises a SchedulerBreakout exception, which will force the current scheduler.run() invocation to terminate, so that we can also check for signals. The main loop will then call the scheduler run again, which will allow it to actually process any due events.

This is needed because scheduler.run() doesn't support a count=..., as asyncore loop, and the scheduler module documents throwing exceptions from inside the delay function as an allowed usage model.

FormatAddress(family, address)

source code 

Format a client's address

Parameters:
  • family (integer) - socket family (one of socket.AF_*)
  • address (family specific (usually tuple)) - address, as reported by this class

GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn, multithreaded=False, console_logging=False, default_ssl_cert=None, default_ssl_key=None, user=_DEFAULT_RUN_USER, group=_DEFAULT_RUN_GROUP)

source code 

Shared main function for daemons.

Parameters:
  • daemon_name (string) - daemon name
  • optionparser (optparse.OptionParser) - initialized optionparser with daemon-specific options (common -f -d options will be handled by this module)
  • dirs (list of (string, integer)) - list of directories that must be created if they don't exist, and the permissions to be used to create them
  • check_fn (function which accepts (options, args)) - function that checks start conditions and exits if they're not met
  • exec_fn (function which accepts (options, args)) - function that's executed with the daemon's pid file held, and runs the daemon itself.
  • multithreaded (bool) - Whether the daemon uses threads
  • console_logging (boolean) - if True, the daemon will fall back to the system console if logging fails
  • default_ssl_cert (string) - Default SSL certificate path
  • default_ssl_key (string) - Default SSL key path
  • user (string) - Default user to run as
  • group (string) - Default group to run as