import optparse
import sys
import stat
+import logging
from ganeti import constants
from ganeti import errors
from ganeti import runtime
from ganeti import ssconf
from ganeti import utils
+from ganeti import cli
(DIR,
@param _chown_fn: chown function to use (unittest only)
"""
+ logging.debug("Checking %s", path)
try:
_chmod_fn(path, mode)
@param _ensure_fn: ensure function to use (unittest only)
"""
+ logging.debug("Checking directory %s", path)
try:
# We don't want to follow symlinks
st_mode = _stat_fn(path)[stat.ST_MODE]
assert os.path.isabs(path), "Path %s is not absolute" % path
assert os.path.isdir(path), "Path %s is not a dir" % path
+ logging.debug("Recursively processing %s", path)
+
for root, dirs, files in os.walk(path):
for subdir in dirs:
EnsurePermission(os.path.join(root, subdir), dir_perm, uid=uid, gid=gid)
return tuple(paths)
+def SetupLogging(opts):
+ """Configures the logging module.
+
+ """
+ formatter = logging.Formatter("%(asctime)s: %(message)s")
+
+ stderr_handler = logging.StreamHandler()
+ stderr_handler.setFormatter(formatter)
+ if opts.debug:
+ stderr_handler.setLevel(logging.NOTSET)
+ elif opts.verbose:
+ stderr_handler.setLevel(logging.INFO)
+ else:
+ stderr_handler.setLevel(logging.WARNING)
+
+ root_logger = logging.getLogger("")
+ root_logger.setLevel(logging.NOTSET)
+ root_logger.addHandler(stderr_handler)
+
+
def ParseOptions():
"""Parses the options passed to the program.
parser = optparse.OptionParser(usage="%%prog [--full-run]",
prog=program)
+ parser.add_option(cli.DEBUG_OPT)
+ parser.add_option(cli.VERBOSE_OPT)
parser.add_option("--full-run", "-f", dest="full_run", action="store_true",
default=False, help=("Make a full run and collect"
" additional files (time consuming)"))
"""Main routine.
"""
- getent = runtime.GetEnts()
(opts, _) = ParseOptions()
+ SetupLogging(opts)
+
+ if opts.full_run:
+ logging.info("Running in full mode")
+
+ getent = runtime.GetEnts()
+
try:
for path in GetPaths():
ProcessPath(path)
RecursiveEnsure(constants.JOB_QUEUE_ARCHIVE_DIR, getent.masterd_uid,
getent.masterd_gid, 0700, 0600)
except EnsureError, err:
- print >> sys.stderr, "An error occurred while ensure permissions:", err
+ logging.error("An error occurred while setting permissions: %s", err)
return constants.EXIT_FAILURE
return constants.EXIT_SUCCESS