root / htools / Ganeti / HTools / Program / Hail.hs @ ad0e078e
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 | 21839f47 | Iustin Pop | Copyright (C) 2009, 2010, 2011, 2012 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 | 21839f47 | Iustin Pop | module Ganeti.HTools.Program.Hail (main, options) where |
27 | 585d4420 | Iustin Pop | |
28 | cc532bdd | Iustin Pop | import Control.Monad |
29 | 3603605a | Iustin Pop | import Data.Maybe (fromMaybe) |
30 | 585d4420 | Iustin Pop | import System.IO |
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 | 179c0828 | Iustin Pop | -- | Options list and functions. |
40 | 0427285d | Iustin Pop | options :: [OptType] |
41 | 01fec0a1 | Iustin Pop | options = |
42 | ebf38064 | Iustin Pop | [ oPrintNodes |
43 | ebf38064 | Iustin Pop | , oSaveCluster |
44 | ebf38064 | Iustin Pop | , oDataFile |
45 | ebf38064 | Iustin Pop | , oNodeSim |
46 | ebf38064 | Iustin Pop | , oVerbose |
47 | ebf38064 | Iustin Pop | , oShowVer |
48 | ebf38064 | Iustin Pop | , oShowHelp |
49 | ebf38064 | Iustin Pop | ] |
50 | f826c5e0 | Iustin Pop | |
51 | 585d4420 | Iustin Pop | -- | Main function. |
52 | 21839f47 | Iustin Pop | main :: Options -> [String] -> IO () |
53 | 21839f47 | Iustin Pop | main opts args = do |
54 | 01fec0a1 | Iustin Pop | let shownodes = optShowNodes opts |
55 | b790839a | Iustin Pop | verbose = optVerbose opts |
56 | 4162995d | Iustin Pop | savecluster = optSaveCluster opts |
57 | 585d4420 | Iustin Pop | |
58 | 01fec0a1 | Iustin Pop | request <- readRequest opts args |
59 | 585d4420 | Iustin Pop | |
60 | 34c00528 | Iustin Pop | let Request rq cdata = request |
61 | f3d53161 | Iustin Pop | |
62 | b790839a | Iustin Pop | when (verbose > 1) $ |
63 | b790839a | Iustin Pop | hPutStrLn stderr $ "Received request: " ++ show rq |
64 | b790839a | Iustin Pop | |
65 | b790839a | Iustin Pop | when (verbose > 2) $ |
66 | b790839a | Iustin Pop | hPutStrLn stderr $ "Received cluster data: " ++ show cdata |
67 | b790839a | Iustin Pop | |
68 | 15329af5 | Iustin Pop | maybePrintNodes shownodes "Initial cluster" |
69 | 15329af5 | Iustin Pop | (Cluster.printNodes (cdNodes cdata)) |
70 | f3d53161 | Iustin Pop | |
71 | 4162995d | Iustin Pop | maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata |
72 | 4162995d | Iustin Pop | |
73 | f9283686 | Iustin Pop | let (maybe_ni, resp) = runIAllocator request |
74 | 3603605a | Iustin Pop | (fin_nl, fin_il) = fromMaybe (cdNodes cdata, cdInstances cdata) maybe_ni |
75 | ed41c179 | Iustin Pop | putStrLn resp |
76 | 15329af5 | Iustin Pop | |
77 | 15329af5 | Iustin Pop | maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl) |
78 | 4162995d | Iustin Pop | |
79 | 4162995d | Iustin Pop | maybeSaveData savecluster "post-ialloc" "after iallocator run" |
80 | 4162995d | Iustin Pop | (cdata { cdNodes = fin_nl, cdInstances = fin_il}) |