Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / HTools / Program / Hail.hs @ d66aa238

History | View | Annotate | Download (2.8 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 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 707cd3d7 Helga Velroyen
  when (null args) $ exitErr "This program needs an input file."
63 c3f8cb12 René Nussbaumer
64 c3f8cb12 René Nussbaumer
  r1 <- readRequest (head args)
65 c3f8cb12 René Nussbaumer
  if isJust (optDataFile opts) ||  (not . null . optNodeSim) opts
66 c3f8cb12 René Nussbaumer
    then do
67 c3f8cb12 René Nussbaumer
      cdata <- loadExternalData opts
68 c3f8cb12 René Nussbaumer
      let Request rqt _ = r1
69 c3f8cb12 René Nussbaumer
      return $ Request rqt cdata
70 c3f8cb12 René Nussbaumer
    else return r1
71 c3f8cb12 René Nussbaumer
72 c3f8cb12 René Nussbaumer
73 585d4420 Iustin Pop
-- | Main function.
74 21839f47 Iustin Pop
main :: Options -> [String] -> IO ()
75 21839f47 Iustin Pop
main opts args = do
76 01fec0a1 Iustin Pop
  let shownodes = optShowNodes opts
77 b790839a Iustin Pop
      verbose = optVerbose opts
78 4162995d Iustin Pop
      savecluster = optSaveCluster opts
79 585d4420 Iustin Pop
80 c3f8cb12 René Nussbaumer
  request <- wrapReadRequest opts args
81 585d4420 Iustin Pop
82 34c00528 Iustin Pop
  let Request rq cdata = request
83 f3d53161 Iustin Pop
84 2cdaf225 Iustin Pop
  when (verbose > 1) .
85 b790839a Iustin Pop
       hPutStrLn stderr $ "Received request: " ++ show rq
86 b790839a Iustin Pop
87 2cdaf225 Iustin Pop
  when (verbose > 2) .
88 b790839a Iustin Pop
       hPutStrLn stderr $ "Received cluster data: " ++ show cdata
89 b790839a Iustin Pop
90 15329af5 Iustin Pop
  maybePrintNodes shownodes "Initial cluster"
91 15329af5 Iustin Pop
       (Cluster.printNodes (cdNodes cdata))
92 f3d53161 Iustin Pop
93 4162995d Iustin Pop
  maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata
94 4162995d Iustin Pop
95 f9283686 Iustin Pop
  let (maybe_ni, resp) = runIAllocator request
96 3603605a Iustin Pop
      (fin_nl, fin_il) = fromMaybe (cdNodes cdata, cdInstances cdata) maybe_ni
97 ed41c179 Iustin Pop
  putStrLn resp
98 15329af5 Iustin Pop
99 15329af5 Iustin Pop
  maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl)
100 4162995d Iustin Pop
101 4162995d Iustin Pop
  maybeSaveData savecluster "post-ialloc" "after iallocator run"
102 4162995d Iustin Pop
       (cdata { cdNodes = fin_nl, cdInstances = fin_il})