Add a small class for Nodes and Instances
[ganeti-local] / Ganeti / HTools / Rapi.hs
index 5cfc42b..ac0ff44 100644 (file)
@@ -17,6 +17,7 @@ import Text.Printf (printf)
 
 import Ganeti.HTools.Utils
 import Ganeti.HTools.Loader
+import Ganeti.HTools.Types
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
 
@@ -58,11 +59,11 @@ parseInstance ktn a = do
   disk <- fromObj "disk_usage" a
   mem <- fromObj "beparams" a >>= fromObj "memory"
   pnode <- fromObj "pnode" a >>= lookupNode ktn name
-  snodes <- getListElement "snodes" a
+  snodes <- fromObj "snodes" a
   snode <- (if null snodes then return Node.noSecondary
             else readEitherString (head snodes) >>= lookupNode ktn name)
   running <- fromObj "status" a
-  let inst = Instance.create mem disk running pnode snode
+  let inst = Instance.create name mem disk running pnode snode
   return (name, inst)
 
 parseNode :: JSObject JSValue -> Result (String, Node.Node)
@@ -70,7 +71,7 @@ parseNode a = do
     name <- fromObj "name" a
     offline <- fromObj "offline" a
     node <- (case offline of
-               True -> return $ Node.create 0 0 0 0 0 True
+               True -> return $ Node.create name 0 0 0 0 0 True
                _ -> do
                  drained <- fromObj "drained" a
                  mtotal <- fromObj "mtotal" a
@@ -78,7 +79,7 @@ parseNode a = do
                  mfree <- fromObj "mfree" a
                  dtotal <- fromObj "dtotal" a
                  dfree <- fromObj "dfree" a
-                 return $ Node.create mtotal mnode mfree
+                 return $ Node.create name mtotal mnode mfree
                         dtotal dfree (offline || drained))
     return (name, node)
 
@@ -91,7 +92,7 @@ loadData master = do -- IO monad
   inst_body <- getUrl $ printf "%s/2/instances?bulk=1" url
   return $ do -- Result monad
     node_data <- node_body >>= getNodes
-    let (node_names, node_idx) = assignIndices Node.setIdx node_data
+    let (node_names, node_idx) = assignIndices node_data
     inst_data <- inst_body >>= getInstances node_names
-    let (inst_names, inst_idx) = assignIndices Instance.setIdx inst_data
+    let (inst_names, inst_idx) = assignIndices inst_data
     return (node_names, node_idx, inst_names, inst_idx)