commit 1c3231aad9e5dddbe9490d49896434000cec6dd9
Author: Thomas Thrainer <thomasth@google.com>
Date:   Mon May 27 16:17:41 2013 +0200

    Index nodes by their UUID
    
    No longer index nodes by their name but by their UUID in the cluster
    config. This change changes large parts of the code, as the following
    adjustments were necessary:
     * Change the index key to UUID in the configuration and the
       ConfigWriter, including all methods.
     * Change all cross-references to nodes to use UUID's.
     * External interfaces (command line interface, IAllocator interface,
       hook scripts, etc.) are kept stable.
     * RPC-calls can resolve UUID's as target node arguments, if the RPC
       runner is based on a ConfigWriter instance. The result dictionary is
       presented in the form the nodes are addressed: by UUID if UUID's were
       given, or by name if names were given.
     * Node UUID's are resolved in ExpandNames and then stored in the
       OpCode. This allows to check for node renames if the OpCode is
       reloaded after a cluster restart. This check is currently only done
       for single node parameters.
     * Variable names are renamed to follow the following pattern:
       - Suffix is 'node' or 'nodes': Variable holds Node objects
       - Suffix is 'name' or 'names': Variable holds node names
       - Suffix is 'uuid' or 'uuids': Variable holds node UUID's
     * Tests are adapted.
    
    Signed-off-by: Thomas Thrainer <thomasth@google.com>
    Reviewed-by: Klaus Aehlig <aehlig@google.com>

diff --git a/src/Ganeti/Confd/Server.hs b/src/Ganeti/Confd/Server.hs
index 4339ce2..f05d3b5 100644
--- a/src/Ganeti/Confd/Server.hs
+++ b/src/Ganeti/Confd/Server.hs
@@ -59,6 +59,7 @@ import Ganeti.Logging
 import qualified Ganeti.Constants as C
 import qualified Ganeti.Path as Path
 import Ganeti.Query.Server (prepQueryD, runQueryD)
+import qualified Ganeti.Query.Cluster as QCluster
 import Ganeti.Utils
 
 -- * Types and constants definitions
@@ -137,16 +138,16 @@ gntErrorToResult (Ok x) = Ok x
 
 -- | Computes the node role.
 nodeRole :: ConfigData -> String -> Result ConfdNodeRole
-nodeRole cfg name =
-  let cmaster = clusterMasterNode . configCluster $ cfg
-      mnode = M.lookup name . fromContainer . configNodes $ cfg
-  in case mnode of
-       Nothing -> Bad "Node not found"
-       Just node | cmaster == name -> Ok NodeRoleMaster
-                 | nodeDrained node -> Ok NodeRoleDrained
-                 | nodeOffline node -> Ok NodeRoleOffline
-                 | nodeMasterCandidate node -> Ok NodeRoleCandidate
-       _ -> Ok NodeRoleRegular
+nodeRole cfg name = do
+  cmaster <- errToResult $ QCluster.clusterMasterNodeName cfg
+  mnode <- errToResult $ getNode cfg name
+  let role = case mnode of
+               node | cmaster == name -> NodeRoleMaster
+                    | nodeDrained node -> NodeRoleDrained
+                    | nodeOffline node -> NodeRoleOffline
+                    | nodeMasterCandidate node -> NodeRoleCandidate
+               _ -> NodeRoleRegular
+  return role
 
 -- | Does an instance ip -> instance -> primary node -> primary ip
 -- transformation.
@@ -170,17 +171,19 @@ buildResponse (cfg, _) (ConfdRequest { confdRqType = ReqPing }) =
 
 buildResponse cdata req@(ConfdRequest { confdRqType = ReqClusterMaster }) =
   case confdRqQuery req of
-    EmptyQuery -> return (ReplyStatusOk, J.showJSON master_name)
+    EmptyQuery -> liftM ((,) ReplyStatusOk . J.showJSON) master_name
     PlainQuery _ -> return queryArgumentError
     DictQuery reqq -> do
-      mnode <- gntErrorToResult $ getNode cfg master_name
+      mnode <- gntErrorToResult $ getNode cfg master_uuid
+      mname <- master_name
       let fvals = map (\field -> case field of
-                                   ReqFieldName -> master_name
+                                   ReqFieldName -> mname
                                    ReqFieldIp -> clusterMasterIp cluster
                                    ReqFieldMNodePip -> nodePrimaryIp mnode
                       ) (confdReqQFields reqq)
       return (ReplyStatusOk, J.showJSON fvals)
-    where master_name = clusterMasterNode cluster
+    where master_uuid = clusterMasterNode cluster
+          master_name = errToResult $ QCluster.clusterMasterNodeName cfg
           cluster = configCluster cfg
           cfg = fst cdata
 
