From 142538ff842f8c4a667e391474a4d8050f0fc20a Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 13 Mar 2009 20:11:12 +0100 Subject: [PATCH] Enhance the command list for the solution This patch moves the formatting of the command list to Cluster.hs and enhances it with separator messages between the steps. --- src/Cluster.hs | 8 ++++++++ src/hbal.hs | 3 +-- src/hn1.hs | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Cluster.hs b/src/Cluster.hs index 0247e6a55..84944917f 100644 --- a/src/Cluster.hs +++ b/src/Cluster.hs @@ -23,6 +23,7 @@ module Cluster , applySolution , printSolution , printSolutionLine + , formatCmds , printNodes -- * Balacing functions , checkMove @@ -569,6 +570,13 @@ printSolutionLine il ktn kti nmlen imlen plc = pmlen nstr c moves, cmds) +formatCmds :: [[String]] -> String +formatCmds cmd_strs = + unlines $ map (" echo " ++) $ + concat $ map (\(a, b) -> + (printf "step %d" (a::Int)):(map ("gnt-instance" ++) b)) $ + zip [1..] cmd_strs + {-| Converts a solution to string format -} printSolution :: InstanceList -> [(Int, String)] diff --git a/src/hbal.hs b/src/hbal.hs index 352fbb4b7..06d85c534 100644 --- a/src/hbal.hs +++ b/src/hbal.hs @@ -185,8 +185,7 @@ main = do do putStrLn "" putStrLn "Commands to run to reach the above solution:" - putStr $ unlines $ map (" echo gnt-instance " ++) - $ concat $ reverse cmd_strs + putStr . Cluster.formatCmds . reverse $ cmd_strs when (optShowNodes opts) $ do let (orig_mem, orig_disk) = Cluster.totalResources nl diff --git a/src/hn1.hs b/src/hn1.hs index cb8439247..5506e8aa0 100644 --- a/src/hn1.hs +++ b/src/hn1.hs @@ -187,7 +187,8 @@ main = do do putStrLn "" putStrLn "Commands to run to reach the above solution:" - putStr $ unlines $ map (" echo gnt-instance " ++) $ concat cmd_strs + putStr . Cluster.formatCmds . reverse $ cmd_strs + when (optShowNodes opts) $ do let (orig_mem, orig_disk) = Cluster.totalResources nl -- GitLab