Commit 0eb83d70 authored by Bernardo Dal Seno's avatar Bernardo Dal Seno Committed by Jose A. Lopes
Browse files

Refactor reading live data in htools

This simplifies different handling of individual items.

Cherry-picked from 8c72f711

.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarThomas Thrainer <thomasth@google.com>
parent 9d7e8218
...@@ -130,20 +130,18 @@ parseNode ktg n a = do ...@@ -130,20 +130,18 @@ parseNode ktg n a = do
vm_capable <- annotateResult desc $ maybeFromObj a "vm_capable" vm_capable <- annotateResult desc $ maybeFromObj a "vm_capable"
let vm_capable' = fromMaybe True vm_capable let vm_capable' = fromMaybe True vm_capable
gidx <- lookupGroup ktg n guuid gidx <- lookupGroup ktg n guuid
node <- if offline || drained || not vm_capable' ndparams <- extract "ndparams" >>= asJSObject
then return $ Node.create n 0 0 0 0 0 0 True 0 gidx spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count"
else do let live = not offline && not drained && vm_capable'
mtotal <- extract "total_memory" lvextract def = eitherLive live def . extract
mnode <- extract "reserved_memory" mtotal <- lvextract 0.0 "total_memory"
mfree <- extract "free_memory" mnode <- lvextract 0 "reserved_memory"
dtotal <- extract "total_disk" mfree <- lvextract 0 "free_memory"
dfree <- extract "free_disk" dtotal <- lvextract 0.0 "total_disk"
ctotal <- extract "total_cpus" dfree <- lvextract 0 "free_disk"
ndparams <- extract "ndparams" >>= asJSObject ctotal <- lvextract 0.0 "total_cpus"
spindles <- tryFromObj desc (fromJSObject ndparams) let node = Node.create n mtotal mnode mfree dtotal dfree ctotal (not live)
"spindle_count" spindles gidx
return $ Node.create n mtotal mnode mfree
dtotal dfree ctotal False spindles gidx
return (n, node) return (n, node)
-- | Parses a group as found in the cluster group list. -- | Parses a group as found in the cluster group list.
......
...@@ -194,17 +194,16 @@ parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree ...@@ -194,17 +194,16 @@ parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
xvm_capable <- convert "vm_capable" vm_capable xvm_capable <- convert "vm_capable" vm_capable
xspindles <- convert "spindles" spindles xspindles <- convert "spindles" spindles
xgdx <- convert "group.uuid" g_uuid >>= lookupGroup ktg xname xgdx <- convert "group.uuid" g_uuid >>= lookupGroup ktg xname
node <- if xoffline || xdrained || not xvm_capable let live = not xoffline && not xdrained && xvm_capable
then return $ Node.create xname 0 0 0 0 0 0 True xspindles xgdx lvconvert def n d = eitherLive live def $ convert n d
else do xmtotal <- lvconvert 0.0 "mtotal" mtotal
xmtotal <- convert "mtotal" mtotal xmnode <- lvconvert 0 "mnode" mnode
xmnode <- convert "mnode" mnode xmfree <- lvconvert 0 "mfree" mfree
xmfree <- convert "mfree" mfree xdtotal <- lvconvert 0.0 "dtotal" dtotal
xdtotal <- convert "dtotal" dtotal xdfree <- lvconvert 0 "dfree" dfree
xdfree <- convert "dfree" dfree xctotal <- lvconvert 0.0 "ctotal" ctotal
xctotal <- convert "ctotal" ctotal let node = Node.create xname xmtotal xmnode xmfree xdtotal xdfree
return $ Node.create xname xmtotal xmnode xmfree xctotal (not live) xspindles xgdx
xdtotal xdfree xctotal False xspindles xgdx
return (xname, node) return (xname, node)
parseNode _ v = fail ("Invalid node query result: " ++ show v) parseNode _ v = fail ("Invalid node query result: " ++ show v)
......
...@@ -157,17 +157,16 @@ parseNode ktg a = do ...@@ -157,17 +157,16 @@ parseNode ktg a = do
spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count" spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count"
guuid <- annotateResult desc $ maybeFromObj a "group.uuid" guuid <- annotateResult desc $ maybeFromObj a "group.uuid"
guuid' <- lookupGroup ktg name (fromMaybe defaultGroupID guuid) guuid' <- lookupGroup ktg name (fromMaybe defaultGroupID guuid)
node <- if offline || drained || not vm_cap' let live = not offline && not drained && vm_cap'
then return $ Node.create name 0 0 0 0 0 0 True 0 guuid' lvextract def = eitherLive live def . extract
else do mtotal <- lvextract 0.0 "mtotal"
mtotal <- extract "mtotal" mnode <- lvextract 0 "mnode"
mnode <- extract "mnode" mfree <- lvextract 0 "mfree"
mfree <- extract "mfree" dtotal <- lvextract 0.0 "dtotal"
dtotal <- extract "dtotal" dfree <- lvextract 0 "dfree"
dfree <- extract "dfree" ctotal <- lvextract 0.0 "ctotal"
ctotal <- extract "ctotal" let node = Node.create name mtotal mnode mfree dtotal dfree ctotal (not live)
return $ Node.create name mtotal mnode mfree spindles guuid'
dtotal dfree ctotal False spindles guuid'
return (name, node) return (name, node)
-- | Construct a group from a JSON object. -- | Construct a group from a JSON object.
......
...@@ -34,6 +34,7 @@ module Ganeti.HTools.Loader ...@@ -34,6 +34,7 @@ module Ganeti.HTools.Loader
, lookupNode , lookupNode
, lookupInstance , lookupInstance
, lookupGroup , lookupGroup
, eitherLive
, commonSuffix , commonSuffix
, RqType(..) , RqType(..)
, Request(..) , Request(..)
...@@ -332,3 +333,8 @@ nodeIdsk node il = ...@@ -332,3 +333,8 @@ nodeIdsk node il =
let rfind = flip Container.find il let rfind = flip Container.find il
in sum . map (Instance.dsk . rfind) in sum . map (Instance.dsk . rfind)
$ Node.pList node ++ Node.sList node $ Node.pList node ++ Node.sList node
-- | Get live information or a default value
eitherLive :: (Monad m) => Bool -> a -> m a -> m a
eitherLive True _ live_data = live_data
eitherLive False def_data _ = return def_data
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