Statistics
| Branch: | Tag: | Revision:

root / htools / hail.hs @ a86fbf36

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 585d4420 Iustin Pop
module Main (main) where
27 585d4420 Iustin Pop
28 cc532bdd Iustin Pop
import Control.Monad
29 585d4420 Iustin Pop
import System.IO
30 585d4420 Iustin Pop
import qualified System
31 585d4420 Iustin Pop
32 585d4420 Iustin Pop
import qualified Ganeti.HTools.Cluster as Cluster
33 0427285d Iustin Pop
34 0427285d Iustin Pop
import Ganeti.HTools.CLI
35 585d4420 Iustin Pop
import Ganeti.HTools.IAlloc
36 cabce2f4 Iustin Pop
import Ganeti.HTools.Loader (Request(..), ClusterData(..))
37 4162995d Iustin Pop
import Ganeti.HTools.ExtLoader (maybeSaveData)
38 585d4420 Iustin Pop
39 585d4420 Iustin Pop
-- | Options list and functions
40 0427285d Iustin Pop
options :: [OptType]
41 01fec0a1 Iustin Pop
options =
42 01fec0a1 Iustin Pop
    [ oPrintNodes
43 4162995d Iustin Pop
    , oSaveCluster
44 01fec0a1 Iustin Pop
    , oDataFile
45 01fec0a1 Iustin Pop
    , oNodeSim
46 b790839a Iustin Pop
    , oVerbose
47 01fec0a1 Iustin Pop
    , oShowVer
48 01fec0a1 Iustin Pop
    , oShowHelp
49 01fec0a1 Iustin Pop
    ]
50 f826c5e0 Iustin Pop
51 585d4420 Iustin Pop
-- | Main function.
52 585d4420 Iustin Pop
main :: IO ()
53 585d4420 Iustin Pop
main = do
54 585d4420 Iustin Pop
  cmd_args <- System.getArgs
55 f3d53161 Iustin Pop
  (opts, args) <- parseOpts cmd_args "hail" options
56 585d4420 Iustin Pop
57 01fec0a1 Iustin Pop
  let shownodes = optShowNodes opts
58 b790839a Iustin Pop
      verbose = optVerbose opts
59 4162995d Iustin Pop
      savecluster = optSaveCluster opts
60 585d4420 Iustin Pop
61 01fec0a1 Iustin Pop
  request <- readRequest opts args
62 585d4420 Iustin Pop
63 34c00528 Iustin Pop
  let Request rq cdata = request
64 f3d53161 Iustin Pop
65 b790839a Iustin Pop
  when (verbose > 1) $
66 b790839a Iustin Pop
       hPutStrLn stderr $ "Received request: " ++ show rq
67 b790839a Iustin Pop
68 b790839a Iustin Pop
  when (verbose > 2) $
69 b790839a Iustin Pop
       hPutStrLn stderr $ "Received cluster data: " ++ show cdata
70 b790839a Iustin Pop
71 15329af5 Iustin Pop
  maybePrintNodes shownodes "Initial cluster"
72 15329af5 Iustin Pop
       (Cluster.printNodes (cdNodes cdata))
73 f3d53161 Iustin Pop
74 4162995d Iustin Pop
  maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata
75 4162995d Iustin Pop
76 f9283686 Iustin Pop
  let (maybe_ni, resp) = runIAllocator request
77 f9283686 Iustin Pop
      (fin_nl, fin_il) = maybe (cdNodes cdata, cdInstances cdata) id maybe_ni
78 ed41c179 Iustin Pop
  putStrLn resp
79 15329af5 Iustin Pop
80 15329af5 Iustin Pop
  maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl)
81 4162995d Iustin Pop
82 4162995d Iustin Pop
  maybeSaveData savecluster "post-ialloc" "after iallocator run"
83 4162995d Iustin Pop
       (cdata { cdNodes = fin_nl, cdInstances = fin_il})