diff --git a/Ganeti/HTools/Luxi.hs b/Ganeti/HTools/Luxi.hs index 8fe728f0cae48396c68bd9ea1488de904182d215..4463683bafd295b2c52e61cbff82947205d0b965 100644 --- a/Ganeti/HTools/Luxi.hs +++ b/Ganeti/HTools/Luxi.hs @@ -70,7 +70,7 @@ queryInstancesMsg = let nnames = JSArray [] fnames = ["name", "disk_usage", "be/memory", "be/vcpus", - "status", "pnode", "snodes", "tags"] + "status", "pnode", "snodes", "tags", "oper_ram"] fields = JSArray $ map (JSString . toJSString) fnames use_locking = JSBool False in JSArray [nnames, fields, use_locking] @@ -101,11 +101,13 @@ parseInstance :: [(String, Ndx)] -> JSValue -> Result (String, Instance.Instance) parseInstance ktn (JSArray [ name, disk, mem, vcpus - , status, pnode, snodes, tags ]) = do + , status, pnode, snodes, tags, oram ]) = do xname <- annotateResult "Parsing new instance" (fromJVal name) let convert v = annotateResult ("Instance '" ++ xname ++ "'") (fromJVal v) xdisk <- convert disk - xmem <- convert mem + xmem <- (case oram of + JSRational _ _ -> convert oram + _ -> convert mem) xvcpus <- convert vcpus xpnode <- convert pnode >>= lookupNode ktn xname xsnodes <- convert snodes::Result [JSString] @@ -131,10 +133,10 @@ parseNode (JSArray [ name, mtotal, mnode, mfree, dtotal, dfree xname <- annotateResult "Parsing new node" (fromJVal name) let convert v = annotateResult ("Node '" ++ xname ++ "'") (fromJVal v) xoffline <- convert offline - node <- (if xoffline + xdrained <- convert drained + node <- (if xoffline || xdrained then return $ Node.create xname 0 0 0 0 0 0 True else do - xdrained <- convert drained xmtotal <- convert mtotal xmnode <- convert mnode xmfree <- convert mfree @@ -142,7 +144,7 @@ parseNode (JSArray [ name, mtotal, mnode, mfree, dtotal, dfree xdfree <- convert dfree xctotal <- convert ctotal return $ Node.create xname xmtotal xmnode xmfree - xdtotal xdfree xctotal (xoffline || xdrained)) + xdtotal xdfree xctotal False) return (xname, node) parseNode v = fail ("Invalid node query result: " ++ show v) diff --git a/Ganeti/HTools/Rapi.hs b/Ganeti/HTools/Rapi.hs index 3f60699074b692bd58148ab47f1dd3af054979c4..623baeb5bc4d0a16114c07a6551b2270ebabef73 100644 --- a/Ganeti/HTools/Rapi.hs +++ b/Ganeti/HTools/Rapi.hs @@ -34,6 +34,7 @@ import Network.Curl.Code import Data.List import Control.Monad import Text.JSON (JSObject, JSValue, fromJSObject, decodeStrict) +import Text.JSON.Types (JSValue(..)) import Text.Printf (printf) import Ganeti.HTools.Utils @@ -78,10 +79,14 @@ parseInstance :: [(String, Ndx)] -> Result (String, Instance.Instance) parseInstance ktn a = do name <- tryFromObj "Parsing new instance" a "name" - let extract s x = tryFromObj ("Instance '" ++ name ++ "'") x s + let owner_name = "Instance '" ++ name ++ "'" + let extract s x = tryFromObj owner_name x s disk <- extract "disk_usage" a beparams <- liftM fromJSObject (extract "beparams" a) - mem <- extract "memory" beparams + omem <- extract "oper_ram" a + mem <- (case omem of + JSRational _ _ -> annotateResult owner_name (fromJVal omem) + _ -> extract "memory" beparams) vcpus <- extract "vcpus" beparams pnode <- extract "pnode" a >>= lookupNode ktn name snodes <- extract "snodes" a @@ -98,10 +103,10 @@ parseNode a = do name <- tryFromObj "Parsing new node" a "name" let extract s = tryFromObj ("Node '" ++ name ++ "'") a s offline <- extract "offline" - node <- (if offline + drained <- extract "drained" + node <- (if offline || drained then return $ Node.create name 0 0 0 0 0 0 True else do - drained <- extract "drained" mtotal <- extract "mtotal" mnode <- extract "mnode" mfree <- extract "mfree" @@ -109,7 +114,7 @@ parseNode a = do dfree <- extract "dfree" ctotal <- extract "ctotal" return $ Node.create name mtotal mnode mfree - dtotal dfree ctotal (offline || drained)) + dtotal dfree ctotal False) return (name, node) -- | Builds the cluster data from an URL.