From a5f8dcdc3e7cde3aaca40ef253f000c89c6140d7 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 21 Oct 2009 17:58:56 +0900
Subject: [PATCH] hbal: ignore unknown instance in dynload file

Since the utilisation file might be generated at a different time from
the hbal run, and instances could dissapear in the meantime, it's better
to simply ignore unknown instances rather than abort.
---
 Ganeti/HTools/Loader.hs | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs
index 2873688de..b737a46e8 100644
--- a/Ganeti/HTools/Loader.hs
+++ b/Ganeti/HTools/Loader.hs
@@ -37,7 +37,6 @@ module Ganeti.HTools.Loader
     , Request(..)
     ) where
 
-import Control.Monad (foldM)
 import Data.Function (on)
 import Data.List
 import Data.Maybe (fromJust)
@@ -138,11 +137,13 @@ mergeData :: [(String, DynUtil)]  -- ^ Instance utilisation data
           -> Result (Node.List, Instance.List, String)
 mergeData um (nl, il) = do
   let il2 = Container.fromAssocList il
-  il3 <- foldM (\im (name, n_util) -> do
-                  inst <- Container.findByName im name
-                  let new_i = inst { Instance.util = n_util }
-                  return $ Container.add (Instance.idx inst) new_i im
-               ) il2 um
+      il3 = foldl' (\im (name, n_util) ->
+                        case Container.findByName im name of
+                          Nothing -> im -- skipping unknown instance
+                          Just inst ->
+                              let new_i = inst { Instance.util = n_util }
+                              in Container.add (Instance.idx inst) new_i im
+                   ) il2 um
   let nl2 = foldl' fixNodes nl (Container.elems il3)
   let nl3 = Container.fromAssocList
             (map (\ (k, v) -> (k, Node.buildPeers v il3)) nl2)
-- 
GitLab