Commit 33e44f0c authored by Iustin Pop's avatar Iustin Pop
Browse files

Add maybePrintInsts for the instance listing



This again abstracts a bit the instance listing. Due to the fact that
I don't want to import Cluster.hs in CLI.hs, we pass the already
generated output. It also moves the instance display to stderr.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 417f6b50
......@@ -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
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment