diff --git a/Ganeti/HTools/CLI.hs b/Ganeti/HTools/CLI.hs index 12f1fef5189147b6058c53f72353923071c15ce8..b000a0083dd3e7a25c77d9ffdf5e4985bd9106fb 100644 --- a/Ganeti/HTools/CLI.hs +++ b/Ganeti/HTools/CLI.hs @@ -34,6 +34,7 @@ module Ganeti.HTools.CLI , shTemplate , defaultLuxiSocket , maybePrintNodes + , maybePrintInsts -- * The options , oDataFile , oDiskMoves @@ -429,3 +430,15 @@ maybePrintNodes (Just fields) msg fn = do hPutStrLn stderr "" hPutStrLn stderr (msg ++ " status:") hPutStrLn stderr $ fn fields + + +-- | Optionally print the instance list. +maybePrintInsts :: Bool -- ^ Whether to print the instance list + -> String -- ^ Type of the instance map (e.g. initial) + -> String -- ^ The instance data + -> IO () +maybePrintInsts do_print msg instdata = + when do_print $ do + hPutStrLn stderr "" + hPutStrLn stderr $ msg ++ " instance map:" + hPutStr stderr instdata diff --git a/hbal.hs b/hbal.hs index c70d6ca4eb91c5210e8ca5117a8ed5646d00152f..46cccf8e19d369294261176d00614c38e2ad9a25 100644 --- a/hbal.hs +++ b/hbal.hs @@ -233,6 +233,7 @@ main = do let oneline = optOneline opts verbose = optVerbose opts shownodes = optShowNodes opts + showinsts = optShowInsts opts ini_cdata@(ClusterData gl fixed_nl ilf ctags) <- loadExternalData opts @@ -328,10 +329,7 @@ main = do putStrLn "Cluster is not N+1 happy, continuing but no guarantee \ \that the cluster will end N+1 happy." - when (optShowInsts opts) $ do - putStrLn "" - putStrLn "Initial instance map:" - putStrLn $ Cluster.printInsts nl il + maybePrintInsts showinsts "Initial" (Cluster.printInsts nl il) maybePrintNodes shownodes "Initial cluster" (Cluster.printNodes nl) @@ -397,10 +395,7 @@ main = do maybeSaveData (optSaveCluster opts) "balanced" "after balancing" (ClusterData gl fin_nl fin_il ctags) - when (optShowInsts opts) $ do - putStrLn "" - putStrLn "Final instance map:" - putStr $ Cluster.printInsts fin_nl fin_il + maybePrintInsts showinsts "Final" (Cluster.printInsts fin_nl fin_il) maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl)