On Tue, Feb 21, 2012 at 12:21 PM, Iustin Pop <[email protected]> wrote:

> +-- | Builds link -> ip -> instname map.
> +buildLinkIpInstnameMap :: ConfigData -> LinkIpMap
> +buildLinkIpInstnameMap cfg =
> +  let cluster = configCluster cfg
> +      instances = M.elems . configInstances $ cfg
> +      defparams = (M.!) (clusterNicparams cluster) C.ppDefault
> +      nics = concatMap (\i -> [(instName i, nic) | nic <- instNics i])
> +             instances
> +  in foldl' (\accum (iname, nic) ->
> +               let pparams = nicNicparams nic
> +                   fparams = fillNICParams defparams pparams
> +                   link = nicpLink fparams
> +               in case nicIp nic of
> +                    Nothing -> accum
> +                    Just ip -> let oldipmap = M.findWithDefault (M.empty)
> +                                              link accum
> +                                   newipmap = M.insert ip iname oldipmap
> +                               in M.insert link newipmap accum
> +            ) M.empty nics

So, looking some more at this function:

  - could we have a way to fetch the instances from the config with
already filled params? This would definitely help simplifying this
function.
  - maybe we can abstract the [instances] to [(nic, instance_name)] part?
  - maybe we can have a function from instance (or nic, instance_name)
to link -> (...) composed with a function from instance to ip ->
instance_name to simplify it a bit

Does this make sense? Shall I give it a try?

Thanks,

Guido

Reply via email to