root / htools / Ganeti / HTools / Program / Hail.hs @ c3f8cb12
History | View | Annotate | Download (2.6 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 | c3f8cb12 | René Nussbaumer | import Data.Maybe (fromMaybe, isJust) |
30 | 585d4420 | Iustin Pop | import System.IO |
31 | c3f8cb12 | René Nussbaumer | import System.Exit |
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 | c3f8cb12 | René Nussbaumer | import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData) |
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 | c3f8cb12 | René Nussbaumer | wrapReadRequest :: Options -> [String] -> IO Request |
53 | c3f8cb12 | René Nussbaumer | wrapReadRequest opts args = do |
54 | c3f8cb12 | René Nussbaumer | when (null args) $ do |
55 | c3f8cb12 | René Nussbaumer | hPutStrLn stderr "Error: this program needs an input file." |
56 | c3f8cb12 | René Nussbaumer | exitWith $ ExitFailure 1 |
57 | c3f8cb12 | René Nussbaumer | |
58 | c3f8cb12 | René Nussbaumer | r1 <- readRequest (head args) |
59 | c3f8cb12 | René Nussbaumer | if isJust (optDataFile opts) || (not . null . optNodeSim) opts |
60 | c3f8cb12 | René Nussbaumer | then do |
61 | c3f8cb12 | René Nussbaumer | cdata <- loadExternalData opts |
62 | c3f8cb12 | René Nussbaumer | let Request rqt _ = r1 |
63 | c3f8cb12 | René Nussbaumer | return $ Request rqt cdata |
64 | c3f8cb12 | René Nussbaumer | else return r1 |
65 | c3f8cb12 | René Nussbaumer | |
66 | c3f8cb12 | René Nussbaumer | |
67 | 585d4420 | Iustin Pop | -- | Main function. |
68 | 21839f47 | Iustin Pop | main :: Options -> [String] -> IO () |
69 | 21839f47 | Iustin Pop | main opts args = do |
70 | 01fec0a1 | Iustin Pop | let shownodes = optShowNodes opts |
71 | b790839a | Iustin Pop | verbose = optVerbose opts |
72 | 4162995d | Iustin Pop | savecluster = optSaveCluster opts |
73 | 585d4420 | Iustin Pop | |
74 | c3f8cb12 | René Nussbaumer | request <- wrapReadRequest opts args |
75 | 585d4420 | Iustin Pop | |
76 | 34c00528 | Iustin Pop | let Request rq cdata = request |
77 | f3d53161 | Iustin Pop | |
78 | b790839a | Iustin Pop | when (verbose > 1) $ |
79 | b790839a | Iustin Pop | hPutStrLn stderr $ "Received request: " ++ show rq |
80 | b790839a | Iustin Pop | |
81 | b790839a | Iustin Pop | when (verbose > 2) $ |
82 | b790839a | Iustin Pop | hPutStrLn stderr $ "Received cluster data: " ++ show cdata |
83 | b790839a | Iustin Pop | |
84 | 15329af5 | Iustin Pop | maybePrintNodes shownodes "Initial cluster" |
85 | 15329af5 | Iustin Pop | (Cluster.printNodes (cdNodes cdata)) |
86 | f3d53161 | Iustin Pop | |
87 | 4162995d | Iustin Pop | maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata |
88 | 4162995d | Iustin Pop | |
89 | f9283686 | Iustin Pop | let (maybe_ni, resp) = runIAllocator request |
90 | 3603605a | Iustin Pop | (fin_nl, fin_il) = fromMaybe (cdNodes cdata, cdInstances cdata) maybe_ni |
91 | ed41c179 | Iustin Pop | putStrLn resp |
92 | 15329af5 | Iustin Pop | |
93 | 15329af5 | Iustin Pop | maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl) |
94 | 4162995d | Iustin Pop | |
95 | 4162995d | Iustin Pop | maybeSaveData savecluster "post-ialloc" "after iallocator run" |
96 | 4162995d | Iustin Pop | (cdata { cdNodes = fin_nl, cdInstances = fin_il}) |