diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs index 1216f1c9c5a1cd30c4bdaeebb651f8f876bdb31d..1e7edf3cd0fb39e40583d5716844a9be63bd1076 100644 --- a/Ganeti/HTools/Node.hs +++ b/Ganeti/HTools/Node.hs @@ -48,6 +48,7 @@ module Ganeti.HTools.Node , addSec -- * Stats , availDisk + , conflictingPrimaries -- * Formatting , defaultFields , showHeader @@ -60,6 +61,7 @@ module Ganeti.HTools.Node import Data.List import qualified Data.Map as Map +import qualified Data.Foldable as Foldable import Text.Printf (printf) import qualified Ganeti.HTools.Container as Container @@ -158,6 +160,14 @@ delTags = foldl' delTag rejectAddTags :: TagMap -> [String] -> Bool rejectAddTags t = any (flip Map.member t) +-- | Check how many primary instances have conflicting tags. The +-- algorithm to compute this is to sum the count of all tags, then +-- subtract the size of the tag map (since each tag has at least one, +-- non-conflicting instance); this is equivalent to summing the +-- values in the tag map minus one. +conflictingPrimaries :: Node -> Int +conflictingPrimaries (Node { pTags = t }) = Foldable.sum t - Map.size t + -- * Initialization functions -- | Create a new node.