Commit 5d1baf63 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add functions to check and fix cluster data

This patch adds a checkData function which goes over the node list and computes
the unaccounted memory, returning a list of warning messages (if any) and the
update nodes.
parent 8c5b0a0d
......@@ -32,6 +32,7 @@ module Ganeti.HTools.Cluster
, printStats
-- * Loading functions
, loadData
, checkData
) where
import Data.List
......@@ -776,3 +777,31 @@ loadData ndata idata =
sti = stripSuffix common_suffix xti
in
(nl3, il3, common_suffix, stn, sti)
-- | Compute the amount of memory used by primary instances on a node.
nodeImem :: Node.Node -> InstanceList -> Int
nodeImem node il =
let rfind = flip Container.find $ il
in sum . map Instance.mem .
map rfind $ Node.plist node
-- | Check cluster data for consistency
checkData :: NodeList -> InstanceList -> NameList -> NameList
-> ([String], NodeList)
checkData nl il ktn kti =
Container.mapAccum
(\ msgs node ->
let nname = fromJust $ lookup (Node.idx node) ktn
delta_mem = (truncate $ Node.t_mem node) -
(Node.n_mem node) -
(Node.f_mem node) -
(nodeImem node il)
newn = Node.setXmem node delta_mem
umsg = if delta_mem > 16
then (printf "node %s has %6d MB of unaccounted \
\memory "
nname delta_mem):msgs
else msgs
in (umsg, newn)
) [] nl
......@@ -20,6 +20,7 @@ module Ganeti.HTools.Container
, addTwo
, remove
, IntMap.map
, IntMap.mapAccum
-- * Conversion
, elems
, keys
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment