On Mon, Jan 10, 2011 at 12:53:54PM +0000, Balazs Lecz wrote:
> 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.

Hah, I tried to make this fit in a single expression, but didn't
manage. Didn't think about two different variables :)

Will do, thanks.

iustin

Reply via email to