Statistics
| Branch: | Tag: | Revision:

root / htools / rpc-test.hs @ c65621d7

History | View | Annotate | Download (1.6 kB)

1 19e21a6c Iustin Pop
{-| RPC test program.
2 19e21a6c Iustin Pop
3 19e21a6c Iustin Pop
-}
4 19e21a6c Iustin Pop
5 19e21a6c Iustin Pop
{-
6 19e21a6c Iustin Pop
7 19e21a6c Iustin Pop
Copyright (C) 2011, 2012 Google Inc.
8 19e21a6c Iustin Pop
9 19e21a6c Iustin Pop
This program is free software; you can redistribute it and/or modify
10 19e21a6c Iustin Pop
it under the terms of the GNU General Public License as published by
11 19e21a6c Iustin Pop
the Free Software Foundation; either version 2 of the License, or
12 19e21a6c Iustin Pop
(at your option) any later version.
13 19e21a6c Iustin Pop
14 19e21a6c Iustin Pop
This program is distributed in the hope that it will be useful, but
15 19e21a6c Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
16 19e21a6c Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 19e21a6c Iustin Pop
General Public License for more details.
18 19e21a6c Iustin Pop
19 19e21a6c Iustin Pop
You should have received a copy of the GNU General Public License
20 19e21a6c Iustin Pop
along with this program; if not, write to the Free Software
21 19e21a6c Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 19e21a6c Iustin Pop
02110-1301, USA.
23 19e21a6c Iustin Pop
24 19e21a6c Iustin Pop
-}
25 19e21a6c Iustin Pop
26 19e21a6c Iustin Pop
import System.Environment
27 19e21a6c Iustin Pop
import System.Exit
28 19e21a6c Iustin Pop
import System.IO
29 19e21a6c Iustin Pop
30 19e21a6c Iustin Pop
import Ganeti.Config
31 19e21a6c Iustin Pop
import Ganeti.Objects
32 19e21a6c Iustin Pop
import qualified Ganeti.Path as P
33 19e21a6c Iustin Pop
import Ganeti.Rpc
34 19e21a6c Iustin Pop
import Ganeti.Utils
35 19e21a6c Iustin Pop
36 19e21a6c Iustin Pop
-- | Show usage info and exit.
37 19e21a6c Iustin Pop
usage :: IO ()
38 19e21a6c Iustin Pop
usage = do
39 19e21a6c Iustin Pop
  prog <- getProgName
40 707cd3d7 Helga Velroyen
  exitErr "Usage: " ++ prog ++ " delay node..."
41 19e21a6c Iustin Pop
42 19e21a6c Iustin Pop
main :: IO ()
43 19e21a6c Iustin Pop
main = do
44 19e21a6c Iustin Pop
  args <- getArgs
45 19e21a6c Iustin Pop
  (delay, nodes) <- case args of
46 19e21a6c Iustin Pop
                      [] -> usage >> return ("", []) -- workaround types...
47 19e21a6c Iustin Pop
                      _:[] -> usage >> return ("", [])
48 19e21a6c Iustin Pop
                      x:xs -> return (x, xs)
49 19e21a6c Iustin Pop
  cfg <- loadConfig P.clusterConfFile >>=
50 19e21a6c Iustin Pop
         exitIfBad "Can't load configuration"
51 19e21a6c Iustin Pop
  let call = RpcCallTestDelay (read delay)
52 19e21a6c Iustin Pop
  nodes' <- exitIfBad "Can't find node" $ mapM (getNode cfg) nodes
53 19e21a6c Iustin Pop
  results <- executeRpcCall nodes' call
54 19e21a6c Iustin Pop
  putStr $ printTable "" ["Node", "Result"]
55 19e21a6c Iustin Pop
           (map (\(n, r) -> [nodeName n, show r]) results) [False, False]