From 8cd36391f90c08c2fb282ab2d68a4633eaadc85a Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 7 Jul 2011 19:59:45 +0200
Subject: [PATCH] htools: abstract a function for displaying warnings

This will make it possible to reuse this in IAllocator too.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 htools/Ganeti/HTools/CLI.hs       | 10 ++++++++++
 htools/Ganeti/HTools/ExtLoader.hs |  6 ++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/htools/Ganeti/HTools/CLI.hs b/htools/Ganeti/HTools/CLI.hs
index cc150c8e5..464afe871 100644
--- a/htools/Ganeti/HTools/CLI.hs
+++ b/htools/Ganeti/HTools/CLI.hs
@@ -35,6 +35,7 @@ module Ganeti.HTools.CLI
     , defaultLuxiSocket
     , maybePrintNodes
     , maybePrintInsts
+    , maybeShowWarnings
     -- * The options
     , oDataFile
     , oDiskMoves
@@ -490,3 +491,12 @@ maybePrintInsts do_print msg instdata =
     hPutStrLn stderr ""
     hPutStrLn stderr $ msg ++ " instance map:"
     hPutStr stderr instdata
+
+-- | Function to display warning messages from parsing the cluster
+-- state.
+maybeShowWarnings :: [String] -- ^ The warning messages
+                  -> IO ()
+maybeShowWarnings fix_msgs =
+  unless (null fix_msgs) $ do
+    hPutStrLn stderr "Warning: cluster has inconsistent data:"
+    hPutStrLn stderr . unlines . map (printf "  - %s") $ fix_msgs
diff --git a/htools/Ganeti/HTools/ExtLoader.hs b/htools/Ganeti/HTools/ExtLoader.hs
index 435d3686d..06cd7df51 100644
--- a/htools/Ganeti/HTools/ExtLoader.hs
+++ b/htools/Ganeti/HTools/ExtLoader.hs
@@ -38,7 +38,7 @@ import Data.Maybe (isJust, fromJust)
 import System.FilePath
 import System.IO
 import System
-import Text.Printf (printf, hPrintf)
+import Text.Printf (hPrintf)
 
 import qualified Ganeti.HTools.Luxi as Luxi
 import qualified Ganeti.HTools.Rapi as Rapi
@@ -123,9 +123,7 @@ loadExternalData opts = do
       )
   let (fix_msgs, nl) = checkData (cdNodes cdata) (cdInstances cdata)
 
-  unless (null fix_msgs || optVerbose opts == 0) $ do
-         hPutStrLn stderr "Warning: cluster has inconsistent data:"
-         hPutStrLn stderr . unlines . map (printf "  - %s") $ fix_msgs
+  unless (optVerbose opts == 0) $ maybeShowWarnings fix_msgs
 
   return cdata {cdNodes = nl}
 
-- 
GitLab