Utility function to set the master node in a node list
authorKlaus Aehlig <aehlig@google.com>
Wed, 17 Apr 2013 09:42:28 +0000 (11:42 +0200)
committerKlaus Aehlig <aehlig@google.com>
Fri, 19 Apr 2013 11:54:14 +0000 (13:54 +0200)
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

index f5b5c72..49109ab 100644 (file)
@@ -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