Skip to content
Snippets Groups Projects
Commit c771b2d7 authored by Bob Lantz's avatar Bob Lantz
Browse files

Add source node option to moveIntf() (note: low-level API!!)

In the future we may wish to enable moving interfaces across
nodes which are not in the root NS, and this would provide
the low-level mechanism to do so.
closes #122
parent 477e84ad
No related branches found
No related tags found
No related merge requests found
...@@ -171,27 +171,35 @@ def retry( retries, delaySecs, fn, *args, **keywords ): ...@@ -171,27 +171,35 @@ def retry( retries, delaySecs, fn, *args, **keywords ):
error( "*** gave up after %i retries\n" % tries ) error( "*** gave up after %i retries\n" % tries )
exit( 1 ) exit( 1 )
def moveIntfNoRetry( intf, node, printError=False ): def moveIntfNoRetry( intf, dstNode, srcNode=None, printError=False ):
"""Move interface to node, without retrying. """Move interface to node, without retrying.
intf: string, interface intf: string, interface
node: Node object dstNode: destination Node
printError: if true, print error""" srcNode: source Node or None (default) for root ns
cmd = 'ip link set ' + intf + ' netns ' + repr( node.pid ) printError: if true, print error"""
quietRun( cmd ) intf = str( intf )
links = node.cmd( 'ip link show' ) cmd = 'ip link set %s netns %s' % ( intf, dstNode.pid )
if srcNode:
srcNode.cmd( cmd )
else:
quietRun( cmd )
links = dstNode.cmd( 'ip link show' )
if not ( ' %s:' % intf ) in links: if not ( ' %s:' % intf ) in links:
if printError: if printError:
error( '*** Error: moveIntf: ' + intf + error( '*** Error: moveIntf: ' + intf +
' not successfully moved to ' + node.name + '\n' ) ' not successfully moved to ' + dstNode.name + '\n' )
return False return False
return True return True
def moveIntf( intf, node, printError=False, retries=3, delaySecs=0.001 ): def moveIntf( intf, dstNode, srcNode=None, printError=False,
retries=3, delaySecs=0.001 ):
"""Move interface to node, retrying on failure. """Move interface to node, retrying on failure.
intf: string, interface intf: string, interface
node: Node object dstNode: destination Node
srcNode: source Node or None (default) for root ns
printError: if true, print error""" printError: if true, print error"""
retry( retries, delaySecs, moveIntfNoRetry, intf, node, printError ) retry( retries, delaySecs, moveIntfNoRetry, intf, dstNode,
srcNode=srcNode, printError=printError )
# Support for dumping network # Support for dumping network
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment