Revision da28218d htools/Ganeti/HTools/Program/Hinfo.hs

b/htools/Ganeti/HTools/Program/Hinfo.hs
59 59
  , oShowHelp
60 60
  ]
61 61

  
62
-- | Group information data-type.
63
data GroupInfo = GroupInfo { giName      :: String
64
                           , giNodeCount :: Int
65
                           , giInstCount :: Int
66
                           , giBadNodes  :: Int
67
                           , giBadInsts  :: Int
68
                           , giN1Status  :: Bool
69
                           }
70

  
62 71
-- | Node group statistics.
63 72
calcGroupInfo :: Group.Group
64 73
              -> Node.List
65 74
              -> Instance.List
66
              -> (String, (Int, Int), (Int, Int), Bool)
75
              -> GroupInfo
67 76
calcGroupInfo g nl il =
68 77
  let nl_size                    = Container.size nl
69 78
      il_size                    = Container.size il
......
71 80
      bn_size                    = length bad_nodes
72 81
      bi_size                    = length bad_instances
73 82
      n1h                        = bn_size == 0
74
  in (Group.name g, (nl_size, il_size), (bn_size, bi_size), n1h)
83
  in GroupInfo (Group.name g) nl_size il_size bn_size bi_size n1h
75 84

  
76 85
-- | Helper to format one group row result.
77
groupRowFormatHelper :: (String, (Int, Int), (Int, Int), Bool) -> [String]
78
groupRowFormatHelper (gname, (nl_size, il_size), (bn_size, bi_size), n1h) =
79
  [ gname
80
  , printf "%d" nl_size
81
  , printf "%d" il_size
82
  , printf "%d" bn_size
83
  , printf "%d" bi_size
84
  , show n1h ]
86
groupRowFormatHelper :: GroupInfo -> [String]
87
groupRowFormatHelper gi =
88
  [ giName gi
89
  , printf "%d" $ giNodeCount gi
90
  , printf "%d" $ giInstCount gi
91
  , printf "%d" $ giBadNodes gi
92
  , printf "%d" $ giBadInsts gi
93
  , show $ giN1Status gi
94
  ]
85 95

  
86 96
-- | Print node group information.
87 97
showGroupInfo :: Int -> Group.List -> Node.List -> Instance.List -> IO ()
......
89 99
  let cgrs   = map (\(gdx, (gnl, gil)) ->
90 100
                 calcGroupInfo (Container.find gdx gl) gnl gil) $
91 101
                 Cluster.splitCluster nl il
92
      cn1h   = all (\(_, _, _, n1h) -> n1h) cgrs
102
      cn1h   = all giN1Status cgrs
93 103
      grs    = map groupRowFormatHelper cgrs
94 104
      header = ["Group", "Nodes", "Instances", "Bad_Nodes", "Bad_Instances",
95 105
                "N+1"]

Also available in: Unified diff