From 000ca91aaa9a42d843cde676714d3b81a781931e Mon Sep 17 00:00:00 2001
From: Klaus Aehlig <aehlig@google.com>
Date: Fri, 19 Apr 2013 14:58:43 +0200
Subject: [PATCH] Extend Text format by marking the master node

Sometimes, e.g., for hroller, it is necessary to know which node
is the master node. Therefore this information has to be included
in the text format as well. Since we never use an offline node as
master node, we can put this information can be put in the "is
offline" field; as old versions only check this field for equality
to "Y", using "M" to indicate the master is compatible in both
directions. This also leaves room to add more roles in the future,
should we need them.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 src/Ganeti/HTools/Backend/Text.hs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/Ganeti/HTools/Backend/Text.hs b/src/Ganeti/HTools/Backend/Text.hs
index 755d8bebf..579ce77bc 100644
--- a/src/Ganeti/HTools/Backend/Text.hs
+++ b/src/Ganeti/HTools/Backend/Text.hs
@@ -83,7 +83,8 @@ serializeNode gl node =
   printf "%s|%.0f|%d|%d|%.0f|%d|%.0f|%c|%s|%d" (Node.name node)
            (Node.tMem node) (Node.nMem node) (Node.fMem node)
            (Node.tDsk node) (Node.fDsk node) (Node.tCpu node)
-           (if Node.offline node then 'Y' else 'N')
+           (if Node.offline node then 'Y' else
+              if Node.isMaster node then 'M' else 'N')
            (Group.uuid grp)
            (Node.spindleCount node)
     where grp = Container.find (Node.group node) gl
@@ -196,7 +197,8 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles] = do
         vfd <- tryRead name fd
         vtc <- tryRead name tc
         vspindles <- tryRead name spindles
-        return $ Node.create name vtm vnm vfm vtd vfd vtc False vspindles gdx
+        return . flip Node.setMaster (fo == "M") $
+          Node.create name vtm vnm vfm vtd vfd vtc False vspindles gdx
   return (name, new_node)
 
 loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu] =
-- 
GitLab