From a68004b7c0324b0898a611928a4c263e3158f76a Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 22 Nov 2010 16:00:21 +0100
Subject: [PATCH] Node: add the node group's UUID

This is not used anywhere yet, and the backend are all just adding the
default UUID, not the real one.

The patch also allows displaying the group UUID in the node list.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Balazs Lecz <leczb@google.com>
---
 Ganeti/HTools/IAlloc.hs |  4 ++--
 Ganeti/HTools/Luxi.hs   |  7 ++++---
 Ganeti/HTools/Node.hs   | 10 +++++++---
 Ganeti/HTools/QC.hs     |  1 +
 Ganeti/HTools/Rapi.hs   |  4 ++--
 Ganeti/HTools/Simu.hs   |  2 +-
 Ganeti/HTools/Text.hs   |  4 ++--
 7 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs
index 88b4a5c88..679ce161b 100644
--- a/Ganeti/HTools/IAlloc.hs
+++ b/Ganeti/HTools/IAlloc.hs
@@ -81,7 +81,7 @@ parseNode n a = do
   offline <- fromObj "offline" a
   drained <- fromObj "drained" a
   node <- (if offline || drained
-           then return $ Node.create n 0 0 0 0 0 0 True
+           then return $ Node.create n 0 0 0 0 0 0 True defaultUUID
            else do
              mtotal <- fromObj "total_memory" a
              mnode  <- fromObj "reserved_memory" a
@@ -90,7 +90,7 @@ parseNode n a = do
              dfree  <- fromObj "free_disk"    a
              ctotal <- fromObj "total_cpus"   a
              return $ Node.create n mtotal mnode mfree
-                    dtotal dfree ctotal False)
+                    dtotal dfree ctotal False defaultUUID)
   return (n, node)
 
 -- | Top-level parser.
diff --git a/Ganeti/HTools/Luxi.hs b/Ganeti/HTools/Luxi.hs
index 7153481c9..9cf66a1fa 100644
--- a/Ganeti/HTools/Luxi.hs
+++ b/Ganeti/HTools/Luxi.hs
@@ -37,7 +37,8 @@ import Ganeti.HTools.Loader
 import Ganeti.HTools.Types
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
-import Ganeti.HTools.Utils (fromJVal, annotateResult, tryFromObj, asJSObject)
+import Ganeti.HTools.Utils (fromJVal, annotateResult, tryFromObj, asJSObject,
+                            defaultUUID)
 
 -- * Utility functions
 
