Modified to allow execed nodes to work, if we ever reinstate them.
This commit is contained in:
+24
-13
@@ -12,35 +12,46 @@ from subprocess import Popen
|
|||||||
from mininet.log import error
|
from mininet.log import error
|
||||||
from mininet.util import quietRun
|
from mininet.util import quietRun
|
||||||
|
|
||||||
|
def joinCmd( args ):
|
||||||
|
"Join args into a string, single-quoting items with spaces."
|
||||||
|
result = ''
|
||||||
|
for arg in args:
|
||||||
|
if ' ' in item:
|
||||||
|
result += " '%s'" % arg
|
||||||
|
else:
|
||||||
|
result += " %s" % arg
|
||||||
|
return result
|
||||||
|
|
||||||
def makeTerm( node, title = '', term = 'xterm' ):
|
def makeTerm( node, title = '', term = 'xterm' ):
|
||||||
"""Run screen on a node, and hook up an xterm.
|
"""Run screen on a node, and hook up a terminal.
|
||||||
node: Node object
|
node: Node object
|
||||||
title: base title
|
title: base title
|
||||||
|
term: 'xterm' or 'gterm'
|
||||||
returns: process created"""
|
returns: process created"""
|
||||||
title += ': ' + node.name
|
title += ': ' + node.name
|
||||||
if not node.inNamespace:
|
if not node.inNamespace:
|
||||||
title += ' (root)'
|
title += ' (root)'
|
||||||
cmd = ''
|
cmds = {
|
||||||
if term == 'xterm':
|
'xterm': [ 'xterm', '-title', title, '-e' ],
|
||||||
cmd = [ 'xterm', '-title', title, '-e' ]
|
'gterm': [ 'gnome-terminal', '--title', title, '-e' ]
|
||||||
elif term == 'gnome':
|
}
|
||||||
cmd = [ 'gnome-terminal', '--title', title, '-e' ]
|
if term not in cmds:
|
||||||
else:
|
|
||||||
error( 'invalid terminal type: %s' % term )
|
error( 'invalid terminal type: %s' % term )
|
||||||
return
|
return
|
||||||
if not node.execed:
|
if not node.execed:
|
||||||
node.cmd( 'screen -dmS ' + node.name)
|
node.cmd( 'screen -dmS ' + node.name)
|
||||||
#cmd += [ 'screen', '-D', '-RR', '-S', node.name ]
|
args = [ 'screen', '-D', '-RR', '-S', 'mininet.' + node.name ]
|
||||||
|
else:
|
||||||
|
args = [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
|
||||||
|
if term == 'gterm':
|
||||||
# Compress these for gnome-terminal, which expects one token to follow
|
# Compress these for gnome-terminal, which expects one token to follow
|
||||||
# the -e option .
|
# the -e option .
|
||||||
cmd += [ 'screen -D -RR -S ' + node.name ]
|
args = joinCmd( args )
|
||||||
else:
|
return Popen( cmds[ term ] + args )
|
||||||
cmd += [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
|
|
||||||
return Popen( cmd )
|
|
||||||
|
|
||||||
def cleanUpScreens():
|
def cleanUpScreens():
|
||||||
"Remove moldy old screen sessions."
|
"Remove moldy old screen sessions."
|
||||||
r = r'(\d+.[hsc]\d+)'
|
r = r'(\d+which .[hsc]\d+)'
|
||||||
output = quietRun( 'screen -ls' ).split( '\n' )
|
output = quietRun( 'screen -ls' ).split( '\n' )
|
||||||
for line in output:
|
for line in output:
|
||||||
m = re.search( r, line )
|
m = re.search( r, line )
|
||||||
|
|||||||
Reference in New Issue
Block a user