nodemap.py
def make_changes(changes, func=call):
    """ Make changes to the live nodemap config as output from diff().
    
        Pass a print function as `func` to output the commands which would normally be run.
    """

    # Unlike other diff functions this is more nodemap-specific, e.g. knows that when nodemap don't need to recurse into parameters, just delete the whole thing.

    deleted_nodemaps = []
    for (keypath, action, value) in changes:
        #print('#', keypath, action, repr(value))
        if keypath[0] != 'nodemap':
            raise ValueError("'nodemap' not at start of key path %s: is this a nodemap diff?" % keypath)
        
        nodemap = keypath[1]
        
        if len(keypath) == 2:
            if nodemap == 'active': # not really a nodemap
                if action == 'ADD': # don't care about what it was
                    func(NODEMAP_ACTIVATE.format(new=value))
            else: # nodemap add/delete
                func(NODEMAP_EXISTS.format(name=nodemap, mode=action.lower()))
                if action == 'DEL':
                    deleted_nodemaps.append(nodemap)
        else:
            if nodemap not in deleted_nodemaps: # can't changed properties if we've deleted it!
                param = keypath[2]
                if param == 'fileset' and action == 'ADD': # can ignore delete on these, just overwrite
                    func(NODEMAP_SET_FILESET.format(nodemap=nodemap, new=value))
                elif param in NODEMAP_MODIFY_PARAMS and action == 'ADD':
                    func(NODEMAP_MODIFY.format(nodemap=nodemap, property=param, new=value))
                elif param == 'admin_nodemap' and action == 'ADD':
                    func(NODEMAP_SET_ADMIN.format(nodemap=nodemap, new=value))
                elif param == 'trusted_nodemap' and action == 'ADD':
                    func(NODEMAP_SET_TRUSTED.format(nodemap=nodemap, new=value))
                elif param == 'idmap': # don't ignore delete as need to get rid of old ones
                    for idmap in value:
                        func(NODEMAP_CHANGE_IDMAP.format(mode=action.lower(), nodemap=nodemap, **idmap))
                elif param == 'ranges': # again need to delete old ones
                    for rng in value:
                        pattern = range_to_pattern(rng['start_nid'], rng['end_nid'])
                        func(NODEMAP_CHANGE_RANGE.format(mode=action.lower(), nodemap=nodemap, nid='{pattern}'.format(pattern=pattern)))
 Make changes to the live nodemap config as output from diff().
    
        Pass a print function as `func` to output the commands which would normally be run.
    
Make changes to the live nodemap config as output from diff().
Pass a print function as `func` to output the commands which would normally be run.
Make changes to the live nodemap config as output from diff () . Pass a print function as ` func ` to output the commands which would normally be run .
def make_changes(changes, func=call):
    deleted_nodemaps = []
    for (keypath, action, value) in changes:
        if keypath[0] != 'nodemap':
            raise ValueError("'nodemap' not at start of key path %s: is this a nodemap diff?" % keypath)
        nodemap = keypath[1]
        if len(keypath) == 2:
            if nodemap == 'active': 
                if action == 'ADD': 
                    func(NODEMAP_ACTIVATE.format(new=value))
            else: 
                func(NODEMAP_EXISTS.format(name=nodemap, mode=action.lower()))
                if action == 'DEL':
                    deleted_nodemaps.append(nodemap)
        else:
            if nodemap not in deleted_nodemaps: 
                param = keypath[2]
                if param == 'fileset' and action == 'ADD': 
                    func(NODEMAP_SET_FILESET.format(nodemap=nodemap, new=value))
                elif param in NODEMAP_MODIFY_PARAMS and action == 'ADD':
                    func(NODEMAP_MODIFY.format(nodemap=nodemap, property=param, new=value))
                elif param == 'admin_nodemap' and action == 'ADD':
                    func(NODEMAP_SET_ADMIN.format(nodemap=nodemap, new=value))
                elif param == 'trusted_nodemap' and action == 'ADD':
                    func(NODEMAP_SET_TRUSTED.format(nodemap=nodemap, new=value))
                elif param == 'idmap': 
                    for idmap in value:
                        func(NODEMAP_CHANGE_IDMAP.format(mode=action.lower(), nodemap=nodemap, **idmap))
                elif param == 'ranges': 
                    for rng in value:
                        pattern = range_to_pattern(rng['start_nid'], rng['end_nid'])
                        func(NODEMAP_CHANGE_RANGE.format(mode=action.lower(), nodemap=nodemap, nid='{pattern}'.format(pattern=pattern)))
def make_changes ( changes , func = call ) : deleted_nodemaps = [ ] for ( keypath , action , value ) in changes : if keypath [ 0 ] != 'nodemap' : raise ValueError ( "'nodemap' not at start of key path %s: is this a nodemap diff?" % keypath ) nodemap = keypath [ 1 ] if len ( keypath ) == 2 : if nodemap == 'active' : if action == 'ADD' : func ( NODEMAP_ACTIVATE . format ( new = value ) ) else : func ( NODEMAP_EXISTS . format ( name = nodemap , mode = action . lower ( ) ) ) if action == 'DEL' : deleted_nodemaps . append ( nodemap ) else : if nodemap not in deleted_nodemaps : param = keypath [ 2 ] if param == 'fileset' and action == 'ADD' : func ( NODEMAP_SET_FILESET . format ( nodemap = nodemap , new = value ) ) elif param in NODEMAP_MODIFY_PARAMS and action == 'ADD' : func ( NODEMAP_MODIFY . format ( nodemap = nodemap , property = param , new = value ) ) elif param == 'admin_nodemap' and action == 'ADD' : func ( NODEMAP_SET_ADMIN . format ( nodemap = nodemap , new = value ) ) elif param == 'trusted_nodemap' and action == 'ADD' : func ( NODEMAP_SET_TRUSTED . format ( nodemap = nodemap , new = value ) ) elif param == 'idmap' : for idmap in value : func ( NODEMAP_CHANGE_IDMAP . format ( mode = action . lower ( ) , nodemap = nodemap , ** idmap ) ) elif param == 'ranges' : for rng in value : pattern = range_to_pattern ( rng [ 'start_nid' ] , rng [ 'end_nid' ] ) func ( NODEMAP_CHANGE_RANGE . format ( mode = action . lower ( ) , nodemap = nodemap , nid = '{pattern}' . format ( pattern = pattern ) ) )
Make changes to the live nodemap config as output from diff().
Make changes to the live nodemap config as output from diff () .
""" Make changes to the live nodemap config as output from diff().
    
        Pass a print function as `func` to output the commands which would normally be run.
    """ # Unlike other diff functions this is more nodemap-specific, e.g. knows that when nodemap don't need to recurse into parameters, just delete the whole thing. #print('#', keypath, action, repr(value)) # not really a nodemap # don't care about what it was # nodemap add/delete # can't changed properties if we've deleted it! # can ignore delete on these, just overwrite # don't ignore delete as need to get rid of old ones # again need to delete old ones
changes
func