From e5cb098ccbf2f8788d2654921c638365431df159 Mon Sep 17 00:00:00 2001 From: Agata Murawska <agatamurawska@google.com> Date: Thu, 20 Sep 2012 15:15:11 +0200 Subject: [PATCH] Config support for NodeGroup query For some results in nodegroup queries we need agregation similar to one that is done for nodes. Signed-off-by: Agata Murawska <agatamurawska@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- htools/Ganeti/Config.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/htools/Ganeti/Config.hs b/htools/Ganeti/Config.hs index 49a3f03fa..f88ba8a68 100644 --- a/htools/Ganeti/Config.hs +++ b/htools/Ganeti/Config.hs @@ -36,6 +36,9 @@ module Ganeti.Config , getInstance , getGroup , getGroupNdParams + , getGroupIpolicy + , getGroupNodes + , getGroupInstances , getGroupOfNode , getInstPrimaryNode , getInstMinorsForNode @@ -168,6 +171,24 @@ getGroupNdParams :: ConfigData -> NodeGroup -> FilledNDParams getGroupNdParams cfg ng = fillNDParams (clusterNdparams $ configCluster cfg) (groupNdparams ng) +-- | Computes a node group's ipolicy. +getGroupIpolicy :: ConfigData -> NodeGroup -> FilledIPolicy +getGroupIpolicy cfg ng = + fillIPolicy (clusterIpolicy $ configCluster cfg) (groupIpolicy ng) + +-- | Get nodes of a given node group. +getGroupNodes :: ConfigData -> String -> [Node] +getGroupNodes cfg gname = + let all_nodes = M.elems . fromContainer . configNodes $ cfg in + filter ((==gname) . nodeGroup) all_nodes + +-- | Get (primary, secondary) instances of a given node group. +getGroupInstances :: ConfigData -> String -> ([Instance], [Instance]) +getGroupInstances cfg gname = + let gnodes = map nodeName (getGroupNodes cfg gname) + ginsts = map (getNodeInstances cfg) gnodes in + (concatMap fst ginsts, concatMap snd ginsts) + -- | Looks up an instance's primary node. getInstPrimaryNode :: ConfigData -> String -> Result Node getInstPrimaryNode cfg name = -- GitLab