LGTM, thanks.
On Fri, Nov 29, 2013 at 9:30 AM, Jose A. Lopes <[email protected]> wrote: > From: Bernardo Dal Seno <[email protected]> > > This simplifies different handling of individual items. > > Cherry-picked from 8c72f7119f50a11661aacba2a1abffdfdc6f7cfa. > > Signed-off-by: Bernardo Dal Seno <[email protected]> > Reviewed-by: Klaus Aehlig <[email protected]> > Signed-off-by: Jose A. Lopes <[email protected]> > --- > src/Ganeti/HTools/Backend/IAlloc.hs | 26 ++++++++++++-------------- > src/Ganeti/HTools/Backend/Luxi.hs | 21 ++++++++++----------- > src/Ganeti/HTools/Backend/Rapi.hs | 21 ++++++++++----------- > src/Ganeti/HTools/Loader.hs | 6 ++++++ > 4 files changed, 38 insertions(+), 36 deletions(-) > > diff --git a/src/Ganeti/HTools/Backend/IAlloc.hs > b/src/Ganeti/HTools/Backend/IAlloc.hs > index 22dad86..c421b5f 100644 > --- a/src/Ganeti/HTools/Backend/IAlloc.hs > +++ b/src/Ganeti/HTools/Backend/IAlloc.hs > @@ -130,20 +130,18 @@ parseNode ktg n a = do > vm_capable <- annotateResult desc $ maybeFromObj a "vm_capable" > let vm_capable' = fromMaybe True vm_capable > gidx <- lookupGroup ktg n guuid > - node <- if offline || drained || not vm_capable' > - then return $ Node.create n 0 0 0 0 0 0 True 0 gidx > - else do > - mtotal <- extract "total_memory" > - mnode <- extract "reserved_memory" > - mfree <- extract "free_memory" > - dtotal <- extract "total_disk" > - dfree <- extract "free_disk" > - ctotal <- extract "total_cpus" > - ndparams <- extract "ndparams" >>= asJSObject > - spindles <- tryFromObj desc (fromJSObject ndparams) > - "spindle_count" > - return $ Node.create n mtotal mnode mfree > - dtotal dfree ctotal False spindles gidx > + ndparams <- extract "ndparams" >>= asJSObject > + spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count" > + let live = not offline && not drained && vm_capable' > + lvextract def = eitherLive live def . extract > + mtotal <- lvextract 0.0 "total_memory" > + mnode <- lvextract 0 "reserved_memory" > + mfree <- lvextract 0 "free_memory" > + dtotal <- lvextract 0.0 "total_disk" > + dfree <- lvextract 0 "free_disk" > + ctotal <- lvextract 0.0 "total_cpus" > + let node = Node.create n mtotal mnode mfree dtotal dfree ctotal (not > live) > + spindles gidx > return (n, node) > > -- | Parses a group as found in the cluster group list. > diff --git a/src/Ganeti/HTools/Backend/Luxi.hs > b/src/Ganeti/HTools/Backend/Luxi.hs > index 71ef347..728054e 100644 > --- a/src/Ganeti/HTools/Backend/Luxi.hs > +++ b/src/Ganeti/HTools/Backend/Luxi.hs > @@ -194,17 +194,16 @@ parseNode ktg [ name, mtotal, mnode, mfree, dtotal, > dfree > xvm_capable <- convert "vm_capable" vm_capable > xspindles <- convert "spindles" spindles > xgdx <- convert "group.uuid" g_uuid >>= lookupGroup ktg xname > - node <- if xoffline || xdrained || not xvm_capable > - then return $ Node.create xname 0 0 0 0 0 0 True xspindles > xgdx > - else do > - xmtotal <- convert "mtotal" mtotal > - xmnode <- convert "mnode" mnode > - xmfree <- convert "mfree" mfree > - xdtotal <- convert "dtotal" dtotal > - xdfree <- convert "dfree" dfree > - xctotal <- convert "ctotal" ctotal > - return $ Node.create xname xmtotal xmnode xmfree > - xdtotal xdfree xctotal False xspindles xgdx > + let live = not xoffline && not xdrained && xvm_capable > + lvconvert def n d = eitherLive live def $ convert n d > + xmtotal <- lvconvert 0.0 "mtotal" mtotal > + xmnode <- lvconvert 0 "mnode" mnode > + xmfree <- lvconvert 0 "mfree" mfree > + xdtotal <- lvconvert 0.0 "dtotal" dtotal > + xdfree <- lvconvert 0 "dfree" dfree > + xctotal <- lvconvert 0.0 "ctotal" ctotal > + let node = Node.create xname xmtotal xmnode xmfree xdtotal xdfree > + xctotal (not live) xspindles xgdx > return (xname, node) > > parseNode _ v = fail ("Invalid node query result: " ++ show v) > diff --git a/src/Ganeti/HTools/Backend/Rapi.hs > b/src/Ganeti/HTools/Backend/Rapi.hs > index 0672e70..d078a79 100644 > --- a/src/Ganeti/HTools/Backend/Rapi.hs > +++ b/src/Ganeti/HTools/Backend/Rapi.hs > @@ -157,17 +157,16 @@ parseNode ktg a = do > spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count" > guuid <- annotateResult desc $ maybeFromObj a "group.uuid" > guuid' <- lookupGroup ktg name (fromMaybe defaultGroupID guuid) > - node <- if offline || drained || not vm_cap' > - then return $ Node.create name 0 0 0 0 0 0 True 0 guuid' > - else do > - mtotal <- extract "mtotal" > - mnode <- extract "mnode" > - mfree <- extract "mfree" > - dtotal <- extract "dtotal" > - dfree <- extract "dfree" > - ctotal <- extract "ctotal" > - return $ Node.create name mtotal mnode mfree > - dtotal dfree ctotal False spindles guuid' > + let live = not offline && not drained && vm_cap' > + lvextract def = eitherLive live def . extract > + mtotal <- lvextract 0.0 "mtotal" > + mnode <- lvextract 0 "mnode" > + mfree <- lvextract 0 "mfree" > + dtotal <- lvextract 0.0 "dtotal" > + dfree <- lvextract 0 "dfree" > + ctotal <- lvextract 0.0 "ctotal" > + let node = Node.create name mtotal mnode mfree dtotal dfree ctotal (not > live) > + spindles guuid' > return (name, node) > > -- | Construct a group from a JSON object. > diff --git a/src/Ganeti/HTools/Loader.hs b/src/Ganeti/HTools/Loader.hs > index 49109ab..07c7de7 100644 > --- a/src/Ganeti/HTools/Loader.hs > +++ b/src/Ganeti/HTools/Loader.hs > @@ -34,6 +34,7 @@ module Ganeti.HTools.Loader > , lookupNode > , lookupInstance > , lookupGroup > + , eitherLive > , commonSuffix > , RqType(..) > , Request(..) > @@ -332,3 +333,8 @@ nodeIdsk node il = > let rfind = flip Container.find il > in sum . map (Instance.dsk . rfind) > $ Node.pList node ++ Node.sList node > + > +-- | Get live information or a default value > +eitherLive :: (Monad m) => Bool -> a -> m a -> m a > +eitherLive True _ live_data = live_data > +eitherLive False def_data _ = return def_data > -- > 1.8.4.1 > > -- Thomas Thrainer | Software Engineer | [email protected] | Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
