From 0fbbf897ca1b56c189edf1a9effc9a9a7bdd6052 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 6 Nov 2007 17:01:20 +0000
Subject: [PATCH] Add better error logging functions for LUs

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 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/mcpu.py b/lib/mcpu.py
index 5226fd7ff..6b3ec768d 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -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.
-- 
GitLab