Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / HTools / Program / Hail.hs @ d605e261

History | View | Annotate | Download (3.1 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 c32c4e4d Spyros Trigazis
import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData
43 c32c4e4d Spyros Trigazis
                               , queryAllMonDDCs)
44 707cd3d7 Helga Velroyen
import Ganeti.Utils
45 585d4420 Iustin Pop
46 179c0828 Iustin Pop
-- | Options list and functions.
47 d66aa238 Iustin Pop
options :: IO [OptType]
48 01fec0a1 Iustin Pop
options =
49 d66aa238 Iustin Pop
  return
50 d66aa238 Iustin Pop
    [ oPrintNodes
51 d66aa238 Iustin Pop
    , oSaveCluster
52 d66aa238 Iustin Pop
    , oDataFile
53 d66aa238 Iustin Pop
    , oNodeSim
54 d66aa238 Iustin Pop
    , oVerbose
55 c32c4e4d Spyros Trigazis
    , oIgnoreDyn
56 c32c4e4d Spyros Trigazis
    , oMonD
57 d66aa238 Iustin Pop
    ]
58 f826c5e0 Iustin Pop
59 22278fa7 Iustin Pop
-- | The list of arguments supported by the program.
60 22278fa7 Iustin Pop
arguments :: [ArgCompletion]
61 22278fa7 Iustin Pop
arguments = [ArgCompletion OptComplFile 1 (Just 1)]
62 22278fa7 Iustin Pop
63 c3f8cb12 René Nussbaumer
wrapReadRequest :: Options -> [String] -> IO Request
64 c3f8cb12 René Nussbaumer
wrapReadRequest opts args = do
65 72747d91 Iustin Pop
  r1 <- case args of
66 72747d91 Iustin Pop
          []    -> exitErr "This program needs an input file."
67 72747d91 Iustin Pop
          _:_:_ -> exitErr "Only one argument is accepted (the input file)"
68 72747d91 Iustin Pop
          x:_   -> readRequest x
69 c3f8cb12 René Nussbaumer
70 c3f8cb12 René Nussbaumer
  if isJust (optDataFile opts) ||  (not . null . optNodeSim) opts
71 c3f8cb12 René Nussbaumer
    then do
72 c3f8cb12 René Nussbaumer
      cdata <- loadExternalData opts
73 c3f8cb12 René Nussbaumer
      let Request rqt _ = r1
74 c3f8cb12 René Nussbaumer
      return $ Request rqt cdata
75 c32c4e4d Spyros Trigazis
    else do
76 c32c4e4d Spyros Trigazis
      let Request rqt cdata = r1
77 c32c4e4d Spyros Trigazis
      cdata' <-
78 c32c4e4d Spyros Trigazis
        if optMonD opts then queryAllMonDDCs cdata opts else return cdata
79 c32c4e4d Spyros Trigazis
      return $ Request rqt cdata'
80 c3f8cb12 René Nussbaumer
81 585d4420 Iustin Pop
-- | Main function.
82 21839f47 Iustin Pop
main :: Options -> [String] -> IO ()
83 21839f47 Iustin Pop
main opts args = do
84 01fec0a1 Iustin Pop
  let shownodes = optShowNodes opts
85 b790839a Iustin Pop
      verbose = optVerbose opts
86 4162995d Iustin Pop
      savecluster = optSaveCluster opts
87 585d4420 Iustin Pop
88 c3f8cb12 René Nussbaumer
  request <- wrapReadRequest opts args
89 585d4420 Iustin Pop
90 34c00528 Iustin Pop
  let Request rq cdata = request
91 f3d53161 Iustin Pop
92 2cdaf225 Iustin Pop
  when (verbose > 1) .
93 b790839a Iustin Pop
       hPutStrLn stderr $ "Received request: " ++ show rq
94 b790839a Iustin Pop
95 2cdaf225 Iustin Pop
  when (verbose > 2) .
96 b790839a Iustin Pop
       hPutStrLn stderr $ "Received cluster data: " ++ show cdata
97 b790839a Iustin Pop
98 15329af5 Iustin Pop
  maybePrintNodes shownodes "Initial cluster"
99 15329af5 Iustin Pop
       (Cluster.printNodes (cdNodes cdata))
100 f3d53161 Iustin Pop
101 4162995d Iustin Pop
  maybeSaveData savecluster "pre-ialloc" "before iallocator run" cdata
102 4162995d Iustin Pop
103 f9283686 Iustin Pop
  let (maybe_ni, resp) = runIAllocator request
104 3603605a Iustin Pop
      (fin_nl, fin_il) = fromMaybe (cdNodes cdata, cdInstances cdata) maybe_ni
105 ed41c179 Iustin Pop
  putStrLn resp
106 15329af5 Iustin Pop
107 15329af5 Iustin Pop
  maybePrintNodes shownodes "Final cluster" (Cluster.printNodes fin_nl)
108 4162995d Iustin Pop
109 4162995d Iustin Pop
  maybeSaveData savecluster "post-ialloc" "after iallocator run"
110 4162995d Iustin Pop
       (cdata { cdNodes = fin_nl, cdInstances = fin_il})