On Tue, Aug 21, 2012 at 3:06 PM, Iustin Pop <[email protected]> wrote:
>
> 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 <[email protected]>
> ---
>  htools/Ganeti/Config.hs |   13 +++++++++++++
>  1 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/htools/Ganeti/Config.hs b/htools/Ganeti/Config.hs
> index 0a55b57..04c9d11 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 =
> --
> 1.7.7.3
>

LGTM

Reply via email to