Add node memory field to Node objects
authorIustin Pop <iustin@google.com>
Sat, 21 Mar 2009 23:25:55 +0000 (00:25 +0100)
committerIustin Pop <iustin@google.com>
Sat, 21 Mar 2009 23:25:55 +0000 (00:25 +0100)
This patch adds a new n_mem field to the node objects, and implements
read/save/show support for it. The field is not currently used (except
in the node list) but will be used for checking data consistency and
instance up/down status.

Ganeti/HTools/Cluster.hs
Ganeti/HTools/Node.hs
Ganeti/HTools/Rapi.hs
README
hbal.1
hn1.1
hscan.hs

index 31b9e4e..3dc52d2 100644 (file)
@@ -642,8 +642,8 @@ printNodes ktn nl =
         snl' = map (\ n -> ((fromJust $ lookup (Node.idx n) ktn), n)) snl
         m_name = maximum . (map length) . fst . unzip $ snl'
         helper = Node.list m_name
-        header = printf "%2s %-*s %5s %5s %5s %5s %5s %3s %3s %7s %7s"
-                 " F" m_name "Name" "t_mem" "f_mem" "r_mem"
+        header = printf "%2s %-*s %5s %5s %5s %5s %5s %5s %3s %3s %7s %7s"
+                 " F" m_name "Name" "t_mem" "n_mem" "f_mem" "r_mem"
                  "t_dsk" "f_dsk"
                  "pri" "sec" "p_fmem" "p_fdsk"
     in unlines $ (header:map (uncurry helper) snl')
@@ -750,11 +750,12 @@ loadData :: String -- ^ Node data in text format
              String, NameList, NameList)
 loadData ndata idata =
     let
-    {- node file: name t_mem f_mem t_disk f_disk -}
+    {- node file: name t_mem n_mem f_mem t_disk f_disk -}
         (ktn, nl) = loadTabular ndata
-                    (\ (name:tm:fm:td:fd:[]) ->
+                    (\ (name:tm:nm:fm:td:fd:[]) ->
                          (name,
-                          Node.create (read tm) (read fm) (read td) (read fd)))
+                          Node.create (read tm) (read nm)
+                                  (read fm) (read td) (read fd)))
                     Node.setIdx
     {- instance file: name mem disk pnode snode -}
         (kti, il) = loadTabular idata
index 5219778..8a6ef3b 100644 (file)
@@ -6,7 +6,8 @@
 
 module Ganeti.HTools.Node
     (
-      Node(failN1, idx, t_mem, f_mem, t_dsk, f_dsk, p_mem, p_dsk, p_rem,
+      Node(failN1, idx, t_mem, n_mem, f_mem, t_dsk, f_dsk,
+           p_mem, p_dsk, p_rem,
            plist, slist, offline)
     -- * Constructor
     , create
@@ -34,7 +35,8 @@ import qualified Ganeti.HTools.PeerMap as PeerMap
 
 import Ganeti.HTools.Utils
 
-data Node = Node { t_mem :: Double -- ^ total memory (Mib)
+data Node = Node { t_mem :: Double -- ^ total memory (MiB)
+                 , n_mem :: Int    -- ^ node memory (MiB)
                  , f_mem :: Int    -- ^ free memory (MiB)
                  , t_dsk :: Double -- ^ total disk space (MiB)
                  , f_dsk :: Int    -- ^ free disk space (MiB)
@@ -59,11 +61,12 @@ The index and the peers maps are empty, and will be need to be update
 later via the 'setIdx' and 'buildPeers' functions.
 
 -}
-create :: Double -> Int -> Double -> Int -> Node
-create mem_t_init mem_f_init dsk_t_init dsk_f_init =
+create :: Double -> Int -> Int -> Double -> Int -> Node
+create mem_t_init mem_n_init mem_f_init dsk_t_init dsk_f_init =
     Node
     {
       t_mem = mem_t_init,
+      n_mem = mem_n_init,
       f_mem = mem_f_init,
       t_dsk = dsk_t_init,
       f_dsk = dsk_f_init,
@@ -217,9 +220,9 @@ list mname n t =
         off = offline t
         fn = failN1 t
     in
-      printf " %c %-*s %5.0f %5d %5d %5.0f %5d %3d %3d %.5f %.5f"
+      printf " %c %-*s %5.0f %5d %5d %5d %5.0f %5d %3d %3d %.5f %.5f"
                  (if off then '-' else if fn then '*' else ' ')
-                 mname n (t_mem t) (f_mem t) (r_mem t)
+                 mname n (t_mem t) (n_mem t) (f_mem t) (r_mem t)
                  ((t_dsk t) / 1024) ((f_dsk t) `div` 1024)
                  (length pl) (length sl)
                  mp dp
index e352313..ba1b577 100644 (file)
@@ -161,10 +161,12 @@ parseNode :: JSObject JSValue -> Either String String
 parseNode a =
     let name = getStringElement "name" a
         mtotal = getIntElement "mtotal" a
+        mnode = getIntElement "mnode" a
         mfree = getIntElement "mfree" a
         dtotal = getIntElement "dtotal" a
         dfree = getIntElement "dfree" a
     in concatElems name $
        concatElems (show `apply1` mtotal) $
+       concatElems (show `apply1` mnode) $
        concatElems (show `apply1` mfree) $
        concatElems (show `apply1` dtotal) (show `apply1` dfree)
diff --git a/README b/README
index 03f3209..b1311fd 100644 (file)
--- a/README
+++ b/README
@@ -240,7 +240,7 @@ The programs can either get their input from text files, or directly
 from a cluster via RAPI. For text files, the following two commands
 should be run::
 
-    gnt-node list -oname,mtotal,mfree,dtotal,dfree \
+    gnt-node list -oname,mtotal,mnode,mfree,dtotal,dfree \
       --separator '|' --no-headers > nodes
     gnt-instance list -oname,admin_ram,sda_size,pnode,snodes \
       --separator '|' --no-head > instances
diff --git a/hbal.1 b/hbal.1
index 323bf2e..9955073 100644 (file)
--- a/hbal.1
+++ b/hbal.1
@@ -111,6 +111,7 @@ The node list will contain these informations:
     node
   - the node name
   - the total node memory
+  - the memory used by the node itself
   - the free node memory
   - the reserved node memory, which is the amount of free memory
     needed for N+1 compliance
diff --git a/hn1.1 b/hn1.1
index f3920ee..ff66d88 100644 (file)
--- a/hn1.1
+++ b/hn1.1
@@ -97,6 +97,7 @@ The node list will contain these informations:
     node
   - the node name
   - the total node memory
+  - the memory used by the node itself
   - the free node memory
   - the reserved node memory, which is the amount of free memory
     needed for N+1 compliance
index dd26798..3922718 100644 (file)
--- a/hscan.hs
+++ b/hscan.hs
@@ -85,8 +85,8 @@ serializeNodes nl csf ktn =
                           t_mem = (truncate $ Node.t_mem node)::Int
                           t_dsk = (truncate $ Node.t_dsk node)::Int
                       in
-                        printf "%s|%d|%d|%d|%d" name
-                                   t_mem (Node.f_mem node)
+                        printf "%s|%d|%d|%d|%d|%d" name
+                                   t_mem (Node.n_mem node) (Node.f_mem node)
                                    t_dsk (Node.f_dsk node))
                  nodes
     in unlines nlines