From 1e4b5230c68db4ad62bfb316f4d53557ff5e9ed6 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sun, 15 Nov 2009 00:01:04 +0100
Subject: [PATCH] Node: add function for conflicting primary count

---
 Ganeti/HTools/Node.hs | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs
index 1216f1c9c..1e7edf3cd 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.
-- 
GitLab