Revision ecc39665 htools/Ganeti/HTools/Program/Hcheck.hs

b/htools/Ganeti/HTools/Program/Hcheck.hs
233 233
      let (Cluster.Table fin_nl fin_il _ _) = fin_tbl
234 234
      return (gidx, (fin_nl, fin_il))
235 235

  
236
-- | Decide whether to simulate rebalance.
237
maybeSimulateRebalance :: Bool             -- ^ Whether to simulate rebalance
238
                       -> Options          -- ^ Command line options
239
                       -> [(Gdx, (Node.List, Instance.List))] -- ^ Group data
240
                       -> IO([(Gdx, (Node.List, Instance.List))])
241
maybeSimulateRebalance True opts cluster =
242
    mapM (simulateRebalance opts) cluster
243
maybeSimulateRebalance False _ cluster = return cluster
244

  
236 245
-- | Prints the final @OK@ marker in machine readable output.
237 246
printFinalHTC :: Bool -> IO ()
238 247
printFinalHTC = printFinal htcPrefix
......
264 273
  when nosimulation $ do
265 274
    unless (verbose == 0 || machineread) $
266 275
      printf "Running in no-simulation mode. Exiting.\n"
267
    printFinalHTC machineread
268
    exitWith ExitSuccess
269 276

  
270 277
  when (length splitinstances > 0) $ do
271 278
    unless (verbose == 0 || machineread) $
272 279
       printf "Split instances found, simulation of re-balancing not possible\n"
273
    exitWith $ ExitFailure 1
274 280

  
275 281
  unless needrebalance $ do
276 282
    unless (verbose == 0 || machineread) $
277 283
      printf "No need to rebalance cluster, no problems found. Exiting.\n"
278
    printFinalHTC machineread
279
    exitWith ExitSuccess
280 284

  
281
  rebalancedcluster <- mapM (simulateRebalance opts) splitcluster
282
  newgroupstats <- mapM (perGroupChecks verbose machineread Rebalanced gl)
285
  let exitOK = nosimulation || not needrebalance
286
      simulate = not nosimulation && length splitinstances == 0 && needrebalance
287

  
288
  rebalancedcluster <- maybeSimulateRebalance simulate opts splitcluster
289

  
290
  when (simulate || machineread) $ do
291
    newgroupstats <- mapM (perGroupChecks verbose machineread Rebalanced gl)
283 292
                     rebalancedcluster
284
  let newclusterstats = map sum (transpose newgroupstats) :: [Int]
285
  _ <- printClusterStats verbose machineread Rebalanced newclusterstats canrebalance
293
    -- We do not introduce new split instances during rebalance
294
    let newsplitinstances = splitinstances
295
        newclusterstats = map sum (transpose newgroupstats) :: [Int]
296
        newcanrebalance = length newsplitinstances == 0
297

  
298
    _ <- printClusterStats verbose machineread Rebalanced newclusterstats
299
                           newcanrebalance
300
    return ()
286 301

  
287 302
  printFinalHTC machineread
303

  
304
  unless exitOK $ exitWith $ ExitFailure 1

Also available in: Unified diff