From 2d1708e033820a32ff46a6a450ffaf5d30ae2dbd Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Fri, 10 Jun 2011 14:45:09 +0100
Subject: [PATCH] Add instance selection list to Loader.mergeData

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 htools/Ganeti/HTools/ExtLoader.hs | 3 ++-
 htools/Ganeti/HTools/IAlloc.hs    | 2 +-
 htools/Ganeti/HTools/Loader.hs    | 5 +++--
 htools/Ganeti/HTools/QC.hs        | 2 +-
 htools/hscan.hs                   | 2 +-
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/htools/Ganeti/HTools/ExtLoader.hs b/htools/Ganeti/HTools/ExtLoader.hs
index 3374de6c9..0db8956c5 100644
--- a/htools/Ganeti/HTools/ExtLoader.hs
+++ b/htools/Ganeti/HTools/ExtLoader.hs
@@ -85,6 +85,7 @@ loadExternalData opts = do
       exTags = case optExTags opts of
                  Nothing -> []
                  Just etl -> map (++ ":") etl
+      selInsts = optSelInst opts
       exInsts = optExInst opts
 
   when (length allSet > 1) $
@@ -111,7 +112,7 @@ loadExternalData opts = do
           | setFile -> wrapIO $ Text.loadData $ fromJust tfile
           | otherwise -> return $ Bad "No backend selected! Exiting."
 
-  let ldresult = input_data >>= mergeData util_data' exTags exInsts
+  let ldresult = input_data >>= mergeData util_data' exTags selInsts exInsts
   cdata <-
       (case ldresult of
          Ok x -> return x
diff --git a/htools/Ganeti/HTools/IAlloc.hs b/htools/Ganeti/HTools/IAlloc.hs
index f06d984a0..f224f1188 100644
--- a/htools/Ganeti/HTools/IAlloc.hs
+++ b/htools/Ganeti/HTools/IAlloc.hs
@@ -148,7 +148,7 @@ parseData body = do
   let (kti, il) = assignIndices iobj
   -- cluster tags
   ctags <- extrObj "cluster_tags"
-  cdata <- mergeData [] [] [] (ClusterData gl nl il ctags)
+  cdata <- mergeData [] [] [] [] (ClusterData gl nl il ctags)
   let map_n = cdNodes cdata
       map_i = cdInstances cdata
       map_g = cdGroups cdata
diff --git a/htools/Ganeti/HTools/Loader.hs b/htools/Ganeti/HTools/Loader.hs
index b53d79ced..427287043 100644
--- a/htools/Ganeti/HTools/Loader.hs
+++ b/htools/Ganeti/HTools/Loader.hs
@@ -190,10 +190,11 @@ commonSuffix nl il =
 -- list and massages it into the correct format.
 mergeData :: [(String, DynUtil)]  -- ^ Instance utilisation data
           -> [String]             -- ^ Exclusion tags
-          -> [String]             -- ^ Untouchable instances
+          -> [String]             -- ^ Selected instances (if not empty)
+          -> [String]             -- ^ Excluded instances
           -> ClusterData          -- ^ Data from backends
           -> Result ClusterData   -- ^ Fixed cluster data
-mergeData um extags exinsts cdata@(ClusterData _ nl il2 tags) =
+mergeData um extags selinsts exinsts cdata@(ClusterData _ nl il2 tags) =
   let il = Container.elems il2
       il3 = foldl' (\im (name, n_util) ->
                         case Container.findByName im name of
diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index 66cf22936..9b130bceb 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -906,7 +906,7 @@ prop_Loader_assignIndices nodes =
 -- is zero
 prop_Loader_mergeData ns =
   let na = Container.fromList $ map (\n -> (Node.idx n, n)) ns
-  in case Loader.mergeData [] [] []
+  in case Loader.mergeData [] [] [] []
          (Loader.emptyCluster {Loader.cdNodes = na}) of
     Types.Bad _ -> False
     Types.Ok (Loader.ClusterData _ nl il _) ->
diff --git a/htools/hscan.hs b/htools/hscan.hs
index 07ab65757..e057972d3 100644
--- a/htools/hscan.hs
+++ b/htools/hscan.hs
@@ -87,7 +87,7 @@ fixSlash = map (\x -> if x == '/' then '_' else x)
 -- | Generates serialized data from loader input.
 processData :: ClusterData -> Result ClusterData
 processData input_data = do
-  cdata@(ClusterData _ nl il _) <- mergeData [] [] [] input_data
+  cdata@(ClusterData _ nl il _) <- mergeData [] [] [] [] input_data
   let (_, fix_nl) = checkData nl il
   return cdata { cdNodes = fix_nl }
 
-- 
GitLab