hbal: Abort for invalid offline node names
authorIustin Pop <iustin@google.com>
Thu, 16 Apr 2009 09:02:48 +0000 (11:02 +0200)
committerIustin Pop <iustin@google.com>
Thu, 16 Apr 2009 09:02:48 +0000 (11:02 +0200)
Since it's easy to pass a wrong node name as offline, we should abort
instead of silently ignoring it.

Ganeti/HTools/Utils.hs
hbal.hs

index 81d5173..d1aa975 100644 (file)
@@ -10,6 +10,7 @@ module Ganeti.HTools.Utils
     , swapPairs
     , varianceCoeff
     , readData
+    , commaJoin
     ) where
 
 import Data.Either
diff --git a/hbal.hs b/hbal.hs
index e97b512..65c5e3f 100644 (file)
--- a/hbal.hs
+++ b/hbal.hs
@@ -160,9 +160,16 @@ main = do
          putStrLn . unlines . map (\s -> printf "  - %s" s) $ fix_msgs
 
   let offline_names = optOffline opts
+      all_names = snd . unzip $ ktn
+      offline_wrong = filter (\n -> not $ elem n all_names) offline_names
       offline_indices = fst . unzip .
                         filter (\(_, n) -> elem n offline_names) $ ktn
 
+  when (length offline_wrong > 0) $ do
+         printf "Wrong node name(s) set as offline: %s\n"
+                (commaJoin offline_wrong)
+         exitWith $ ExitFailure 1
+
   let nl = Container.map (\n -> if elem (Node.idx n) offline_indices
                                 then Node.setOffline n True
                                 else n) fixed_nl