-parseNode :: JSObject JSValue -> Result String
-parseNode a =
- let name = getStringElement "name" a
- offline = getBoolElement "offline" a
- drained = getBoolElement "drained" a
- mtotal = getIntElement "mtotal" a
- mnode = getIntElement "mnode" a
- mfree = getIntElement "mfree" a
- dtotal = getIntElement "dtotal" a
- dfree = getIntElement "dfree" a
- in name |+
- (case offline of
- Ok True -> Ok "0|0|0|0|0|Y"
- _ ->
- (show `liftM` mtotal) |+ (show `liftM` mnode) |+
- (show `liftM` mfree) |+ (show `liftM` dtotal) |+
- (show `liftM` dfree) |+
- ((liftM2 (||) offline drained) >>= boolToYN)
- )
+loadData :: String -- ^ Cluster/URL to use as source
+ -> IO (Result (NameAssoc, Node.AssocList,
+ NameAssoc, Instance.AssocList))
+loadData master = do -- IO monad
+ let url = formatHost master
+ node_body <- getUrl $ printf "%s/2/nodes?bulk=1" url
+ 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_data
+ inst_data <- inst_body >>= getInstances node_names
+ let (inst_names, inst_idx) = assignIndices inst_data
+ return (node_names, node_idx, inst_names, inst_idx)