@@ -123,7 +124,7 @@ parseNode (JSArray [ name, mtotal, mnode, mfree, dtotal, dfree
   xdrained <- convert drained
   xvm_capable <- convert vm_capable
   node <- (if xoffline || xdrained || not xvm_capable
-           then return $ Node.create xname 0 0 0 0 0 0 True
+           then return $ Node.create xname 0 0 0 0 0 0 True defaultUUID
            else do
              xmtotal  <- convert mtotal
              xmnode   <- convert mnode
@@ -132,7 +133,7 @@ parseNode (JSArray [ name, mtotal, mnode, mfree, dtotal, dfree
              xdfree   <- convert dfree
              xctotal  <- convert ctotal
              return $ Node.create xname xmtotal xmnode xmfree
-                    xdtotal xdfree xctotal False)
+                    xdtotal xdfree xctotal False defaultUUID)
   return (xname, node)
 
 parseNode v = fail ("Invalid node query result: " ++ show v)
diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs
index 37deec55e..be2a3dc8b 100644
--- a/Ganeti/HTools/Node.hs
+++ b/Ganeti/HTools/Node.hs
@@ -68,7 +68,7 @@ module Ganeti.HTools.Node
     , noSecondary
     ) where
 
-import Data.List
+import Data.List hiding (group)
 import qualified Data.Map as Map
 import qualified Data.Foldable as Foldable
 import Text.Printf (printf)
@@ -119,6 +119,7 @@ data Node = Node
     , utilPool :: T.DynUtil -- ^ Total utilisation capacity
     , utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
     , pTags    :: TagMap    -- ^ Map of primary instance tags and their count
+    , group    :: String    -- ^ The node's group (as UUID)
     } deriving (Show, Eq)
 
 instance T.Element Node where
@@ -182,9 +183,9 @@ conflictingPrimaries (Node { pTags = t }) = Foldable.sum t - Map.size t
 -- The index and the peers maps are empty, and will be need to be
 -- update later via the 'setIdx' and 'buildPeers' functions.
 create :: String -> Double -> Int -> Int -> Double
-       -> Int -> Double -> Bool -> Node
+       -> Int -> Double -> Bool -> String -> Node
 create name_init mem_t_init mem_n_init mem_f_init
-       dsk_t_init dsk_f_init cpu_t_init offline_init =
+       dsk_t_init dsk_f_init cpu_t_init offline_init group_init =
     Node { name = name_init
          , alias = name_init
          , tMem = mem_t_init
@@ -213,6 +214,7 @@ create name_init mem_t_init mem_n_init mem_f_init
          , utilPool = T.baseUtil
          , utilLoad = T.zeroUtil
          , pTags = Map.empty
+         , group = group_init
          }
 
 -- | Conversion formula from mDsk\/tDsk to loDsk
@@ -483,6 +485,7 @@ showField t field =
       "ptags" -> intercalate "," . map (\(k, v) -> printf "%s=%d" k v) .
                  Map.toList $ pTags t
       "peermap" -> show $ peers t
+      "group.uuid" -> group t
       _ -> T.unknownField
     where
       T.DynUtil { T.cpuWeight = uC, T.memWeight = uM,
@@ -521,6 +524,7 @@ showHeader field =
       "nload" -> ("lNet", True)
       "ptags" -> ("PrimaryTags", False)
       "peermap" -> ("PeerMap", False)
+      "group.uuid" -> ("GroupUUID", False)
       _ -> (T.unknownField, False)
 
 -- | String converter for the node list functionality.
diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs
index b7a030f14..5e7120ea0 100644
--- a/Ganeti/HTools/QC.hs
+++ b/Ganeti/HTools/QC.hs
@@ -176,6 +176,7 @@ instance Arbitrary Node.Node where
       offl <- arbitrary
       let n = Node.create name (fromIntegral mem_t) mem_n mem_f
               (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl
+              Utils.defaultUUID
           n' = Node.buildPeers n Container.empty
       return n'
 
diff --git a/Ganeti/HTools/Rapi.hs b/Ganeti/HTools/Rapi.hs
index d0619204e..3f4a754ea 100644
--- a/Ganeti/HTools/Rapi.hs
+++ b/Ganeti/HTools/Rapi.hs
@@ -106,7 +106,7 @@ parseNode a = do
   offline <- extract "offline"
   drained <- extract "drained"
   node <- (if offline || drained
-           then return $ Node.create name 0 0 0 0 0 0 True
+           then return $ Node.create name 0 0 0 0 0 0 True defaultUUID
            else do
              mtotal  <- extract "mtotal"
              mnode   <- extract "mnode"
@@ -115,7 +115,7 @@ parseNode a = do
              dfree   <- extract "dfree"
              ctotal  <- extract "ctotal"
              return $ Node.create name mtotal mnode mfree
-                    dtotal dfree ctotal False)
+                    dtotal dfree ctotal False defaultUUID)
   return (name, node)
 
 -- | Loads the raw cluster data from an URL.
diff --git a/Ganeti/HTools/Simu.hs b/Ganeti/HTools/Simu.hs
index 6c01726ec..d41f4a39b 100644
--- a/Ganeti/HTools/Simu.hs
+++ b/Ganeti/HTools/Simu.hs
@@ -59,7 +59,7 @@ parseData ndata = do
                     let n = Node.create (printf "node%03d" idx)
                             (fromIntegral mem) 0 mem
                             (fromIntegral disk) disk
-                            (fromIntegral cpu) False
+                            (fromIntegral cpu) False defaultUUID
                     in (idx, Node.setIdx n idx)
                   ) [1..cnt]
   return (nodes, [], [])
diff --git a/Ganeti/HTools/Text.hs b/Ganeti/HTools/Text.hs
index c9aac174a..5b8d95598 100644
--- a/Ganeti/HTools/Text.hs
+++ b/Ganeti/HTools/Text.hs
@@ -95,7 +95,7 @@ loadNode :: (Monad m) => [String] -> m (String, Node.Node)
 loadNode [name, tm, nm, fm, td, fd, tc, fo] = do
   new_node <-
       if any (== "?") [tm,nm,fm,td,fd,tc] || fo == "Y" then
-          return $ Node.create name 0 0 0 0 0 0 True
+          return $ Node.create name 0 0 0 0 0 0 True defaultUUID
       else do
         vtm <- tryRead name tm
         vnm <- tryRead name nm
@@ -103,7 +103,7 @@ loadNode [name, tm, nm, fm, td, fd, tc, fo] = do
         vtd <- tryRead name td
         vfd <- tryRead name fd
         vtc <- tryRead name tc
-        return $ Node.create name vtm vnm vfm vtd vfd vtc False
+        return $ Node.create name vtm vnm vfm vtd vfd vtc False defaultUUID
   return (name, new_node)
 loadNode s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'"
 
-- 
GitLab