Commit 417f6b50 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add maybePrintNodes for abstracting the node list



Since this bit of code (including the “when (isJust …)” is used in
multiple places, let's abstract it in a function that is used
consistently. One (bad?) side-effect is that all node lists are done
to stderr, including the ones from hbal where it was previously done
to stdout (is that fine?).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 4188449c
......@@ -33,6 +33,7 @@ module Ganeti.HTools.CLI
, parseOpts
, shTemplate
, defaultLuxiSocket
, maybePrintNodes
-- * The options
, oDataFile
, oDiskMoves
......@@ -417,3 +418,14 @@ shTemplate =
\ exit 0\n\
\ fi\n\
\}\n\n"
-- | Optionally print the node list.
maybePrintNodes :: Maybe [String] -- ^ The field list
-> String -- ^ Informational message
-> ([String] -> String) -- ^ Function to generate the listing
-> IO ()
maybePrintNodes Nothing _ _ = return ()
maybePrintNodes (Just fields) msg fn = do
hPutStrLn stderr ""
hPutStrLn stderr (msg ++ " status:")
hPutStrLn stderr $ fn fields
......@@ -333,10 +333,7 @@ main = do
putStrLn "Initial instance map:"
putStrLn $ Cluster.printInsts nl il
when (isJust shownodes) $
do
putStrLn "Initial cluster status:"
putStrLn $ Cluster.printNodes nl (fromJust shownodes)
maybePrintNodes shownodes "Initial cluster" (Cluster.printNodes nl)
let ini_cv = Cluster.compCV nl
ini_tbl = Cluster.Table nl il ini_cv []
......@@ -405,19 +402,15 @@ main = do
putStrLn "Final instance map:"
putStr $ Cluster.printInsts fin_nl fin_il
when (isJust shownodes) $
do
maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl)
when (verbose > 3) $ do
let ini_cs = Cluster.totalResources nl
fin_cs = Cluster.totalResources fin_nl
putStrLn ""
putStrLn "Final cluster status:"
putStrLn $ Cluster.printNodes fin_nl (fromJust shownodes)
when (verbose > 3) $
do
printf "Original: mem=%d disk=%d\n"
(Cluster.csFmem ini_cs) (Cluster.csFdsk ini_cs) :: IO ()
printf "Final: mem=%d disk=%d\n"
(Cluster.csFmem fin_cs) (Cluster.csFdsk fin_cs)
printf "Original: mem=%d disk=%d\n"
(Cluster.csFmem ini_cs) (Cluster.csFdsk ini_cs) :: IO ()
printf "Final: mem=%d disk=%d\n"
(Cluster.csFmem fin_cs) (Cluster.csFdsk fin_cs)
when oneline $
putStrLn $ formatOneline ini_cv (length ord_plc) fin_cv
......
......@@ -295,10 +295,8 @@ main = do
formatTable (map (printInstance trl_nl) (reverse trl_ixes))
[False, False, False, True, True, True]
when (isJust shownodes) $ do
hPutStrLn stderr ""
hPutStrLn stderr "Tiered allocation status:"
hPutStrLn stderr $ Cluster.printNodes trl_nl (fromJust shownodes)
maybePrintNodes shownodes "Tiered allocation"
(Cluster.printNodes trl_nl)
maybeSaveData (optSaveCluster opts) "tiered" "after tiered allocation"
(ClusterData gl trl_nl trl_il ctags)
......@@ -323,11 +321,7 @@ main = do
hPutStr stderr . unlines . map ((:) ' ' . intercalate " ") $
formatTable (map (printInstance fin_nl) fin_ixes)
[False, False, False, True, True, True]
when (isJust shownodes) $
do
hPutStrLn stderr ""
hPutStrLn stderr "Final cluster status:"
hPutStrLn stderr $ Cluster.printNodes fin_nl (fromJust shownodes)
maybePrintNodes shownodes "Standard allocation" (Cluster.printNodes fin_nl)
maybeSaveData (optSaveCluster opts) "alloc" "after standard allocation"
(ClusterData gl fin_nl fin_il ctags)
......
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