Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / HTools / Program / Hail.hs @ 8b5a517a

History | View | Annotate | Download (2.2 kB)

1 525bfb36 Iustin Pop
{-| IAllocator plugin for Ganeti.
2 585d4420 Iustin Pop
3 585d4420 Iustin Pop
-}
4 585d4420 Iustin Pop
5 e2fa2baf Iustin Pop
{-
6 e2fa2baf Iustin Pop
7 4bc33d60 Iustin Pop
Copyright (C) 2009, 2010, 2011 Google Inc.
8 e2fa2baf Iustin Pop
9 e2fa2baf Iustin Pop
This program is free software; you can redistribute it and/or modify
10 e2fa2baf Iustin Pop
it under the terms of the GNU General Public License as published by
11 e2fa2baf Iustin Pop
the Free Software Foundation; either version 2 of the License, or
12 e2fa2baf Iustin Pop
(at your option) any later version.
13 e2fa2baf Iustin Pop
14 e2fa2baf Iustin Pop
This program is distributed in the hope that it will be useful, but
15 e2fa2baf Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
16 e2fa2baf Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 e2fa2baf Iustin Pop
General Public License for more details.
18 e2fa2baf Iustin Pop
19 e2fa2baf Iustin Pop
You should have received a copy of the GNU General Public License
20 e2fa2baf Iustin Pop
along with this program; if not, write to the Free Software
21 e2fa2baf Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 e2fa2baf Iustin Pop
02110-1301, USA.
23 e2fa2baf Iustin Pop
24 e2fa2baf Iustin Pop
-}
25 e2fa2baf Iustin Pop
26 458a286a Iustin Pop
module Ganeti.HTools.Program.Hail (main) where
27 585d4420 Iustin Pop
28 cc532bdd Iustin Pop
import Control.Monad
29 3603605a Iustin Pop
import Data.Maybe (fromMaybe)
30 7345b69b Iustin Pop
import System.Environment (getArgs)
31 585d4420 Iustin Pop
import System.IO
32 585d4420 Iustin Pop
33 585d4420 Iustin Pop
import qualified Ganeti.HTools.Cluster as Cluster
34 0427285d Iustin Pop
35 0427285d Iustin Pop
import Ganeti.HTools.CLI
36 585d4420 Iustin Pop
import Ganeti.HTools.IAlloc
37 cabce2f4 Iustin Pop
import Ganeti.HTools.Loader (Request(..), ClusterData(..))
38 4162995d Iustin Pop
import Ganeti.HTools.ExtLoader (maybeSaveData)
39 585d4420 Iustin Pop
40 179c0828 Iustin Pop
-- | Options list and functions.
41 0427285d Iustin Pop
options :: [OptType]
42 01fec0a1 Iustin Pop
options =
43 ebf38064 Iustin Pop
  [ oPrintNodes
44 ebf38064 Iustin Pop
  , oSaveCluster
45 ebf38064 Iustin Pop
  , oDataFile
46 ebf38064 Iustin Pop
  , oNodeSim
47 ebf38064 Iustin Pop
  , oVerbose
48 ebf38064 Iustin Pop
  , oShowVer
49 ebf38064 Iustin Pop
  , oShowHelp
50 ebf38064 Iustin Pop
  ]
51 f826c5e0 Iustin Pop
52 585d4420 Iustin Pop
-- | Main function.
53 585d4420 Iustin Pop
main :: IO ()
54 585d4420 Iustin Pop
main = do
55 7345b69b Iustin Pop
  cmd_args <- getArgs
56 f3d53161 Iustin Pop
  (opts, args) <- parseOpts cmd_args "hail" options
57 585d4420 Iustin Pop
58 01fec0a1 Iustin Pop
  let shownodes = optShowNodes opts
59 b790839a Iustin Pop
      verbose = optVerbose opts
60 4162995d Iustin Pop
      savecluster = optSaveCluster opts
61 585d4420 Iustin Pop
62 01fec0a1 Iustin Pop
  request <- readRequest opts args
63 585d4420 Iustin Pop
64 34c00528 Iustin Pop
  let Request rq cdata = request
65 f3d53161 Iustin Pop
66 b790839a Iustin Pop
  when (verbose > 1) $
67 b790839a Iustin Pop
       hPutStrLn stderr $ "Received request: " ++ show rq
68 b790839a Iustin Pop
69 b790839a Iustin Pop
  when (verbose > 2) $
70 b790839a Iustin Pop
       hPutStrLn stderr $ "Received cluster data: " ++ show cdata
71 b790839a Iustin Pop
72 15329af5 Iustin Pop
  maybePrintNodes shownodes "Initial cluster"
73 15329af5 Iustin Pop
       (Cluster.printNodes (cdNodes cdata))
74 f3d53161 Iustin Pop
75 4162995d Iustin Pop
  maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata
76 4162995d Iustin Pop
77 f9283686 Iustin Pop
  let (maybe_ni, resp) = runIAllocator request
78 3603605a Iustin Pop
      (fin_nl, fin_il) = fromMaybe (cdNodes cdata, cdInstances cdata) maybe_ni
79 ed41c179 Iustin Pop
  putStrLn resp
80 15329af5 Iustin Pop
81 15329af5 Iustin Pop
  maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl)
82 4162995d Iustin Pop
83 4162995d Iustin Pop
  maybeSaveData savecluster "post-ialloc" "after iallocator run"
84 4162995d Iustin Pop
       (cdata { cdNodes = fin_nl, cdInstances = fin_il})