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

customize makeIntfPair to eliminate fastIntfPair

parent da4dcf37
No related branches found
No related tags found
No related merge requests found
......@@ -415,8 +415,8 @@ def __init__( self, node1, node2, port1=None, port2=None,
if fast:
params1.setdefault( 'moveIntfFn', self._ignore )
params2.setdefault( 'moveIntfFn', self._ignore )
self.fastIntfPair( intfName1, intfName2, addr1, addr2,
node1=node1, node2=node2)
self.makeIntfPair( intfName1, intfName2, addr1, addr2,
node1, node2, deleteIntfs=False )
else:
self.makeIntfPair( intfName1, intfName2, addr1, addr2 )
......@@ -446,35 +446,21 @@ def intfName( self, node, n ):
return node.name + '-eth' + repr( n )
@classmethod
def makeIntfPair( cls, intfname1, intfname2, addr1=None, addr2=None ):
def makeIntfPair( cls, intfname1, intfname2, addr1=None, addr2=None,
node1=None, node2=None, deleteIntfs=True ):
"""Create pair of interfaces
intfname1: name of interface 1
intfname2: name of interface 2
intfname1: name for interface 1
intfname2: name for interface 2
addr1: MAC address for interface 1 (optional)
addr2: MAC address for interface 2 (optional)
node1: home node for interface 1 (optional)
node2: home node for interface 2 (optional)
(override this method [and possibly delete()]
to change link type)"""
# Leave this as a class method for now
assert cls
return makeIntfPair( intfname1, intfname2, addr1, addr2 )
@classmethod
def fastIntfPair( cls, intfname1, intfname2, addr1=None, addr2=None,
node1=None, node2=None ):
"""Create pair of interfaces
'fast' version: no checking, only works with Nodes.
intf1: name of interface 1
intf2: name of interface 2
(override this class method [and possibly delete()]
to change link type)"""
if addr1 is None and addr2 is None:
return node1.cmd( 'ip link add name', intfname1,
'type veth peer name',
intfname2, 'netns', node2.pid )
else:
return node1.cmd( 'ip link add name', intfname1,
'address', addr1,
'type veth peer name', intfname2,
'address', addr2,
'netns', node2.pid )
return makeIntfPair( intfname1, intfname2, addr1, addr2, node1, node2,
deleteIntfs=deleteIntfs )
def delete( self ):
"Delete this link"
......@@ -519,12 +505,10 @@ def __init__( self, node1, node2, **kwargs ):
kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
Link.__init__( self, node1, node2, **kwargs )
def fastIntfPair( self, *args, **kwargs ):
def makeIntfPair( self, *args, **kwargs ):
"Usually delegated to OVSSwitch"
if self.isPatchLink:
return None, None
elif self.fast:
return Link.fastIntfPair( *args, **kwargs )
else:
return Link.makeIntfPair( *args, **kwargs )
......
......@@ -145,22 +145,38 @@ def isShellBuiltin( cmd ):
# live in the root namespace and thus do not have to be
# explicitly moved.
def makeIntfPair( intf1, intf2, addr1=None, addr2=None, runCmd=quietRun ):
"""Make a veth pair connecting intf1 and intf2.
intf1: string, interface
intf2: string, interface
def makeIntfPair( intf1, intf2, addr1=None, addr2=None, node1=None, node2=None,
deleteIntfs=True, runCmd=None ):
"""Make a veth pair connnecting new interfaces intf1 and intf2
intf1: name for interface 1
intf2: name for interface 2
addr1: MAC address for interface 1 (optional)
addr2: MAC address for interface 2 (optional)
node1: home node for interface 1 (optional)
node2: home node for interface 2 (optional)
deleteIntfs: delete intfs before creating them
runCmd: function to run shell commands (quietRun)
returns: ip link add result"""
# Delete any old interfaces with the same names
runCmd( 'ip link del ' + intf1 )
runCmd( 'ip link del ' + intf2 )
if not runCmd:
runCmd = quietRun if not node1 else node1.cmd
runCmd2 = quietRun if not node2 else node2.cmd
if deleteIntfs:
# Delete any old interfaces with the same names
runCmd( 'ip link del ' + intf1 )
runCmd2( 'ip link del ' + intf2 )
# Create new pair
netns = 1 if not node2 else node2.pid
if addr1 is None and addr2 is None:
cmd = 'ip link add name ' + intf1 + ' type veth peer name ' + intf2
cmdOutput = runCmd( 'ip link add name %s '
'type veth peer name %s '
'netns %s' % ( intf1, intf2, netns ) )
else:
cmd = ( 'ip link add name ' + intf1 + ' address ' + addr1 +
' type veth peer name ' + intf2 + ' address ' + addr2 )
cmdOutput = runCmd( cmd )
cmdOutput = runCmd( 'ip link add name %s '
'address %s '
'type veth peer name %s '
'address %s '
'netns %s' %
( intf1, addr1, intf2, addr2, netns ) )
if cmdOutput == '':
return True
else:
......
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