From 4cd428db90b1f59b39523d918d225e4536ec19d6 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 19 Aug 2012 02:11:49 +0200 Subject: [PATCH] Config.hs: Add a function to lookup group Like in the python code, this is a bit more complex since groups are indexed by UUID, so we must fallback to lookup via the name (slow; but the number of groups should be small). Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Agata Murawska <agatamurawska@google.com> --- htools/Ganeti/Config.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/htools/Ganeti/Config.hs b/htools/Ganeti/Config.hs index 0a55b574d..04c9d118e 100644 --- a/htools/Ganeti/Config.hs +++ b/htools/Ganeti/Config.hs @@ -31,6 +31,7 @@ module Ganeti.Config , getInstancesIpByLink , getNode , getInstance + , getGroup , getInstPrimaryNode , getInstMinorsForNode , buildLinkIpInstnameMap @@ -132,6 +133,18 @@ getInstance :: ConfigData -> String -> Result Instance getInstance cfg name = getItem "Instance" name (fromContainer $ configInstances cfg) +-- | Looks up a node group. This is more tricky than for +-- node/instances since the groups map is indexed by uuid, not name. +getGroup :: ConfigData -> String -> Result NodeGroup +getGroup cfg name = + let groups = fromContainer (configNodegroups cfg) + in case getItem "NodeGroup" name groups of + -- if not found by uuid, we need to look it up by name, slow + Ok grp -> Ok grp + Bad _ -> let by_name = M.mapKeys + (\k -> groupName ((M.!) groups k )) groups + in getItem "NodeGroup" name by_name + -- | Looks up an instance's primary node. getInstPrimaryNode :: ConfigData -> String -> Result Node getInstPrimaryNode cfg name = -- GitLab