customize makeIntfPair to eliminate fastIntfPair

This commit is contained in:
Bob Lantz
2015-01-15 02:07:00 -08:00
parent da4dcf3753
commit 7a4a865bdb
2 changed files with 40 additions and 40 deletions
+13 -29
View File
@@ -415,8 +415,8 @@ class Link( object ):
if fast: if fast:
params1.setdefault( 'moveIntfFn', self._ignore ) params1.setdefault( 'moveIntfFn', self._ignore )
params2.setdefault( 'moveIntfFn', self._ignore ) params2.setdefault( 'moveIntfFn', self._ignore )
self.fastIntfPair( intfName1, intfName2, addr1, addr2, self.makeIntfPair( intfName1, intfName2, addr1, addr2,
node1=node1, node2=node2) node1, node2, deleteIntfs=False )
else: else:
self.makeIntfPair( intfName1, intfName2, addr1, addr2 ) self.makeIntfPair( intfName1, intfName2, addr1, addr2 )
@@ -446,35 +446,21 @@ class Link( object ):
return node.name + '-eth' + repr( n ) return node.name + '-eth' + repr( n )
@classmethod @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 """Create pair of interfaces
intfname1: name of interface 1 intfname1: name for interface 1
intfname2: name of interface 2 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()] (override this method [and possibly delete()]
to change link type)""" to change link type)"""
# Leave this as a class method for now # Leave this as a class method for now
assert cls assert cls
return makeIntfPair( intfname1, intfname2, addr1, addr2 ) return makeIntfPair( intfname1, intfname2, addr1, addr2, node1, node2,
deleteIntfs=deleteIntfs )
@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 )
def delete( self ): def delete( self ):
"Delete this link" "Delete this link"
@@ -519,12 +505,10 @@ class OVSLink( Link ):
kwargs.update( cls1=OVSIntf, cls2=OVSIntf ) kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
Link.__init__( self, node1, node2, **kwargs ) Link.__init__( self, node1, node2, **kwargs )
def fastIntfPair( self, *args, **kwargs ): def makeIntfPair( self, *args, **kwargs ):
"Usually delegated to OVSSwitch" "Usually delegated to OVSSwitch"
if self.isPatchLink: if self.isPatchLink:
return None, None return None, None
elif self.fast:
return Link.fastIntfPair( *args, **kwargs )
else: else:
return Link.makeIntfPair( *args, **kwargs ) return Link.makeIntfPair( *args, **kwargs )
+27 -11
View File
@@ -145,22 +145,38 @@ isShellBuiltin.builtIns = None
# live in the root namespace and thus do not have to be # live in the root namespace and thus do not have to be
# explicitly moved. # explicitly moved.
def makeIntfPair( intf1, intf2, addr1=None, addr2=None, runCmd=quietRun ): def makeIntfPair( intf1, intf2, addr1=None, addr2=None, node1=None, node2=None,
"""Make a veth pair connecting intf1 and intf2. deleteIntfs=True, runCmd=None ):
intf1: string, interface """Make a veth pair connnecting new interfaces intf1 and intf2
intf2: string, interface 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) runCmd: function to run shell commands (quietRun)
returns: ip link add result""" returns: ip link add result"""
# Delete any old interfaces with the same names if not runCmd:
runCmd( 'ip link del ' + intf1 ) runCmd = quietRun if not node1 else node1.cmd
runCmd( 'ip link del ' + intf2 ) 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 # Create new pair
netns = 1 if not node2 else node2.pid
if addr1 is None and addr2 is None: 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: else:
cmd = ( 'ip link add name ' + intf1 + ' address ' + addr1 + cmdOutput = runCmd( 'ip link add name %s '
' type veth peer name ' + intf2 + ' address ' + addr2 ) 'address %s '
cmdOutput = runCmd( cmd ) 'type veth peer name %s '
'address %s '
'netns %s' %
( intf1, addr1, intf2, addr2, netns ) )
if cmdOutput == '': if cmdOutput == '':
return True return True
else: else: