From 3eeea90f3f773216fe7f0ee8d04748de50322818 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 7 Jan 2011 14:45:53 +0100
Subject: [PATCH] IAllocator: read and use the vm_capable node flag

This allows non-vm_capable nodes, which don't export runtime data, to
not break the IAllocator message parsing.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Balazs Lecz <leczb@google.com>
---
 Ganeti/HTools/IAlloc.hs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs
index 548e42780..4812b8e31 100644
--- a/Ganeti/HTools/IAlloc.hs
+++ b/Ganeti/HTools/IAlloc.hs
@@ -29,6 +29,7 @@ module Ganeti.HTools.IAlloc
     ) where
 
 import Data.Either ()
+import Data.Maybe (fromMaybe)
 import Control.Monad
 import Text.JSON (JSObject, JSValue(JSBool, JSString, JSArray),
                   makeObj, encodeStrict, decodeStrict,
@@ -81,12 +82,15 @@ parseNode :: NameAssoc           -- ^ The group association
           -> [(String, JSValue)] -- ^ The JSON object
           -> Result (String, Node.Node)
 parseNode ktg n a = do
-  let extract x = tryFromObj ("invalid data for node '" ++ n ++ "'") a x
+  let desc = "invalid data for node '" ++ n ++ "'"
+      extract x = tryFromObj desc a x
   offline <- extract "offline"
   drained <- extract "drained"
   guuid   <- extract "group"
+  vm_capable  <- annotateResult desc $ maybeFromObj a "vm_capable"
+  let vm_capable' = fromMaybe True vm_capable
   gidx <- lookupGroup ktg n guuid
-  node <- (if offline || drained
+  node <- (if offline || drained || not vm_capable'
            then return $ Node.create n 0 0 0 0 0 0 True gidx
            else do
              mtotal <- extract "total_memory"
-- 
GitLab