root / src / Ganeti / HTools / Program / Hail.hs @ f2e50930
History | View | Annotate | Download (2.9 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 | 72747d91 | Iustin Pop | Copyright (C) 2009, 2010, 2011, 2012, 2013 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 | 22278fa7 | Iustin Pop | module Ganeti.HTools.Program.Hail |
27 | 22278fa7 | Iustin Pop | ( main |
28 | 22278fa7 | Iustin Pop | , options |
29 | 22278fa7 | Iustin Pop | , arguments |
30 | 22278fa7 | Iustin Pop | ) where |
31 | 585d4420 | Iustin Pop | |
32 | cc532bdd | Iustin Pop | import Control.Monad |
33 | c3f8cb12 | René Nussbaumer | import Data.Maybe (fromMaybe, isJust) |
34 | 585d4420 | Iustin Pop | import System.IO |
35 | 585d4420 | Iustin Pop | |
36 | 585d4420 | Iustin Pop | import qualified Ganeti.HTools.Cluster as Cluster |
37 | 0427285d | Iustin Pop | |
38 | 22278fa7 | Iustin Pop | import Ganeti.Common |
39 | 0427285d | Iustin Pop | import Ganeti.HTools.CLI |
40 | 879d9290 | Iustin Pop | import Ganeti.HTools.Backend.IAlloc |
41 | cabce2f4 | Iustin Pop | import Ganeti.HTools.Loader (Request(..), ClusterData(..)) |
42 | c3f8cb12 | René Nussbaumer | import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData) |
43 | 707cd3d7 | Helga Velroyen | import Ganeti.Utils |
44 | 585d4420 | Iustin Pop | |
45 | 179c0828 | Iustin Pop | -- | Options list and functions. |
46 | d66aa238 | Iustin Pop | options :: IO [OptType] |
47 | 01fec0a1 | Iustin Pop | options = |
48 | d66aa238 | Iustin Pop | return |
49 | d66aa238 | Iustin Pop | [ oPrintNodes |
50 | d66aa238 | Iustin Pop | , oSaveCluster |
51 | d66aa238 | Iustin Pop | , oDataFile |
52 | d66aa238 | Iustin Pop | , oNodeSim |
53 | d66aa238 | Iustin Pop | , oVerbose |
54 | d66aa238 | Iustin Pop | ] |
55 | f826c5e0 | Iustin Pop | |
56 | 22278fa7 | Iustin Pop | -- | The list of arguments supported by the program. |
57 | 22278fa7 | Iustin Pop | arguments :: [ArgCompletion] |
58 | 22278fa7 | Iustin Pop | arguments = [ArgCompletion OptComplFile 1 (Just 1)] |
59 | 22278fa7 | Iustin Pop | |
60 | c3f8cb12 | René Nussbaumer | wrapReadRequest :: Options -> [String] -> IO Request |
61 | c3f8cb12 | René Nussbaumer | wrapReadRequest opts args = do |
62 | 72747d91 | Iustin Pop | r1 <- case args of |
63 | 72747d91 | Iustin Pop | [] -> exitErr "This program needs an input file." |
64 | 72747d91 | Iustin Pop | _:_:_ -> exitErr "Only one argument is accepted (the input file)" |
65 | 72747d91 | Iustin Pop | x:_ -> readRequest x |
66 | c3f8cb12 | René Nussbaumer | |
67 | c3f8cb12 | René Nussbaumer | if isJust (optDataFile opts) || (not . null . optNodeSim) opts |
68 | c3f8cb12 | René Nussbaumer | then do |
69 | c3f8cb12 | René Nussbaumer | cdata <- loadExternalData opts |
70 | c3f8cb12 | René Nussbaumer | let Request rqt _ = r1 |
71 | c3f8cb12 | René Nussbaumer | return $ Request rqt cdata |
72 | c3f8cb12 | René Nussbaumer | else return r1 |
73 | c3f8cb12 | René Nussbaumer | |
74 | c3f8cb12 | René Nussbaumer | |
75 | 585d4420 | Iustin Pop | -- | Main function. |
76 | 21839f47 | Iustin Pop | main :: Options -> [String] -> IO () |
77 | 21839f47 | Iustin Pop | main opts args = do |
78 | 01fec0a1 | Iustin Pop | let shownodes = optShowNodes opts |
79 | b790839a | Iustin Pop | verbose = optVerbose opts |
80 | 4162995d | Iustin Pop | savecluster = optSaveCluster opts |
81 | 585d4420 | Iustin Pop | |
82 | c3f8cb12 | René Nussbaumer | request <- wrapReadRequest opts args |
83 | 585d4420 | Iustin Pop | |
84 | 34c00528 | Iustin Pop | let Request rq cdata = request |
85 | f3d53161 | Iustin Pop | |
86 | 2cdaf225 | Iustin Pop | when (verbose > 1) . |
87 | b790839a | Iustin Pop | hPutStrLn stderr $ "Received request: " ++ show rq |
88 | b790839a | Iustin Pop | |
89 | 2cdaf225 | Iustin Pop | when (verbose > 2) . |
90 | b790839a | Iustin Pop | hPutStrLn stderr $ "Received cluster data: " ++ show cdata |
91 | b790839a | Iustin Pop | |
92 | 15329af5 | Iustin Pop | maybePrintNodes shownodes "Initial cluster" |
93 | 15329af5 | Iustin Pop | (Cluster.printNodes (cdNodes cdata)) |
94 | f3d53161 | Iustin Pop | |
95 | 4162995d | Iustin Pop | maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata |
96 | 4162995d | Iustin Pop | |
97 | f9283686 | Iustin Pop | let (maybe_ni, resp) = runIAllocator request |
98 | 3603605a | Iustin Pop | (fin_nl, fin_il) = fromMaybe (cdNodes cdata, cdInstances cdata) maybe_ni |
99 | ed41c179 | Iustin Pop | putStrLn resp |
100 | 15329af5 | Iustin Pop | |
101 | 15329af5 | Iustin Pop | maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl) |
102 | 4162995d | Iustin Pop | |
103 | 4162995d | Iustin Pop | maybeSaveData savecluster "post-ialloc" "after iallocator run" |
104 | 4162995d | Iustin Pop | (cdata { cdNodes = fin_nl, cdInstances = fin_il}) |