customize makeIntfPair to eliminate fastIntfPair
This commit is contained in:
+13
-29
@@ -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 )
|
||||||
|
|
||||||
|
|||||||
+25
-9
@@ -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"""
|
||||||
|
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
|
# Delete any old interfaces with the same names
|
||||||
runCmd( 'ip link del ' + intf1 )
|
runCmd( 'ip link del ' + intf1 )
|
||||||
runCmd( 'ip link del ' + intf2 )
|
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user