def substitute_ng_ids(cl, ng_dict):
    """Substitute node group template ids for node group template names

    If the cluster template contains node group elements with
    node_group_template_id fields that reference node group templates
    by name, substitute the node group template id for the name.
    The name reference is expected to be a string containing a format
    specifier of the form "{name}", for example "{master}"

    :param cl: a cluster template
    :param ng_dict: a dictionary of node group template ids keyed by
                    node group template names
    """
    for ng in cl['node_groups']:
        if 'node_group_template_id' in ng:
            val = ng['node_group_template_id'].format(**ng_dict)
            ng['node_group_template_id'] = val
