Allow overriding the field list in -p
authorIustin Pop <iustin@google.com>
Tue, 10 Nov 2009 12:59:56 +0000 (13:59 +0100)
committerIustin Pop <iustin@google.com>
Tue, 10 Nov 2009 12:59:56 +0000 (13:59 +0100)
The print nodes option can now accept an optional field list to
customise the output. This is ugly, since the field names do not match
the header names, but it is at least barely customisable (at runtime).

Ganeti/HTools/CLI.hs
Ganeti/HTools/Cluster.hs
hbal.1
hbal.hs
hscan.hs
hspace.1
hspace.hs

index 89432fc..b977b6a 100644 (file)
@@ -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
index 01a419e..9a94d0b 100644 (file)
@@ -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 e74ecd8..52622fc 100644 (file)
--- 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 aa5cfde..1ad686e 100644 (file)
--- 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"
index d4b8641..66b6e4f 100644 (file)
--- 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
index 194aec7..075f01d 100644 (file)
--- 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
index 386e7ef..6ede8de 100644 (file)
--- 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