hail.hs 1.86 KB
Newer Older
1
{-| IAllocator plugin for Ganeti.
Iustin Pop's avatar
Iustin Pop committed
2
3
4

-}

Iustin Pop's avatar
Iustin Pop committed
5
6
{-

7
Copyright (C) 2009, 2010, 2011 Google Inc.
Iustin Pop's avatar
Iustin Pop committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

-}

Iustin Pop's avatar
Iustin Pop committed
26
27
module Main (main) where

Iustin Pop's avatar
Iustin Pop committed
28
import Control.Monad
29
import Data.Maybe (isJust, fromJust)
Iustin Pop's avatar
Iustin Pop committed
30
31
32
33
import System.IO
import qualified System

import qualified Ganeti.HTools.Cluster as Cluster
34
35

import Ganeti.HTools.CLI
Iustin Pop's avatar
Iustin Pop committed
36
import Ganeti.HTools.IAlloc
37
import Ganeti.HTools.Loader (Request(..), ClusterData(..))
Iustin Pop's avatar
Iustin Pop committed
38
39

-- | Options list and functions
40
options :: [OptType]
41
42
43
44
options =
    [ oPrintNodes
    , oDataFile
    , oNodeSim
45
    , oVerbose
46
47
48
    , oShowVer
    , oShowHelp
    ]
49

Iustin Pop's avatar
Iustin Pop committed
50
51
52
53
-- | Main function.
main :: IO ()
main = do
  cmd_args <- System.getArgs
54
  (opts, args) <- parseOpts cmd_args "hail" options
Iustin Pop's avatar
Iustin Pop committed
55

56
  let shownodes = optShowNodes opts
57
      verbose = optVerbose opts
Iustin Pop's avatar
Iustin Pop committed
58

59
  request <- readRequest opts args
Iustin Pop's avatar
Iustin Pop committed
60

61
  let Request rq cdata = request
62

63
64
65
66
67
68
  when (verbose > 1) $
       hPutStrLn stderr $ "Received request: " ++ show rq

  when (verbose > 2) $
       hPutStrLn stderr $ "Received cluster data: " ++ show cdata

69
70
  when (isJust shownodes) $ do
         hPutStrLn stderr "Initial cluster status:"
71
72
         hPutStrLn stderr $ Cluster.printNodes (cdNodes cdata)
                       (fromJust shownodes)
73

74
  let resp = runIAllocator request
75
  putStrLn resp