Statistics
| Branch: | Tag: | Revision:

root / htools / hail.hs @ 9bb5721c

History | View | Annotate | Download (1.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 4bc33d60 Iustin Pop
Copyright (C) 2009, 2010, 2011 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 585d4420 Iustin Pop
module Main (main) where
27 585d4420 Iustin Pop
28 cc532bdd Iustin Pop
import Control.Monad
29 f3d53161 Iustin Pop
import Data.Maybe (isJust, fromJust)
30 585d4420 Iustin Pop
import System.IO
31 585d4420 Iustin Pop
import qualified System
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 585d4420 Iustin Pop
39 585d4420 Iustin Pop
-- | Options list and functions
40 0427285d Iustin Pop
options :: [OptType]
41 01fec0a1 Iustin Pop
options =
42 01fec0a1 Iustin Pop
    [ oPrintNodes
43 01fec0a1 Iustin Pop
    , oDataFile
44 01fec0a1 Iustin Pop
    , oNodeSim
45 b790839a Iustin Pop
    , oVerbose
46 01fec0a1 Iustin Pop
    , oShowVer
47 01fec0a1 Iustin Pop
    , oShowHelp
48 01fec0a1 Iustin Pop
    ]
49 f826c5e0 Iustin Pop
50 585d4420 Iustin Pop
-- | Main function.
51 585d4420 Iustin Pop
main :: IO ()
52 585d4420 Iustin Pop
main = do
53 585d4420 Iustin Pop
  cmd_args <- System.getArgs
54 f3d53161 Iustin Pop
  (opts, args) <- parseOpts cmd_args "hail" options
55 585d4420 Iustin Pop
56 01fec0a1 Iustin Pop
  let shownodes = optShowNodes opts
57 b790839a Iustin Pop
      verbose = optVerbose opts
58 585d4420 Iustin Pop
59 01fec0a1 Iustin Pop
  request <- readRequest opts args
60 585d4420 Iustin Pop
61 34c00528 Iustin Pop
  let Request rq cdata = request
62 f3d53161 Iustin Pop
63 b790839a Iustin Pop
  when (verbose > 1) $
64 b790839a Iustin Pop
       hPutStrLn stderr $ "Received request: " ++ show rq
65 b790839a Iustin Pop
66 b790839a Iustin Pop
  when (verbose > 2) $
67 b790839a Iustin Pop
       hPutStrLn stderr $ "Received cluster data: " ++ show cdata
68 b790839a Iustin Pop
69 f3d53161 Iustin Pop
  when (isJust shownodes) $ do
70 f3d53161 Iustin Pop
         hPutStrLn stderr "Initial cluster status:"
71 34c00528 Iustin Pop
         hPutStrLn stderr $ Cluster.printNodes (cdNodes cdata)
72 34c00528 Iustin Pop
                       (fromJust shownodes)
73 f3d53161 Iustin Pop
74 00152519 Iustin Pop
  let resp = runIAllocator request
75 ed41c179 Iustin Pop
  putStrLn resp