Currently memory_dom0 collected value is used for Xen and Kvm. In case
of Kvm collection is broken because the amount of memory used by
hypervisor includes the amount of memory used by instances as well.
Replace memory_dom0 with memory_node from hv_state parameter.

Signed-off-by: Oleg Ponomarev <[email protected]>
---
 src/Ganeti/HTools/Backend/Luxi.hs | 12 ++++++++----
 src/Ganeti/HTools/Loader.hs       | 15 +++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/Ganeti/HTools/Backend/Luxi.hs 
b/src/Ganeti/HTools/Backend/Luxi.hs
index 2e2447b..aeb3fe9 100644
--- a/src/Ganeti/HTools/Backend/Luxi.hs
+++ b/src/Ganeti/HTools/Backend/Luxi.hs
@@ -93,7 +93,8 @@ queryNodesMsg =
      ["name", "mtotal", "mnode", "mfree", "dtotal", "dfree",
       "ctotal", "cnos", "offline", "drained", "vm_capable",
       "ndp/spindle_count", "group.uuid", "tags",
-      "ndp/exclusive_storage", "sptotal", "spfree", "ndp/cpu_speed"]
+      "ndp/exclusive_storage", "sptotal", "spfree", "ndp/cpu_speed",
+      "hv_state"]
      Qlang.EmptyFilter
 
 -- | The input data for instance query.
@@ -183,7 +184,8 @@ getNodes ktg arr = L.extractArray arr >>= mapM (parseNode 
ktg)
 parseNode :: NameAssoc -> [(JSValue, JSValue)] -> Result (String, Node.Node)
 parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
               , ctotal, cnos, offline, drained, vm_capable, spindles, g_uuid
-              , tags, excl_stor, sptotal, spfree, cpu_speed ]
+              , tags, excl_stor, sptotal, spfree, cpu_speed, hv_state ]
+
     = do
   xname <- annotateResult "Parsing new node" (L.fromJValWithStatus name)
   let convert a = genericConvert "Node" xname a
@@ -214,9 +216,11 @@ parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
       -- is the only supported disk template
   xctotal <- lvconvert 0.0 "ctotal" ctotal
   xcnos <- lvconvert 0 "cnos" cnos
-  let node = flip Node.setCpuSpeed xcpu_speed .
+  xhv_state <- convert "hv_state" hv_state
+  let node_mem = obtainNodeMemory xhv_state xmnode
+      node = flip Node.setCpuSpeed xcpu_speed .
              flip Node.setNodeTags xtags $
-             Node.create xname xmtotal xmnode xmfree xdtotal xdfree
+             Node.create xname xmtotal node_mem xmfree xdtotal xdfree
              xctotal xcnos (not live || xdrained) xsptotal xspfree
              xgdx xexcl_stor
   return (xname, node)
diff --git a/src/Ganeti/HTools/Loader.hs b/src/Ganeti/HTools/Loader.hs
index 21848c3..6f396ab 100644
--- a/src/Ganeti/HTools/Loader.hs
+++ b/src/Ganeti/HTools/Loader.hs
@@ -53,6 +53,7 @@ module Ganeti.HTools.Loader
   , ClusterData(..)
   , isAllocationRequest
   , emptyCluster
+  , obtainNodeMemory
   ) where
 
 import Control.Monad
@@ -74,8 +75,11 @@ import Ganeti.BasicTypes
 import qualified Ganeti.HTools.Tags as Tags
 import qualified Ganeti.HTools.Tags.Constants as TagsC
 import Ganeti.HTools.Types
+import qualified Ganeti.Types as T
+import qualified Ganeti.Objects as O
 import Ganeti.Utils
 import Ganeti.Types (EvacMode)
+import Ganeti.JSON
 
 -- * Types
 
@@ -415,3 +419,14 @@ nodeIdsk node il =
 eitherLive :: (Monad m) => Bool -> a -> m a -> m a
 eitherLive True _ live_data = live_data
 eitherLive False def_data _ = return def_data
+
+-- | Obtains memory used by node. It's memory_dom0 for Xen and memNode
+-- otherwise because live data collector exists only for Xen
+obtainNodeMemory :: O.FilledHvState -> Int -> Int
+obtainNodeMemory hv_state memory_dom0 =
+  let getNM ((_, hvs):_) 0 = O.hvstateMemNode hvs
+      getNM ((T.XenPvm, _):_) mem_dom0 = mem_dom0
+      getNM ((T.XenHvm, _):_) mem_dom0 = mem_dom0
+      getNM ((_, hvs):_) _ = O.hvstateMemNode hvs
+      getNM _ mem_dom0 = mem_dom0
+  in getNM (M.toList $ fromContainer hv_state) memory_dom0
-- 
2.6.0.rc2.230.g3dd15c0

Reply via email to