On Fri, Jan 7, 2011 at 15:02, Iustin Pop <[email protected]> wrote:
> This allows non-vm_capable nodes, which don't export runtime data, to
> not break the IAllocator message parsing.
> ---
> Ganeti/HTools/IAlloc.hs | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs
> index 548e427..f4c9044 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,14 @@ 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_cap <- annotateResult desc $ maybeFromObj a "vm_capable"
> gidx <- lookupGroup ktg n guuid
> - node <- (if offline || drained
> + node <- (if offline || drained || not (fromMaybe True vm_cap)
>
Just a minor comment: I would give the "fromMaybe True vm_cap" expression a
name (say, "vm_capable") to make the condition a bit more readable.
then return $ Node.create n 0 0 0 0 0 0 True gidx
> else do
> mtotal <- extract "total_memory"
> --
> 1.7.3.1
>
>
LGTM as is.