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]>
---
 lib/masterd/iallocator.py                     | 1 +
 src/Ganeti/HTools/Backend/IAlloc.hs           | 5 ++++-
 test/py/ganeti.masterd.iallocator_unittest.py | 3 +++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/masterd/iallocator.py b/lib/masterd/iallocator.py
index 547c939..d8b36ea 100644
--- a/lib/masterd/iallocator.py
+++ b/lib/masterd/iallocator.py
@@ -572,6 +572,7 @@ class IAllocator(object):
       "master_capable": ninfo.master_capable,
       "vm_capable": ninfo.vm_capable,
       "ndparams": cfg.GetNdParams(ninfo),
+      "hv_state": cfg.GetFilledHvStateParams(ninfo)
       })
       for ninfo in node_cfg.values())
 
diff --git a/src/Ganeti/HTools/Backend/IAlloc.hs 
b/src/Ganeti/HTools/Backend/IAlloc.hs
index d704950..5946efe 100644
--- a/src/Ganeti/HTools/Backend/IAlloc.hs
+++ b/src/Ganeti/HTools/Backend/IAlloc.hs
@@ -147,9 +147,11 @@ parseNode :: NameAssoc   -- ^ The group association
 parseNode ktg n a = do
   let desc = "invalid data for node '" ++ n ++ "'"
       extract x = tryFromObj desc a x
+      extractDef def key = fromObjWithDefault a key def
   offline <- extract "offline"
   drained <- extract "drained"
   guuid   <- extract "group"
+  hvstate   <- extractDef emptyContainer "hv_state"
   vm_capable  <- annotateResult desc $ maybeFromObj a "vm_capable"
   let vm_capable' = fromMaybe True vm_capable
   gidx <- lookupGroup ktg n guuid
@@ -168,7 +170,8 @@ parseNode ktg n a = do
   dfree  <- lvextract 0 "free_disk"
   ctotal <- lvextract 0.0 "total_cpus"
   cnos <- lvextract 0 "reserved_cpus"
-  let node = Node.create n mtotal mnode mfree dtotal dfree ctotal cnos
+  let node_mem = obtainNodeMemory hvstate mnode
+      node = Node.create n mtotal node_mem mfree dtotal dfree ctotal cnos
              (not live || drained) sptotal spfree gidx excl_stor
   return (n, node)
 
diff --git a/test/py/ganeti.masterd.iallocator_unittest.py 
b/test/py/ganeti.masterd.iallocator_unittest.py
index bf4d2b2..5fb18a8 100755
--- a/test/py/ganeti.masterd.iallocator_unittest.py
+++ b/test/py/ganeti.masterd.iallocator_unittest.py
@@ -114,6 +114,7 @@ class TestComputeBasicNodeData(unittest.TestCase):
     self.assertEqual(self.fn({}), {})
 
   def testSimple(self):
+    self.maxDiff = None
     node1 = objects.Node(name="node1",
                          primary_ip="192.0.2.1",
                          secondary_ip="192.0.2.2",
@@ -153,6 +154,7 @@ class TestComputeBasicNodeData(unittest.TestCase):
         "master_capable": True,
         "vm_capable": False,
         "ndparams": None,
+        "hv_state": None,
         },
       "node2": {
         "tags": [],
@@ -165,6 +167,7 @@ class TestComputeBasicNodeData(unittest.TestCase):
         "master_capable": False,
         "vm_capable": True,
         "ndparams": None,
+        "hv_state": None,
         },
       })
 
-- 
2.6.0.rc2.230.g3dd15c0

Reply via email to