--- I'm not sure about the line breaks, please let me know if there's a better line wrap htools/Ganeti/HTools/Program/Hinfo.hs | 41 +++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/htools/Ganeti/HTools/Program/Hinfo.hs b/htools/Ganeti/HTools/Program/Hinfo.hs index ba26746..600440c 100644 --- a/htools/Ganeti/HTools/Program/Hinfo.hs +++ b/htools/Ganeti/HTools/Program/Hinfo.hs @@ -58,6 +58,45 @@ options = , oShowHelp ] +-- | Node group statistics +calcGroupInfo :: Group.Group -> Node.List -> Instance.List -> ( String + , (Int, Int) + , (Int, Int) + , Bool ) +calcGroupInfo g nl il = + let nl_size = (Container.size nl) + il_size = (Container.size il) + (bad_nodes, bad_instances) = Cluster.computeBadItems nl il + bn_size = length bad_nodes + bi_size = length bad_instances + n1h = bn_size == 0 + in (Group.name g, (nl_size, il_size), (bn_size, bi_size), n1h) + +-- | Helper to format one group row result +groupRowFormatHelper :: Group.Group -> Node.List -> Instance.List -> [String] +groupRowFormatHelper g nl il = + let (gname, (nl_size, il_size), (bn_size, bi_size), n1h) = (calcGroupInfo g + nl + il) + in [ gname + , printf "%d" nl_size + , printf "%d" il_size + , printf "%d" bn_size + , printf "%d" bi_size + , show n1h ] + +-- | Print node group information +groupInfo :: Group.List -> Node.List -> Instance.List -> IO () +groupInfo gl nl il = do + let grs = map (\(gdx, (gnl, gil)) -> + groupRowFormatHelper (Container.find gdx gl) gnl gil) $ + Cluster.splitCluster nl il + header = ["Group", "Nodes", "Instances", "Bad_Nodes", "Bad_Instances", + "N+1"] + + printf "Node group information:\n%s" + (printTable " " header grs [False, True, True, True, True, False]) + -- | Gather and print split instances splitInstancesInfo :: Int -> Node.List -> Instance.List -> IO () splitInstancesInfo verbose nl il = do @@ -112,6 +151,8 @@ main opts args = do splitInstancesInfo verbose nlf ilf + groupInfo gl nlf ilf + maybePrintInsts showinsts "Instances" (Cluster.printInsts nlf ilf) maybePrintNodes shownodes "Cluster" (Cluster.printNodes nlf) -- 1.7.7.3