root / htools / Ganeti / HTools / Program / Hinfo.hs @ 2922d2c5
History | View | Annotate | Download (3.2 kB)
1 |
{-| Cluster information printer. |
---|---|
2 |
|
3 |
-} |
4 |
|
5 |
{- |
6 |
|
7 |
Copyright (C) 2012 Google Inc. |
8 |
|
9 |
This program is free software; you can redistribute it and/or modify |
10 |
it under the terms of the GNU General Public License as published by |
11 |
the Free Software Foundation; either version 2 of the License, or |
12 |
(at your option) any later version. |
13 |
|
14 |
This program is distributed in the hope that it will be useful, but |
15 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
General Public License for more details. |
18 |
|
19 |
You should have received a copy of the GNU General Public License |
20 |
along with this program; if not, write to the Free Software |
21 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 |
02110-1301, USA. |
23 |
|
24 |
-} |
25 |
|
26 |
module Ganeti.HTools.Program.Hinfo (main, options) where |
27 |
|
28 |
import Control.Monad |
29 |
import Data.List |
30 |
import System.Exit |
31 |
import System.IO |
32 |
|
33 |
import Text.Printf (printf) |
34 |
|
35 |
import qualified Ganeti.HTools.Container as Container |
36 |
import qualified Ganeti.HTools.Cluster as Cluster |
37 |
import qualified Ganeti.HTools.Node as Node |
38 |
import qualified Ganeti.HTools.Instance as Instance |
39 |
|
40 |
import Ganeti.HTools.CLI |
41 |
import Ganeti.HTools.ExtLoader |
42 |
import Ganeti.HTools.Loader |
43 |
|
44 |
-- | Options list and functions. |
45 |
options :: [OptType] |
46 |
options = |
47 |
[ oPrintNodes |
48 |
, oPrintInsts |
49 |
, oDataFile |
50 |
, oRapiMaster |
51 |
, oLuxiSocket |
52 |
, oVerbose |
53 |
, oQuiet |
54 |
, oOfflineNode |
55 |
, oShowVer |
56 |
, oShowHelp |
57 |
] |
58 |
|
59 |
-- | Do a few checks on the cluster data. |
60 |
checkCluster :: Int -> Node.List -> Instance.List -> IO () |
61 |
checkCluster verbose nl il = do |
62 |
-- nothing to do on an empty cluster |
63 |
when (Container.null il) $ do |
64 |
printf "Cluster is empty, exiting.\n"::IO () |
65 |
exitWith ExitSuccess |
66 |
|
67 |
-- hbal doesn't currently handle split clusters |
68 |
let split_insts = Cluster.findSplitInstances nl il |
69 |
unless (null split_insts) $ do |
70 |
hPutStrLn stderr "Found instances belonging to multiple node groups:" |
71 |
mapM_ (\i -> hPutStrLn stderr $ " " ++ Instance.name i) split_insts |
72 |
hPutStrLn stderr "Aborting." |
73 |
exitWith $ ExitFailure 1 |
74 |
|
75 |
printf "Loaded %d nodes, %d instances\n" |
76 |
(Container.size nl) |
77 |
(Container.size il)::IO () |
78 |
|
79 |
let csf = commonSuffix nl il |
80 |
when (not (null csf) && verbose > 1) $ |
81 |
printf "Note: Stripping common suffix of '%s' from names\n" csf |
82 |
|
83 |
-- | Main function. |
84 |
main :: Options -> [String] -> IO () |
85 |
main opts args = do |
86 |
unless (null args) $ do |
87 |
hPutStrLn stderr "Error: this program doesn't take any arguments." |
88 |
exitWith $ ExitFailure 1 |
89 |
|
90 |
let verbose = optVerbose opts |
91 |
shownodes = optShowNodes opts |
92 |
showinsts = optShowInsts opts |
93 |
|
94 |
(ClusterData gl fixed_nl ilf ctags ipol) <- loadExternalData opts |
95 |
|
96 |
when (verbose > 1) $ do |
97 |
putStrLn $ "Loaded cluster tags: " ++ intercalate "," ctags |
98 |
putStrLn $ "Loaded cluster ipolicy: " ++ show ipol |
99 |
putStrLn $ "Loaded node groups: " ++ show gl |
100 |
|
101 |
nlf <- setNodeStatus opts fixed_nl |
102 |
checkCluster verbose nlf ilf |
103 |
|
104 |
printf "Cluster has %d node group(s)\n" (Container.size gl)::IO () |
105 |
|
106 |
maybePrintInsts showinsts "Instances" (Cluster.printInsts nlf ilf) |
107 |
|
108 |
maybePrintNodes shownodes "Cluster" (Cluster.printNodes nlf) |
109 |
|
110 |
printf "Cluster coefficients:\n%s" (Cluster.printStats " " nlf)::IO () |
111 |
printf "Cluster score: %.8f\n" (Cluster.compCV nlf) |