From 63a7805527762da35403ace922230bc7bb3376c3 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 4 Jul 2011 23:41:52 +0200 Subject: [PATCH] htools: add a function for computing evacuated nodes The new IAllocator interface is based on instances, not nodes, so we need to backtrack and compute on which nodes we can't allocate instances during the current operation. This patch adds a function for computing this node set. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- htools/Ganeti/HTools/Cluster.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs index 901c981c9..1cc61174e 100644 --- a/htools/Ganeti/HTools/Cluster.hs +++ b/htools/Ganeti/HTools/Cluster.hs @@ -74,6 +74,7 @@ module Ganeti.HTools.Cluster ) where import Data.Function (on) +import qualified Data.IntSet as IntSet import Data.List import Data.Ord (comparing) import Text.Printf (printf) @@ -1103,3 +1104,25 @@ associateIdxs :: [Idx] -- ^ Instance indices to be split/associated associateIdxs idxs = map (\(gdx, (nl, il)) -> (gdx, (nl, il, filter (`Container.member` il) idxs))) + +-- | Compute the list of nodes that are to be evacuated, given a list +-- of instances and an evacuation mode. +nodesToEvacuate :: Instance.List -- ^ The cluster-wide instance list + -> EvacMode -- ^ The evacuation mode we're using + -> [Idx] -- ^ List of instance indices being evacuated + -> IntSet.IntSet -- ^ Set of node indices +nodesToEvacuate il mode = + IntSet.delete Node.noSecondary . + foldl' (\ns idx -> + let i = Container.find idx il + pdx = Instance.pNode i + sdx = Instance.sNode i + dt = Instance.diskTemplate i + withSecondary = case dt of + DTDrbd8 -> IntSet.insert sdx ns + _ -> ns + in case mode of + ChangePrimary -> IntSet.insert pdx ns + ChangeSecondary -> withSecondary + ChangeAll -> IntSet.insert pdx withSecondary + ) IntSet.empty -- GitLab