Commit 63a78055 authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 97936d51
......@@ -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
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