-parseNode :: JSObject JSValue -> Result (String, Node.Node)
-parseNode a = do
- name <- fromObj "name" a
- offline <- fromObj "offline" a
- node <- (case offline of
- True -> return $ Node.create name 0 0 0 0 0 True
- _ -> do
- drained <- fromObj "drained" a
- mtotal <- fromObj "mtotal" a
- mnode <- fromObj "mnode" a
- mfree <- fromObj "mfree" a
- dtotal <- fromObj "dtotal" a
- dfree <- fromObj "dfree" a
- return $ Node.create name mtotal mnode mfree
- dtotal dfree (offline || drained))
- return (name, node)
-
-loadData :: String -- ^ Cluster/URL to use as source
- -> IO (Result (Node.AssocList, Instance.AssocList))
-loadData master = do -- IO monad
+-- | Construct a node from a JSON object.
+parseNode :: NameAssoc -> [(String, JSValue)] -> Result (String, Node.Node)
+parseNode ktg a = do
+ name <- tryFromObj "Parsing new node" a "name"
+ let extract s = tryFromObj ("Node '" ++ name ++ "'") a s
+ offline <- extract "offline"
+ drained <- extract "drained"
+ guuid <- extract "group.uuid" >>= lookupGroup ktg name
+ node <- (if offline || drained
+ then return $ Node.create name 0 0 0 0 0 0 True guuid
+ else do
+ mtotal <- extract "mtotal"
+ mnode <- extract "mnode"
+ mfree <- extract "mfree"
+ dtotal <- extract "dtotal"
+ dfree <- extract "dfree"
+ ctotal <- extract "ctotal"
+ return $ Node.create name mtotal mnode mfree
+ dtotal dfree ctotal False guuid)
+ return (name, node)
+
+-- | Construct a group from a JSON object.
+parseGroup :: [(String, JSValue)] -> Result (String, Group.Group)
+parseGroup a = do
+ name <- tryFromObj "Parsing new group" a "name"
+ let extract s = tryFromObj ("Group '" ++ name ++ "'") a s
+ uuid <- extract "uuid"
+ apol <- extract "alloc_policy"
+ return (uuid, Group.create name uuid apol)
+
+-- | Loads the raw cluster data from an URL.
+readData :: String -- ^ Cluster or URL to use as source
+ -> IO (Result String, Result String, Result String, Result String)
+readData master = do