diff --git a/htools/Ganeti/Config.hs b/htools/Ganeti/Config.hs index 0a55b574de913c98ab69097baf792e46aaa4194f..04c9d118e0965583412aa242748ee81b4db870c4 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 =