def clone_nodemeister_group(nm_host, dst_gname, src_gname, munge_re=None, noop=False, verbose=False):
    '\n    Clone a group in nodemeister, munging all parameters and class params through munge_re,\n    a list of lists, each having 2 elements, a regex and a string to replace matches with.\n    '
    group_names = get_group_names(nm_host)
    dst_gid = get_nm_group_id(nm_host, dst_gname, groups=group_names)
    if (dst_gid is not False):
        logger.error(('ERROR: group %s already exists in NodeMeister with id %d.' % (dst_gname, dst_gid)))
        return False
    src_group = get_nm_group(nm_host, gname=src_gname, groupnames=group_names)
    if (len(src_group) == 0):
        logger.error(('ERROR: could not find source group %s' % src_gname))
        return False
    if verbose:
        logger.debug('Got source group id: {n}\n{src}'.format(n=src_group['id'], src=src_group))
    classes = get_nm_group_classes(nm_host)
    params = get_nm_group_params(nm_host)
    interp_src_group = interpolate_group(src_group, classes, params, group_names)
    groups = []
    for foo in src_group['groups']:
        bar = get_nm_group_id(nm_host, foo, groups=group_names)
        if bar:
            groups.append(bar)
    gid = add_group(nm_host, dst_gname, ('imported by %s' % __file__), groups=groups, dry_run=noop)
    if (gid is False):
        logger.error('ERROR adding group in Nodemeister.')
        return False
    else:
        logger.info(('Group added to NodeMeister with id %d' % gid))
    ok = True
    for p in src_group['parameters']:
        for (ptn, repl) in munge_re:
            foo = re.sub(ptn, repl, src_group['parameters'][p])
            if ((foo != src_group['parameters'][p]) and verbose):
                logger.debug(("Munged value of '%s' from '%s' to '%s'" % (p, src_group['parameters'][p], foo)))
            src_group['parameters'][p] = foo
        res = add_param_to_group(nm_host, gid, p, src_group['parameters'][p], dry_run=noop)
        if (not res):
            logger.error(("ERROR adding param %s with value '%s' to group %d" % (p, src_group['parameters'][p], gid)))
            ok = False
        if verbose:
            logger.info(("added param %s with value '%s' to group %d" % (p, src_group['parameters'][p], gid)))
    for c in src_group['classes']:
        for (ptn, repl) in munge_re:
            foo = re.sub(ptn, repl, src_group['classes'][c])
            if ((foo != src_group['classes'][c]) and verbose):
                logger.debug(("Munged value of '%s' from '%s' to '%s'" % (c, src_group['classes'][c], foo)))
            src_group['classes'][c] = foo
        res = add_class_to_group(nm_host, gid, c, src_group['classes'][c], dry_run=noop)
        if (not res):
            logger.error(("ERROR adding class %s with value '%s' to group %d" % (c, src_group['classes'][c], gid)))
            ok = False
        if verbose:
            logger.info(("added class %s with value '%s' to group %d" % (c, src_group['classes'][c], gid)))
    if (ok is False):
        logger.critical('cloning group failed.')
        return False
    return gid
Clone a group in nodemeister, munging all parameters and class params through munge_re,
a list of lists, each having 2 elements, a regex and a string to replace matches with.
def clone_nodemeister_group(nm_host, dst_gname, src_gname, munge_re=None, noop=False, verbose=False):
    '\n    Clone a group in nodemeister, munging all parameters and class params through munge_re,\n    a list of lists, each having 2 elements, a regex and a string to replace matches with.\n    '
    group_names = get_group_names(nm_host)
    dst_gid = get_nm_group_id(nm_host, dst_gname, groups=group_names)
    if (dst_gid is not False):
        logger.error(('ERROR: group %s already exists in NodeMeister with id %d.' % (dst_gname, dst_gid)))
        return False
    src_group = get_nm_group(nm_host, gname=src_gname, groupnames=group_names)
    if (len(src_group) == 0):
        logger.error(('ERROR: could not find source group %s' % src_gname))
        return False
    if verbose:
        logger.debug('Got source group id: {n}\n{src}'.format(n=src_group['id'], src=src_group))
    classes = get_nm_group_classes(nm_host)
    params = get_nm_group_params(nm_host)
    interp_src_group = interpolate_group(src_group, classes, params, group_names)
    groups = []
    for foo in src_group['groups']:
        bar = get_nm_group_id(nm_host, foo, groups=group_names)
        if bar:
            groups.append(bar)
    gid = add_group(nm_host, dst_gname, ('imported by %s' % __file__), groups=groups, dry_run=noop)
    if (gid is False):
        logger.error('ERROR adding group in Nodemeister.')
        return False
    else:
        logger.info(('Group added to NodeMeister with id %d' % gid))
    ok = True
    for p in src_group['parameters']:
        for (ptn, repl) in munge_re:
            foo = re.sub(ptn, repl, src_group['parameters'][p])
            if ((foo != src_group['parameters'][p]) and verbose):
                logger.debug(("Munged value of '%s' from '%s' to '%s'" % (p, src_group['parameters'][p], foo)))
            src_group['parameters'][p] = foo
        res = add_param_to_group(nm_host, gid, p, src_group['parameters'][p], dry_run=noop)
        if (not res):
            logger.error(("ERROR adding param %s with value '%s' to group %d" % (p, src_group['parameters'][p], gid)))
            ok = False
        if verbose:
            logger.info(("added param %s with value '%s' to group %d" % (p, src_group['parameters'][p], gid)))
    for c in src_group['classes']:
        for (ptn, repl) in munge_re:
            foo = re.sub(ptn, repl, src_group['classes'][c])
            if ((foo != src_group['classes'][c]) and verbose):
                logger.debug(("Munged value of '%s' from '%s' to '%s'" % (c, src_group['classes'][c], foo)))
            src_group['classes'][c] = foo
        res = add_class_to_group(nm_host, gid, c, src_group['classes'][c], dry_run=noop)
        if (not res):
            logger.error(("ERROR adding class %s with value '%s' to group %d" % (c, src_group['classes'][c], gid)))
            ok = False
        if verbose:
            logger.info(("added class %s with value '%s' to group %d" % (c, src_group['classes'][c], gid)))
    if (ok is False):
        logger.critical('cloning group failed.')
        return False
    return gid