Statistics
| Branch: | Tag: | Revision:

root / src / rpc-test.hs @ 7ec2f76b

History | View | Annotate | Download (1.7 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
28 08fd383d Iustin Pop
import Ganeti.Errors
29 19e21a6c Iustin Pop
import Ganeti.Config
30 19e21a6c Iustin Pop
import Ganeti.Objects
31 19e21a6c Iustin Pop
import qualified Ganeti.Path as P
32 19e21a6c Iustin Pop
import Ganeti.Rpc
33 19e21a6c Iustin Pop
import Ganeti.Utils
34 19e21a6c Iustin Pop
35 19e21a6c Iustin Pop
-- | Show usage info and exit.
36 19e21a6c Iustin Pop
usage :: IO ()
37 19e21a6c Iustin Pop
usage = do
38 19e21a6c Iustin Pop
  prog <- getProgName
39 08fd383d Iustin Pop
  exitErr $ "Usage: " ++ prog ++ " delay node..."
40 19e21a6c Iustin Pop
41 19e21a6c Iustin Pop
main :: IO ()
42 19e21a6c Iustin Pop
main = do
43 19e21a6c Iustin Pop
  args <- getArgs
44 19e21a6c Iustin Pop
  (delay, nodes) <- case args of
45 19e21a6c Iustin Pop
                      [] -> usage >> return ("", []) -- workaround types...
46 19e21a6c Iustin Pop
                      _:[] -> usage >> return ("", [])
47 19e21a6c Iustin Pop
                      x:xs -> return (x, xs)
48 08fd383d Iustin Pop
  cfg_file <- P.clusterConfFile
49 08fd383d Iustin Pop
  cfg <- loadConfig  cfg_file>>= exitIfBad "Can't load configuration"
50 19e21a6c Iustin Pop
  let call = RpcCallTestDelay (read delay)
51 08fd383d Iustin Pop
  nodes' <- exitIfBad "Can't find node" . errToResult $
52 08fd383d Iustin Pop
            mapM (getNode cfg) nodes
53 19e21a6c Iustin Pop
  results <- executeRpcCall nodes' call
54 19e21a6c Iustin Pop
  putStr $ printTable "" ["Node", "Result"]
55 4d829f55 Iustin Pop
           (map (\(n, r) -> [nodeName n, either explainRpcError show r])
56 4d829f55 Iustin Pop
                results)
57 4d829f55 Iustin Pop
           [False, False]