From 748654f72ad41d8c2b93e7c88ff0a3060e8cfc55 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 26 Aug 2010 11:49:19 +0200
Subject: [PATCH] Implement cluster state saving in hbal

Also move the LUXI execution (-X) to the end, after all the output
messages are printed. No good in waiting for the messages for a long
while, especially as they are not up-to-date stats after the job
execution, just an estimation of what the state will be.
---
 hbal.hs | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/hbal.hs b/hbal.hs
index 55f428d42..88c64dd93 100644
--- a/hbal.hs
+++ b/hbal.hs
@@ -4,7 +4,7 @@
 
 {-
 
-Copyright (C) 2009 Google Inc.
+Copyright (C) 2009, 2010 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -46,6 +46,8 @@ import Ganeti.HTools.ExtLoader
 import Ganeti.HTools.Utils
 import Ganeti.HTools.Types
 
+import Ganeti.HTools.Text (serializeCluster)
+
 import qualified Ganeti.Luxi as L
 import Ganeti.Jobs
 
@@ -72,6 +74,7 @@ options =
     , oDynuFile
     , oExTags
     , oExInst
+    , oSaveCluster
     , oShowVer
     , oShowHelp
     ]
@@ -303,12 +306,12 @@ main = do
             writeFile out_path (shTemplate ++ cmd_data)
             printf "The commands have been written to file '%s'\n" out_path)
 
-  when (optExecJobs opts && not (null ord_plc))
-           (case optLuxi opts of
-              Nothing -> do
-                hPutStrLn stderr "Execution of commands possible only on LUXI"
-                exitWith $ ExitFailure 1
-              Just master -> execJobSet master fin_nl il cmd_jobs)
+  when (isJust $ optSaveCluster opts) $
+       do
+         let out_path = fromJust $ optSaveCluster opts
+             adata = serializeCluster fin_nl fin_il
+         writeFile out_path adata
+         printf "The cluster state has been written to file '%s'\n" out_path
 
   when (optShowInsts opts) $ do
          putStrLn ""
@@ -330,3 +333,10 @@ main = do
                        (Cluster.csFmem fin_cs) (Cluster.csFdsk fin_cs)
   when oneline $
          putStrLn $ formatOneline ini_cv (length ord_plc) fin_cv
+
+  when (optExecJobs opts && not (null ord_plc))
+           (case optLuxi opts of
+              Nothing -> do
+                hPutStrLn stderr "Execution of commands possible only on LUXI"
+                exitWith $ ExitFailure 1
+              Just master -> execJobSet master fin_nl il cmd_jobs)
-- 
GitLab