Skip to content
Snippets Groups Projects
Commit 4cd428db authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent a9ccc950
No related branches found
No related tags found
No related merge requests found
......@@ -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 =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment