Commit 8ce618f3 authored by Iustin Pop's avatar Iustin Pop
Browse files

Merge branch 'master' into next

* master:
  Use the oper_ram field if available
  rapi, luxi: treat drained nodes as offline
parents 673f0f00 6402a260
......@@ -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)
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment