Move more node-listing functionality in Node.hs
authorIustin Pop <iustin@google.com>
Mon, 9 Nov 2009 15:49:48 +0000 (16:49 +0100)
committerIustin Pop <iustin@google.com>
Mon, 9 Nov 2009 15:49:48 +0000 (16:49 +0100)
This will prepare for the runtime-selectable field list.

Ganeti/HTools/Cluster.hs
Ganeti/HTools/Node.hs

index d2a7dac..01a419e 100644 (file)
@@ -662,14 +662,9 @@ printSolution nl il sol =
 printNodes :: Node.List -> String
 printNodes nl =
     let snl = sortBy (compare `on` Node.idx) (Container.elems nl)
-        header = ["F", "Name"
-                 , "t_mem", "n_mem", "i_mem", "x_mem", "f_mem", "r_mem"
-                 , "t_dsk", "f_dsk", "pcpu", "vcpu", "pri",  "sec"
-                 , "p_fmem", "p_fdsk", "r_cpu"
-                 , "lCpu", "lMem", "lDsk", "lNet" ]
-        isnum = False:False:repeat True
+        (header, isnum) = unzip $ map Node.showHeader Node.defaultFields
     in unlines . map ((:) ' ' .  intercalate " ") $
-       formatTable (header:map Node.list snl) isnum
+       formatTable (header:map (Node.list Node.defaultFields) snl) isnum
 
 -- | Print the instance list.
 printInsts :: Node.List -> Instance.List -> String
index 23141d1..296d8b1 100644 (file)
@@ -49,6 +49,9 @@ module Ganeti.HTools.Node
     -- * Stats
     , availDisk
     -- * Formatting
+    , defaultFields
+    , showHeader
+    , showField
     , list
     -- * Misc stuff
     , AssocList
@@ -357,6 +360,7 @@ showField t field =
       "fmem" -> printf "%5d" $ fMem t
       "imem" -> printf "%5d" imem
       "rmem" -> printf "%5d" $ rMem t
+      "amem" -> printf "%5d" $ fMem t - rMem t
       "tdsk" -> printf "%5.0f" $ tDsk t / 1024
       "fdsk" -> printf "%5d" $ fDsk t `div` 1024
       "tcpu" -> printf "%4.0f" $ tCpu t
@@ -376,11 +380,42 @@ showField t field =
                   T.dskWeight = uD, T.netWeight = uN } = utilLoad t
       imem = truncate (tMem t) - nMem t - xMem t - fMem t
 
+-- | Returns the header and numeric propery of a field
+showHeader :: String -> (String, Bool)
+showHeader field =
+    case field of
+      "name" -> ("Name", False)
+      "status" -> ("F", False)
+      "tmem" -> ("t_mem", True)
+      "nmem" -> ("n_mem", True)
+      "xmem" -> ("x_mem", True)
+      "fmem" -> ("f_mem", True)
+      "imem" -> ("i_mem", True)
+      "rmem" -> ("r_mem", True)
+      "amem" -> ("a_mem", True)
+      "tdsk" -> ("t_dsk", True)
+      "fdsk" -> ("f_dsk", True)
+      "tcpu" -> ("pcpu", True)
+      "ucpu" -> ("vcpu", True)
+      "plist" -> ("pri", True)
+      "slist" -> ("sec", True)
+      "pfmem" -> ("p_fmem", True)
+      "pfdsk" -> ("p_fdsk", True)
+      "rcpu"  -> ("r_cpu", True)
+      "cload" -> ("lCpu", True)
+      "mload" -> ("lMem", True)
+      "dload" -> ("lDsk", True)
+      "nload" -> ("lNet", True)
+      _ -> ("<unknown field>", False)
 
 -- | String converter for the node list functionality.
-list :: Node -> [String]
-list t = map (showField t)
-         [ "status", "name", "tmem", "nmem", "imem", "xmem", "fmem"
-         , "rmem", "tdsk", "fdsk", "tcpu", "ucpu", "plist", "slist"
-         , "pfmem", "pfdsk", "rcpu"
-         , "cload", "mload", "dload", "nload" ]
+list :: [String] -> Node -> [String]
+list fields t = map (showField t) fields
+
+
+defaultFields :: [String]
+defaultFields =
+    [ "status", "name", "tmem", "nmem", "imem", "xmem", "fmem"
+    , "rmem", "tdsk", "fdsk", "tcpu", "ucpu", "plist", "slist"
+    , "pfmem", "pfdsk", "rcpu"
+    , "cload", "mload", "dload", "nload" ]