-parseInstance :: JSObject JSValue -> Either String String
-parseInstance a =
- let name = getStringElement "name" a
- disk = case getIntElement "disk_usage" a of
- Left _ -> let log_sz = applyEither2 (+)
- (getIntElement "sda_size" a)
- (getIntElement "sdb_size" a)
- in applyEither2 (+) log_sz
- (Right $ drbdOverhead * 2)
- Right x -> Right x
- bep = fromObj "beparams" a
- pnode = getStringElement "pnode" a
- snode = (eitherListHead $ getListElement "snodes" a)
- `combineEithers` readEitherString
- mem = case bep of
- Left _ -> getIntElement "admin_ram" a
- Right o -> getIntElement "memory" o
- running = getStringElement "status" a
- in
- concatEitherElems name $
- concatEitherElems (show `applyEither1` mem) $
- concatEitherElems (show `applyEither1` disk) $
- concatEitherElems running $
- concatEitherElems pnode snode
+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)