| Branch: | Tag: | Revision:

root / src / Ganeti / HTools / Program / Main.hs @ 2d6bdcc5

History | View | Annotate | Download (4.1 kB)

1 9f13be88 Iustin Pop
{-| Small module holding program definitions.
2 9f13be88 Iustin Pop
3 9f13be88 Iustin Pop
4 9f13be88 Iustin Pop
5 9f13be88 Iustin Pop
6 9f13be88 Iustin Pop
7 9f13be88 Iustin Pop
Copyright (C) 2011, 2012 Google Inc.
8 9f13be88 Iustin Pop
9 9f13be88 Iustin Pop
This program is free software; you can redistribute it and/or modify
10 9f13be88 Iustin Pop
it under the terms of the GNU General Public License as published by
11 9f13be88 Iustin Pop
the Free Software Foundation; either version 2 of the License, or
12 9f13be88 Iustin Pop
(at your option) any later version.
13 9f13be88 Iustin Pop
14 9f13be88 Iustin Pop
This program is distributed in the hope that it will be useful, but
15 9f13be88 Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
16 9f13be88 Iustin Pop
17 9f13be88 Iustin Pop
General Public License for more details.
18 9f13be88 Iustin Pop
19 9f13be88 Iustin Pop
You should have received a copy of the GNU General Public License
20 9f13be88 Iustin Pop
along with this program; if not, write to the Free Software
21 9f13be88 Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 9f13be88 Iustin Pop
02110-1301, USA.
23 9f13be88 Iustin Pop
24 9f13be88 Iustin Pop
25 9f13be88 Iustin Pop
26 2fd5a116 Iustin Pop
module Ganeti.HTools.Program.Main
27 9f13be88 Iustin Pop
  ( personalities
28 2fd5a116 Iustin Pop
  , main
29 9f13be88 Iustin Pop
  ) where
30 9f13be88 Iustin Pop
31 2fd5a116 Iustin Pop
import Control.Exception
32 2fd5a116 Iustin Pop
import Control.Monad (guard)
33 2fd5a116 Iustin Pop
import Data.Char (toLower)
34 2fd5a116 Iustin Pop
import System.Environment
35 2fd5a116 Iustin Pop
import System.IO
36 2fd5a116 Iustin Pop
import System.IO.Error (isDoesNotExistError)
37 9f13be88 Iustin Pop
38 2fd5a116 Iustin Pop
import Ganeti.Common (formatCommands, PersonalityList)
39 2fd5a116 Iustin Pop
import Ganeti.HTools.CLI (Options, parseOpts, genericOpts)
40 9f13be88 Iustin Pop
import qualified Ganeti.HTools.Program.Hail as Hail
41 9f13be88 Iustin Pop
import qualified Ganeti.HTools.Program.Hbal as Hbal
42 22e513e7 Agata Murawska
import qualified Ganeti.HTools.Program.Hcheck as Hcheck
43 9f13be88 Iustin Pop
import qualified Ganeti.HTools.Program.Hscan as Hscan
44 9f13be88 Iustin Pop
import qualified Ganeti.HTools.Program.Hspace as Hspace
45 2922d2c5 René Nussbaumer
import qualified Ganeti.HTools.Program.Hinfo as Hinfo
46 3504d6c8 Guido Trotter
import qualified Ganeti.HTools.Program.Hroller as Hroller
47 2fd5a116 Iustin Pop
import Ganeti.Utils
48 9f13be88 Iustin Pop
49 9f13be88 Iustin Pop
-- | Supported binaries.
50 2e6ef129 Iustin Pop
personalities :: PersonalityList Options
51 559c4a98 Iustin Pop
personalities =
52 3504d6c8 Guido Trotter
  [ ("hail",    (Hail.main,    Hail.options,    Hail.arguments,
53 3504d6c8 Guido Trotter
                 "Ganeti IAllocator plugin that implements the instance\
54 3504d6c8 Guido Trotter
                 \ placement and movement using the same algorithm as\
55 3504d6c8 Guido Trotter
                 \ hbal(1)"))
56 3504d6c8 Guido Trotter
  , ("hbal",    (Hbal.main,    Hbal.options,    Hbal.arguments,
57 3504d6c8 Guido Trotter
                 "cluster balancer that looks at the current state of\
58 3504d6c8 Guido Trotter
                 \ the cluster and computes a series of steps designed\
59 3504d6c8 Guido Trotter
                 \ to bring the cluster into a better state"))
60 3504d6c8 Guido Trotter
  , ("hcheck",  (Hcheck.main,  Hcheck.options,  Hcheck.arguments,
61 3504d6c8 Guido Trotter
                "cluster checker; prints information about cluster's\
62 3504d6c8 Guido Trotter
                \ health and checks whether a rebalance done using\
63 3504d6c8 Guido Trotter
                \ hbal would help"))
64 3504d6c8 Guido Trotter
  , ("hscan",   (Hscan.main,   Hscan.options,   Hscan.arguments,
65 3504d6c8 Guido Trotter
                "tool for scanning clusters via RAPI and saving their\
66 3504d6c8 Guido Trotter
                \ data in the input format used by hbal(1) and hspace(1)"))
67 3504d6c8 Guido Trotter
  , ("hspace",  (Hspace.main,  Hspace.options,  Hspace.arguments,
68 3504d6c8 Guido Trotter
                "computes how many additional instances can be fit on a\
69 3504d6c8 Guido Trotter
                \ cluster, while maintaining N+1 status."))
70 3504d6c8 Guido Trotter
  , ("hinfo",   (Hinfo.main,   Hinfo.options,   Hinfo.arguments,
71 3504d6c8 Guido Trotter
                "cluster information printer; it prints information\
72 3504d6c8 Guido Trotter
                \ about the current cluster state and its residing\
73 3504d6c8 Guido Trotter
                \ nodes/instances"))
74 3504d6c8 Guido Trotter
  , ("hroller", (Hroller.main, Hroller.options, Hroller.arguments,
75 3504d6c8 Guido Trotter
                "cluster rolling maintenance helper; it helps scheduling\
76 3504d6c8 Guido Trotter
                \ node reboots in a manner that doesn't conflict with the\
77 3504d6c8 Guido Trotter
                \ instances' topology"))
78 559c4a98 Iustin Pop
79 2fd5a116 Iustin Pop
80 2fd5a116 Iustin Pop
-- | Display usage and exit.
81 2fd5a116 Iustin Pop
usage :: String -> IO ()
82 2fd5a116 Iustin Pop
usage name = do
83 2fd5a116 Iustin Pop
  hPutStrLn stderr $ "Unrecognised personality '" ++ name ++ "'."
84 2fd5a116 Iustin Pop
  hPutStrLn stderr "This program must be installed under one of the following\
85 2fd5a116 Iustin Pop
                   \ names:"
86 2fd5a116 Iustin Pop
  hPutStrLn stderr . unlines $ formatCommands personalities
87 2fd5a116 Iustin Pop
  exitErr "Please either rename/symlink the program or set\n\
88 2fd5a116 Iustin Pop
          \the environment variable HTOOLS to the desired role."
89 2fd5a116 Iustin Pop
90 2fd5a116 Iustin Pop
main :: IO ()
91 2fd5a116 Iustin Pop
main = do
92 2fd5a116 Iustin Pop
  binary <- catchJust (guard . isDoesNotExistError)
93 2fd5a116 Iustin Pop
            (getEnv "HTOOLS") (const getProgName)
94 2fd5a116 Iustin Pop
  let name = map toLower binary
95 2fd5a116 Iustin Pop
  case name `lookup` personalities of
96 2fd5a116 Iustin Pop
    Nothing -> usage name
97 2fd5a116 Iustin Pop
    Just (fn, options, arguments, _) -> do
98 2fd5a116 Iustin Pop
         cmd_args <- getArgs
99 2fd5a116 Iustin Pop
         real_options <- options
100 2fd5a116 Iustin Pop
         (opts, args) <- parseOpts cmd_args name (real_options ++ genericOpts)
101 2fd5a116 Iustin Pop
102 2fd5a116 Iustin Pop
         fn opts args