From 09ab9fb23019c1a71f16004956d6b3f135a9282b Mon Sep 17 00:00:00 2001
From: Klaus Aehlig <aehlig@google.com>
Date: Wed, 17 Apr 2013 11:42:28 +0200
Subject: [PATCH] Utility function to set the master node in a node list

The information about which node is the master node is a cluster-wide
setting, in most formats provided independently of the node information.
Most backends therefore have to set the isMaster bit indepently in the
obtained node list. This patch provides a utility function for this.

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

diff --git a/src/Ganeti/HTools/Loader.hs b/src/Ganeti/HTools/Loader.hs
index f5b5c723d..49109ab56 100644
--- a/src/Ganeti/HTools/Loader.hs
+++ b/src/Ganeti/HTools/Loader.hs
@@ -30,6 +30,7 @@ module Ganeti.HTools.Loader
   ( mergeData
   , checkData
   , assignIndices
+  , setMaster
   , lookupNode
   , lookupInstance
   , lookupGroup
@@ -127,6 +128,14 @@ assignIndices name_element =
           . zip [0..] $ name_element
   in (M.fromList name_idx, Container.fromList idx_element)
 
+-- | Given am indexed node list, and the name of the master, mark it as such. 
+setMaster :: (Monad m) => NameAssoc -> Node.List -> String -> m Node.List
+setMaster node_names node_idx master = do
+  kmaster <- maybe (fail $ "Master node " ++ master ++ " unknown") return $
+             M.lookup master node_names
+  let mnode = Container.find kmaster node_idx
+  return $ Container.add kmaster (Node.setMaster mnode True) node_idx
+
 -- | For each instance, add its index to its primary and secondary nodes.
 fixNodes :: Node.List
          -> Instance.Instance
-- 
GitLab