Add better error logging functions for LUs
authorIustin Pop <iustin@google.com>
Tue, 6 Nov 2007 17:01:20 +0000 (17:01 +0000)
committerIustin Pop <iustin@google.com>
Tue, 6 Nov 2007 17:01:20 +0000 (17:01 +0000)
Currently, some LUs use logger.Error, others just feedback_fn, etc. This
patch adds three functions to mcpu.Processor than can be used to log
messages to both the log and to the user.

These function will be used to enhance the output of replace-disks for
drbd8 (at least).

Reviewed-by: imsnah

lib/mcpu.py

index 5226fd7..6b3ec76 100644 (file)
@@ -36,6 +36,7 @@ from ganeti import rpc
 from ganeti import cmdlib
 from ganeti import config
 from ganeti import ssconf
+from ganeti import logger
 
 class Processor(object):
   """Object which runs OpCodes"""
@@ -165,6 +166,28 @@ class Processor(object):
     #  hm.RunPhase(constants.HOOKS_PHASE_POST)
     return result
 
+  def LogStep(self, current, total, message):
+    """Log a change in LU execution progress.
+
+    """
+    logger.Debug("Step %d/%d %s" % (current, total, message))
+    self._feedback_fn("STEP %d/%d %s" % (current, total, message))
+
+  def LogWarning(self, message, hint):
+    """Log a warning to the logs and the user.
+
+    """
+    logger.Error(message)
+    self._feedback_fn(" - WARNING: %s" % message)
+    self._feedback_fn("      Hint: %s" % hint)
+
+  def LogInfo(self, message):
+    """Log an informational message to the logs and the user.
+
+    """
+    logger.Info(message)
+    self._feedback_fn(" - INFO: %s" % message)
+
 
 class HooksMaster(object):
   """Hooks master.