In Rapi, set master correctly
authorKlaus Aehlig <aehlig@google.com>
Wed, 17 Apr 2013 09:22:02 +0000 (11:22 +0200)
committerKlaus Aehlig <aehlig@google.com>
Fri, 19 Apr 2013 11:54:38 +0000 (13:54 +0200)
The cluster data contains the information about the master
node. Use this information to set the isMaster bit correctly.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

src/Ganeti/HTools/Backend/Rapi.hs

index 4f8f52b..ffc6dc2 100644 (file)
@@ -166,7 +166,7 @@ parseNode ktg a = do
               dtotal  <- extract "dtotal"
               dfree   <- extract "dfree"
               ctotal  <- extract "ctotal"
-              return $ Node.create name mtotal mnode mfree 
+              return $ Node.create name mtotal mnode mfree
                      dtotal dfree ctotal False spindles guuid'
   return (name, node)
 
@@ -182,13 +182,14 @@ parseGroup a = do
   return (uuid, Group.create name uuid apol ipol tags)
 
 -- | Parse cluster data from the info resource.
-parseCluster :: JSObject JSValue -> Result ([String], IPolicy)
+parseCluster :: JSObject JSValue -> Result ([String], IPolicy, String)
 parseCluster obj = do
   let obj' = fromJSObject obj
       extract s = tryFromObj "Parsing cluster data" obj' s
+  master <- extract "master"
   tags <- extract "tags"
   ipolicy <- extract "ipolicy"
-  return (tags, ipolicy)
+  return (tags, ipolicy, master)
 
 -- | Loads the raw cluster data from an URL.
 readDataHttp :: String -- ^ Cluster or URL to use as source
@@ -229,10 +230,12 @@ parseData (group_body, node_body, inst_body, info_body) = do
   let (node_names, node_idx) = assignIndices node_data
   inst_data <- inst_body >>= getInstances node_names
   let (_, inst_idx) = assignIndices inst_data
-  (tags, ipolicy) <- info_body >>=
-                     (fromJResult "Parsing cluster info" . decodeStrict) >>=
-                     parseCluster
-  return (ClusterData group_idx node_idx inst_idx tags ipolicy)
+  (tags, ipolicy, master) <- 
+    info_body >>=
+    (fromJResult "Parsing cluster info" . decodeStrict) >>=
+    parseCluster
+  node_idx' <- setMaster node_names node_idx master
+  return (ClusterData group_idx node_idx' inst_idx tags ipolicy)
 
 -- | Top level function for data loading.
 loadData :: String -- ^ Cluster or URL to use as source