def clone_nodemeister_node(nm_host, dst_name, src_name, munge_res, group_replace=None, noop=False, verbose=False):
    '\n    Clone a node 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\n    group_replace is a hash of old_group_id => new_group_id to replace when creating the new node\n    '
    nodes = get_node_names(nm_host)
    dst_node_id = get_nm_node_id(nm_host, dst_name, nodenames=nodes)
    if (dst_node_id is not False):
        logger.error(('ERROR: node %s already exists in NodeMeister with id %d.' % (dst_name, dst_node_id)))
        return False
    src_node = get_nm_node(nm_host, hostname=src_name, nodenames=nodes)
    if (len(src_node) == 0):
        logger.error(('ERROR: could not find source node %s' % src_name))
        return False
    if verbose:
        logger.debug('Got source node id: {n}\n{src}'.format(n=src_node['id'], src=src_node))
    classes = get_nm_node_classes(nm_host)
    params = get_nm_node_params(nm_host)
    groups = []
    for g in src_node['groups']:
        if (group_replace is not None):
            if (g in group_replace):
                if verbose:
                    logger.debug(('  changing group %d to %d (group_replace)' % (g, group_replace[g])))
                g = group_replace[g]
        groups.append(g)
    node_id = add_node(nm_host, dst_name, ('imported by %s' % __file__), groups=groups, dry_run=noop)
    if (node_id is False):
        logger.error('ERROR adding node in Nodemeister.')
        return False
    else:
        logger.info(('Node added to NodeMeister with id %d' % node_id))
    ok = True
    for c in src_node['excluded_classes']:
        c_name = get_name_for_class_exclusion(nm_host, c, verbose=verbose)
        if verbose:
            logger.debug(('excluded class %s (%d)' % (c_name, c)))
        res = add_node_class_exclusion(nm_host, node_id, c_name, dry_run=noop, verbose=verbose)
        if (not res):
            logger.error(("ERROR adding class exclusion of '%s' to node %d" % (c_name, node_id)))
            ok = False
        if verbose:
            logger.info(("added class_exclusion of '%s' to group %d" % (c_name, node_id)))
    for p in src_node['parameters']:
        for (ptn, repl) in munge_re:
            foo = re.sub(ptn, repl, src_node['parameters'][p])
            if ((foo != src_node['parameters'][p]) and verbose):
                logger.debug(("Munged value of '%s' from '%s' to '%s'" % (p, src_node['parameters'][p], foo)))
            src_node['parameters'][p] = foo
        res = add_param_to_node(nm_host, node_id, p, src_node['parameters'][p], dry_run=noop)
        if (not res):
            logger.error(("ERROR adding param %s with value '%s' to node %d" % (p, src_node['parameters'][p], node_id)))
            ok = False
        if verbose:
            logger.info(("\tadded param %s with value '%s' to group %d" % (p, src_node['parameters'][p], node_id)))
    if (len(src_node['classes']) > 0):
        logger.critical('ERROR: script does not yet migrate classes for nodes.')
        ok = False
    if (ok is False):
        return False
    return node_id
Clone a node 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.

group_replace is a hash of old_group_id => new_group_id to replace when creating the new node
def clone_nodemeister_node(nm_host, dst_name, src_name, munge_res, group_replace=None, noop=False, verbose=False):
    '\n    Clone a node 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\n    group_replace is a hash of old_group_id => new_group_id to replace when creating the new node\n    '
    nodes = get_node_names(nm_host)
    dst_node_id = get_nm_node_id(nm_host, dst_name, nodenames=nodes)
    if (dst_node_id is not False):
        logger.error(('ERROR: node %s already exists in NodeMeister with id %d.' % (dst_name, dst_node_id)))
        return False
    src_node = get_nm_node(nm_host, hostname=src_name, nodenames=nodes)
    if (len(src_node) == 0):
        logger.error(('ERROR: could not find source node %s' % src_name))
        return False
    if verbose:
        logger.debug('Got source node id: {n}\n{src}'.format(n=src_node['id'], src=src_node))
    classes = get_nm_node_classes(nm_host)
    params = get_nm_node_params(nm_host)
    groups = []
    for g in src_node['groups']:
        if (group_replace is not None):
            if (g in group_replace):
                if verbose:
                    logger.debug(('  changing group %d to %d (group_replace)' % (g, group_replace[g])))
                g = group_replace[g]
        groups.append(g)
    node_id = add_node(nm_host, dst_name, ('imported by %s' % __file__), groups=groups, dry_run=noop)
    if (node_id is False):
        logger.error('ERROR adding node in Nodemeister.')
        return False
    else:
        logger.info(('Node added to NodeMeister with id %d' % node_id))
    ok = True
    for c in src_node['excluded_classes']:
        c_name = get_name_for_class_exclusion(nm_host, c, verbose=verbose)
        if verbose:
            logger.debug(('excluded class %s (%d)' % (c_name, c)))
        res = add_node_class_exclusion(nm_host, node_id, c_name, dry_run=noop, verbose=verbose)
        if (not res):
            logger.error(("ERROR adding class exclusion of '%s' to node %d" % (c_name, node_id)))
            ok = False
        if verbose:
            logger.info(("added class_exclusion of '%s' to group %d" % (c_name, node_id)))
    for p in src_node['parameters']:
        for (ptn, repl) in munge_re:
            foo = re.sub(ptn, repl, src_node['parameters'][p])
            if ((foo != src_node['parameters'][p]) and verbose):
                logger.debug(("Munged value of '%s' from '%s' to '%s'" % (p, src_node['parameters'][p], foo)))
            src_node['parameters'][p] = foo
        res = add_param_to_node(nm_host, node_id, p, src_node['parameters'][p], dry_run=noop)
        if (not res):
            logger.error(("ERROR adding param %s with value '%s' to node %d" % (p, src_node['parameters'][p], node_id)))
            ok = False
        if verbose:
            logger.info(("\tadded param %s with value '%s' to group %d" % (p, src_node['parameters'][p], node_id)))
    if (len(src_node['classes']) > 0):
        logger.critical('ERROR: script does not yet migrate classes for nodes.')
        ok = False
    if (ok is False):
        return False
    return node_id