From 5d1baf6306e49a6fc4c2bf3b8cf2b6e17e6b7902 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 22 Mar 2009 11:02:59 +0100 Subject: [PATCH] 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. --- Ganeti/HTools/Cluster.hs | 29 +++++++++++++++++++++++++++++ Ganeti/HTools/Container.hs | 1 + 2 files changed, 30 insertions(+) diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index 3dc52d264..6877f6c91 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -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 diff --git a/Ganeti/HTools/Container.hs b/Ganeti/HTools/Container.hs index c113193f3..09ab37ffc 100644 --- a/Ganeti/HTools/Container.hs +++ b/Ganeti/HTools/Container.hs @@ -20,6 +20,7 @@ module Ganeti.HTools.Container , addTwo , remove , IntMap.map + , IntMap.mapAccum -- * Conversion , elems , keys -- GitLab