From 4162995d96e95daa23dd53992deb5b25933fa84d Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 7 Jul 2011 19:09:12 +0200
Subject: [PATCH] htools: add cluster state saving support to hail

This add support for saving the cluster state (both pre- and
post-iallocator run) to a text file such that it can be fed back into
any of the htools commands.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 htools/hail.hs | 8 ++++++++
 man/hail.rst   | 6 ++++++
 2 files changed, 14 insertions(+)

diff --git a/htools/hail.hs b/htools/hail.hs
index 9e2e3c2e5..59bd20705 100644
--- a/htools/hail.hs
+++ b/htools/hail.hs
@@ -35,11 +35,13 @@ import qualified Ganeti.HTools.Cluster as Cluster
 import Ganeti.HTools.CLI
 import Ganeti.HTools.IAlloc
 import Ganeti.HTools.Loader (Request(..), ClusterData(..))
+import Ganeti.HTools.ExtLoader (maybeSaveData)
 
 -- | Options list and functions
 options :: [OptType]
 options =
     [ oPrintNodes
+    , oSaveCluster
     , oDataFile
     , oNodeSim
     , oVerbose
@@ -55,6 +57,7 @@ main = do
 
   let shownodes = optShowNodes opts
       verbose = optVerbose opts
+      savecluster = optSaveCluster opts
 
   request <- readRequest opts args
 
@@ -71,9 +74,14 @@ main = do
          hPutStrLn stderr $ Cluster.printNodes (cdNodes cdata)
                        (fromJust shownodes)
 
+  maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata
+
   let (maybe_ni, resp) = runIAllocator request
       (fin_nl, fin_il) = maybe (cdNodes cdata, cdInstances cdata) id maybe_ni
   putStrLn resp
   when (isJust shownodes) $ do
          hPutStrLn stderr "Final cluster status:"
          hPutStrLn stderr $ Cluster.printNodes fin_nl (fromJust shownodes)
+
+  maybeSaveData savecluster "post-ialloc" "after iallocator run"
+       (cdata { cdNodes = fin_nl, cdInstances = fin_il})
diff --git a/man/hail.rst b/man/hail.rst
index 33b2787e1..23b12e58f 100644
--- a/man/hail.rst
+++ b/man/hail.rst
@@ -68,6 +68,12 @@ The options that can be passed to the program are as follows:
   data with a simulated cluster. For details about the description,
   see the man page **hspace**(1).
 
+-S *filename*, --save-cluster=*filename*
+  If given, the state of the cluster before and the iallocator run is
+  saved to a file named *filename.pre-ialloc*, respectively
+  *filename.post-ialloc*. This allows re-feeding the cluster state to
+  any of the htools utilities.
+
 -v
   This option increases verbosity and can be used for debugging in order
   to understand how the IAllocator request is parsed; it can be passed
-- 
GitLab