diff --git a/Ganeti/HTools/CLI.hs b/Ganeti/HTools/CLI.hs index 89432fc390a27772fb62b13a50756f200ad43688..b977b6a854573f0bae6ff242f758779b63ccb176 100644 --- a/Ganeti/HTools/CLI.hs +++ b/Ganeti/HTools/CLI.hs @@ -82,7 +82,7 @@ defaultLuxiSocket = "/var/run/ganeti/socket/ganeti-master" -- | Command line options structure. data Options = Options - { optShowNodes :: Bool -- ^ Whether to show node status + { optShowNodes :: Maybe [String] -- ^ Whether to show node status , optShowInsts :: Bool -- ^ Whether to show the instance map , optShowCmds :: Maybe FilePath -- ^ Whether to show the command list , optOneline :: Bool -- ^ Switch output to a single line @@ -114,7 +114,7 @@ data Options = Options -- | Default values for the command line options. defaultOptions :: Options defaultOptions = Options - { optShowNodes = False + { optShowNodes = Nothing , optShowInsts = False , optShowCmds = Nothing , optOneline = False @@ -148,7 +148,10 @@ type OptType = OptDescr (Options -> Result Options) oPrintNodes :: OptType oPrintNodes = Option "p" ["print-nodes"] - (NoArg (\ opts -> Ok opts { optShowNodes = True })) + (OptArg ((\ f opts -> + let splitted = sepSplit ',' f + in Ok opts { optShowNodes = Just splitted }) . + fromMaybe []) "FIELDS") "print the final node list" oPrintInsts :: OptType diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index 01a419ed07dad99fce77c86040d00cc1b908ed0e..9a94d0b0a2cb42d569407cd14df60d52f45e1afe 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -659,12 +659,15 @@ printSolution nl il sol = unzip $ zipWith (printSolutionLine nl il nmlen imlen) sol [1..] -- | Print the node list. -printNodes :: Node.List -> String -printNodes nl = - let snl = sortBy (compare `on` Node.idx) (Container.elems nl) - (header, isnum) = unzip $ map Node.showHeader Node.defaultFields +printNodes :: Node.List -> [String] -> String +printNodes nl fs = + let fields = if null fs + then Node.defaultFields + else fs + snl = sortBy (compare `on` Node.idx) (Container.elems nl) + (header, isnum) = unzip $ map Node.showHeader fields in unlines . map ((:) ' ' . intercalate " ") $ - formatTable (header:map (Node.list Node.defaultFields) snl) isnum + formatTable (header:map (Node.list fields) snl) isnum -- | Print the instance list. printInsts :: Node.List -> Instance.List -> String diff --git a/hbal.1 b/hbal.1 index e74ecd8dc301175e087d6e4cfb294662bae675df..52622fcc02d5a258acf71138d0ed89eebd2d89f7 100644 --- a/hbal.1 +++ b/hbal.1 @@ -33,7 +33,7 @@ Algorithm options: .TP Reporting options: .BI "[ -C[" file "] ]" -.B "[ -p ]" +.BI "[ -p[" fields "] ]" .B "[ --print-instances ]" .B "[ -o ]" .B "[ -v... | -q ]" @@ -217,7 +217,10 @@ resource allocation in Ganeti) and thus we start a new jobset. Prints the before and after node status, in a format designed to allow the user to understand the node's most important parameters. -The node list will contain these informations: +It is possible to customise the listed information by passing a +comma-separated list of field names to this option (the field list is +currently undocumented). By default, the node list will contain these +informations: .RS .TP .B F diff --git a/hbal.hs b/hbal.hs index aa5cfde750a0aa4f913b70d168fddb01f8b0f7f8..1ad686e89b24019bc59f070f75ac04ece5b56632 100644 --- a/hbal.hs +++ b/hbal.hs @@ -184,6 +184,7 @@ main = do let oneline = optOneline opts verbose = optVerbose opts + shownodes = optShowNodes opts (fixed_nl, il, csf) <- loadExternalData opts @@ -234,10 +235,10 @@ main = do putStrLn "Initial instance map:" putStrLn $ Cluster.printInsts nl il - when (optShowNodes opts) $ + when (isJust shownodes) $ do putStrLn "Initial cluster status:" - putStrLn $ Cluster.printNodes nl + putStrLn $ Cluster.printNodes nl (fromJust shownodes) let ini_cv = Cluster.compCV nl ini_tbl = Cluster.Table nl il ini_cv [] @@ -308,13 +309,13 @@ main = do putStrLn "Final instance map:" putStr $ Cluster.printInsts fin_nl fin_il - when (optShowNodes opts) $ + when (isJust shownodes) $ do let ini_cs = Cluster.totalResources nl fin_cs = Cluster.totalResources fin_nl putStrLn "" putStrLn "Final cluster status:" - putStrLn $ Cluster.printNodes fin_nl + putStrLn $ Cluster.printNodes fin_nl (fromJust shownodes) when (verbose > 3) $ do printf "Original: mem=%d disk=%d\n" diff --git a/hscan.hs b/hscan.hs index d4b86417b90ba88d486d6cc2880ec6e48126b756..66b6e4fd3561a1e855a6b4750ad27a7e7841f321 100644 --- a/hscan.hs +++ b/hscan.hs @@ -27,6 +27,7 @@ module Main (main) where import Data.List import Data.Function +import Data.Maybe (isJust, fromJust) import Monad import System import System.IO @@ -124,6 +125,7 @@ main = do let odir = optOutPath opts nlen = maximum . map length $ clusters + shownodes = optShowNodes opts unless (optNoHeaders opts) $ printf "%-*s %5s %5s %5s %5s %6s %6s %6s %6s %10s\n" nlen @@ -143,8 +145,8 @@ main = do let (nl, il, csf) = x (_, fix_nl) = Loader.checkData nl il putStrLn $ printCluster fix_nl il - when (optShowNodes opts) $ - putStr $ Cluster.printNodes fix_nl + when (isJust shownodes) $ + putStr $ Cluster.printNodes fix_nl (fromJust shownodes) let ndata = serializeNodes csf nl idata = serializeInstances csf nl il oname = odir </> fixSlash name diff --git a/hspace.1 b/hspace.1 index 194aec76bbb77d7859406f5840a1a10f063b37b4..075f01dc4c8f609f4c48209388a52ee5b62ad7e9 100644 --- a/hspace.1 +++ b/hspace.1 @@ -7,7 +7,7 @@ hspace \- Cluster space analyzer for Ganeti .B "[backend options...]" .B "[algorithm options...]" .B "[request options..."] -.B "[-p]" +.BI "[ -p[" fields "] ]" .B "[-v... | -q]" .B hspace @@ -221,7 +221,10 @@ that at least one quarter of disk space should be left free on nodes. Prints the before and after node status, in a format designed to allow the user to understand the node's most important parameters. -The node list will contain these informations: +It is possible to customise the listed information by passing a +comma-separated list of field names to this option (the field list is +currently undocumented). By default, the node list will contain these +informations: .RS .TP .B F diff --git a/hspace.hs b/hspace.hs index 386e7eff9d3fb5089bd2765aa931283b92fc0433..6ede8dec8e847cfb2c667c679297b1dc9ca8ba84 100644 --- a/hspace.hs +++ b/hspace.hs @@ -28,6 +28,7 @@ module Main (main) where import Data.Char (toUpper) import Data.List import Data.Function +import Data.Maybe (isJust, fromJust) import Monad import System import System.IO @@ -213,6 +214,7 @@ main = do let verbose = optVerbose opts ispec = optISpec opts + shownodes = optShowNodes opts (fixed_nl, il, csf) <- loadExternalData opts @@ -250,10 +252,10 @@ main = do when (length csf > 0 && verbose > 1) $ hPrintf stderr "Note: Stripping common suffix of '%s' from names\n" csf - when (optShowNodes opts) $ + when (isJust shownodes) $ do hPutStrLn stderr "Initial cluster status:" - hPutStrLn stderr $ Cluster.printNodes nl + hPutStrLn stderr $ Cluster.printNodes nl (fromJust shownodes) let ini_cv = Cluster.compCV nl ini_stats = Cluster.totalResources nl @@ -307,10 +309,10 @@ main = do formatTable (map (printInstance trl_nl) fin_trl_ixes) [False, False, False, True, True, True] - when (optShowNodes opts) $ do + when (isJust shownodes) $ do hPutStrLn stderr "" hPutStrLn stderr "Tiered allocation status:" - hPutStrLn stderr $ Cluster.printNodes trl_nl + hPutStrLn stderr $ Cluster.printNodes trl_nl (fromJust shownodes) printKeys $ printStats PTiered (Cluster.totalResources trl_nl) printKeys [("TSPEC", intercalate " " spec_map')]) @@ -329,10 +331,10 @@ main = do hPutStr stderr . unlines . map ((:) ' ' . intercalate " ") $ formatTable (map (printInstance fin_nl) fin_ixes) [False, False, False, True, True, True] - when (optShowNodes opts) $ + when (isJust shownodes) $ do hPutStrLn stderr "" hPutStrLn stderr "Final cluster status:" - hPutStrLn stderr $ Cluster.printNodes fin_nl + hPutStrLn stderr $ Cluster.printNodes fin_nl (fromJust shownodes) printResults fin_nl num_instances allocs sreason