Commit 6402a260 authored by Iustin Pop's avatar Iustin Pop
Browse files

Use the oper_ram field if available

For the RAPI and LUXI backends, we can get the actual memory usage (if
instances are running) via the oper_ram, whereas backend/memory only
tell what the instance will use at the next boot.

Not using oper_ram means that the node model is flawed and we consider
wrong values for the instance's memory (resulting sometimes in hilarious
values such as x_mem = -700 MB).
parent b45222ce
......@@ -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]
......
......@@ -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
......
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