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
This commit is contained in:
Bob Lantz
2013-03-24 16:14:04 -07:00
parent 477e84adba
commit c771b2d75a
+16 -8
View File
@@ -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
srcNode: source Node or None (default) for root ns
printError: if true, print error""" printError: if true, print error"""
cmd = 'ip link set ' + intf + ' netns ' + repr( node.pid ) intf = str( intf )
cmd = 'ip link set %s netns %s' % ( intf, dstNode.pid )
if srcNode:
srcNode.cmd( cmd )
else:
quietRun( cmd ) quietRun( cmd )
links = node.cmd( 'ip link show' ) 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