Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / HTools / Program / Hinfo.hs @ 19e310cc

History | View | Annotate | Download (3.6 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.Group as Group
39
import qualified Ganeti.HTools.Instance as Instance
40

    
41
import Ganeti.HTools.Utils
42
import Ganeti.HTools.CLI
43
import Ganeti.HTools.ExtLoader
44
import Ganeti.HTools.Loader
45

    
46
-- | Options list and functions.
47
options :: [OptType]
48
options =
49
  [ oPrintNodes
50
  , oPrintInsts
51
  , oDataFile
52
  , oRapiMaster
53
  , oLuxiSocket
54
  , oVerbose
55
  , oQuiet
56
  , oOfflineNode
57
  , oShowVer
58
  , oShowHelp
59
  ]
60

    
61
-- | Gather and print split instances
62
splitInstancesInfo :: Int -> Node.List -> Instance.List -> IO ()
63
splitInstancesInfo verbose nl il = do
64
  let split_insts = Cluster.findSplitInstances nl il
65
  if (null split_insts)
66
    then
67
      when (verbose > 1) $ do
68
        putStrLn "No split instances found"::IO ()
69
    else do
70
      putStrLn "Found instances belonging to multiple node groups:"
71
      mapM_ (\i -> hPutStrLn stderr $ "  " ++ Instance.name i) split_insts
72

    
73
-- | Print common (interesting) information
74
commonInfo :: Int -> Group.List -> Node.List -> Instance.List -> IO ()
75
commonInfo verbose gl nl il = do
76
  when (Container.null il && verbose > 1) $ do
77
         printf "Cluster is empty.\n"::IO ()
78

    
79
  let nl_size = (Container.size nl)
80
      il_size = (Container.size il)
81
      gl_size = (Container.size gl)
82
  printf "Loaded %d %s, %d %s, %d %s\n"
83
             nl_size (plural nl_size "node" "nodes")
84
             il_size (plural il_size "instance" "instances")
85
             gl_size (plural gl_size "node group" "node groups")::IO ()
86

    
87
  let csf = commonSuffix nl il
88
  when (not (null csf) && verbose > 1) $
89
       printf "Note: Stripping common suffix of '%s' from names\n" csf
90

    
91
-- | Main function.
92
main :: Options -> [String] -> IO ()
93
main opts args = do
94
  unless (null args) $ do
95
         hPutStrLn stderr "Error: this program doesn't take any arguments."
96
         exitWith $ ExitFailure 1
97

    
98
  let verbose = optVerbose opts
99
      shownodes = optShowNodes opts
100
      showinsts = optShowInsts opts
101

    
102
  (ClusterData gl fixed_nl ilf ctags ipol) <- loadExternalData opts
103

    
104
  when (verbose > 1) $ do
105
       putStrLn $ "Loaded cluster tags: " ++ intercalate "," ctags
106
       putStrLn $ "Loaded cluster ipolicy: " ++ show ipol
107
       putStrLn $ "Loaded node groups: " ++ show gl
108

    
109
  nlf <- setNodeStatus opts fixed_nl
110

    
111
  commonInfo verbose gl nlf ilf
112

    
113
  splitInstancesInfo verbose nlf ilf
114

    
115
  maybePrintInsts showinsts "Instances" (Cluster.printInsts nlf ilf)
116

    
117
  maybePrintNodes shownodes "Cluster" (Cluster.printNodes nlf)
118

    
119
  printf "Cluster coefficients:\n%s" (Cluster.printStats "  " nlf)::IO ()
120
  printf "Cluster score: %.8f\n" (Cluster.compCV nlf)