_ -> Left $ printf "Curl error for '%s', error %s"
url (show code))
-tryRapi :: String -> String -> IO (Either String String)
-tryRapi url1 url2 =
- do
- body1 <- getUrl url1
- (case body1 of
- Left _ -> getUrl url2
- Right _ -> return body1)
-
getInstances :: String -> IO (Either String String)
-getInstances master =
- let
- url2 = printf "https://%s:5080/2/instances?bulk=1" master
- url1 = printf "http://%s:5080/instances?bulk=1" master
- in do
- body <- tryRapi url1 url2
- let inst = body `combineEithers`
- loadJSArray `combineEithers`
- (parseEitherList parseInstance)
- return inst
+getInstances master = do
+ let url2 = printf "https://%s:5080/2/instances?bulk=1" master
+ body <- getUrl url2
+ let inst = body `combineEithers`
+ loadJSArray `combineEithers`
+ (parseEitherList parseInstance)
+ return inst
getNodes :: String -> IO (Either String String)
-getNodes master =
- let
- url2 = printf "https://%s:5080/2/nodes?bulk=1" master
- url1 = printf "http://%s:5080/nodes?bulk=1" master
- in do
- body <- tryRapi url1 url2
- let inst = body `combineEithers`
- loadJSArray `combineEithers`
- (parseEitherList parseNode)
- return inst
+getNodes master = do
+ let url2 = printf "https://%s:5080/2/nodes?bulk=1" master
+ body <- getUrl url2
+ let inst = body `combineEithers`
+ loadJSArray `combineEithers`
+ (parseEitherList parseNode)
+ return inst
parseInstance :: JSObject JSValue -> Either String String
parseInstance a =
concatEitherElems running $
concatEitherElems pnode snode
+boolToYN :: Bool -> Either String String
+boolToYN True = Right "Y"
+boolToYN _ = Right "N"
+
parseNode :: JSObject JSValue -> Either String 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 concatEitherElems name $
- concatEitherElems (show `applyEither1` mtotal) $
- concatEitherElems (show `applyEither1` mnode) $
- concatEitherElems (show `applyEither1` mfree) $
- concatEitherElems (show `applyEither1` dtotal)
- (show `applyEither1` dfree)
+ (case offline of
+ Right True -> Right "0|0|0|0|0|Y"
+ _ ->
+ concatEitherElems (show `applyEither1` mtotal) $
+ concatEitherElems (show `applyEither1` mnode) $
+ concatEitherElems (show `applyEither1` mfree) $
+ concatEitherElems (show `applyEither1` dtotal) $
+ concatEitherElems (show `applyEither1` dfree)
+ ((applyEither2 (||) offline drained) `combineEithers` boolToYN)
+ )