Revision 5d1baf63

b/Ganeti/HTools/Cluster.hs
32 32
    , printStats
33 33
    -- * Loading functions
34 34
    , loadData
35
    , checkData
35 36
    ) where
36 37

  
37 38
import Data.List
......
776 777
        sti = stripSuffix common_suffix xti
777 778
    in
778 779
      (nl3, il3, common_suffix, stn, sti)
780

  
781
-- | Compute the amount of memory used by primary instances on a node.
782
nodeImem :: Node.Node -> InstanceList -> Int
783
nodeImem node il =
784
    let rfind = flip Container.find $ il
785
    in sum . map Instance.mem .
786
       map rfind $ Node.plist node
787

  
788

  
789
-- | Check cluster data for consistency
790
checkData :: NodeList -> InstanceList -> NameList -> NameList
791
          -> ([String], NodeList)
792
checkData nl il ktn kti =
793
    Container.mapAccum
794
        (\ msgs node ->
795
             let nname = fromJust $ lookup (Node.idx node) ktn
796
                 delta_mem = (truncate $ Node.t_mem node) -
797
                             (Node.n_mem node) -
798
                             (Node.f_mem node) -
799
                             (nodeImem node il)
800
                 newn = Node.setXmem node delta_mem
801
                 umsg = if delta_mem > 16
802
                        then (printf "node %s has %6d MB of unaccounted \
803
                                     \memory "
804
                                     nname delta_mem):msgs
805
                        else msgs
806
             in (umsg, newn)
807
        ) [] nl
b/Ganeti/HTools/Container.hs
20 20
    , addTwo
21 21
    , remove
22 22
    , IntMap.map
23
    , IntMap.mapAccum
23 24
    -- * Conversion
24 25
    , elems
25 26
    , keys

Also available in: Unified diff