IVSSwitch: support running IVS in a namespace

This change uses the `Node.cmd` method instead of `Popen`. The `cmd` method
sends the input to a shell which may be in another namespace (if --innamespace
is in use), while `Popen` would always run in the root namespace.
This commit is contained in:
Rich Lane
2013-07-18 17:50:52 -07:00
parent 5c24263779
commit 0a54360211
+4 -10
View File
@@ -1023,7 +1023,6 @@ class IVSSwitch(Switch):
def __init__( self, name, **kwargs ): def __init__( self, name, **kwargs ):
Switch.__init__( self, name, **kwargs ) Switch.__init__( self, name, **kwargs )
self.process = None
@classmethod @classmethod
def setup( cls ): def setup( cls ):
@@ -1052,18 +1051,13 @@ class IVSSwitch(Switch):
if self.listenPort: if self.listenPort:
args.extend( ['--listen', '127.0.0.1:%i' % self.listenPort] ) args.extend( ['--listen', '127.0.0.1:%i' % self.listenPort] )
with open( '/tmp/ivs.%s.log' % self.name, 'w' ) as logfile: logfile = '/tmp/ivs.%s.log' % self.name
with open( '/dev/null', 'w' ) as nullfile:
self.process = Popen( args, stdout=logfile, stderr=STDOUT, self.cmd( ' '.join(args) + ' >' + logfile + ' 2>&1 </dev/null &' )
stdin=nullfile, preexec_fn=os.setsid )
self.execed = False
def stop( self ): def stop( self ):
"Terminate IVS switch." "Terminate IVS switch."
if self.process: self.cmd( 'kill %ivs' )
self.process.terminate()
self.process.wait()
self.process = None
self.deleteIntfs() self.deleteIntfs()
def attach( self, intf ): def attach( self, intf ):