Add 'x' command to open an X11 tunnel (and run a client)

fixes #142
This commit is contained in:
Bob Lantz
2013-05-28 22:10:27 -07:00
parent f53866d0c0
commit e3d07bc1a0
2 changed files with 18 additions and 1 deletions
+12 -1
View File
@@ -33,7 +33,7 @@ import sys
import time import time
from mininet.log import info, output, error from mininet.log import info, output, error
from mininet.term import makeTerms from mininet.term import makeTerms, runX11
from mininet.util import quietRun, isShellBuiltin, dumpNodeConnections from mininet.util import quietRun, isShellBuiltin, dumpNodeConnections
class CLI( Cmd ): class CLI( Cmd ):
@@ -241,6 +241,17 @@ class CLI( Cmd ):
node = self.nodemap[ arg ] node = self.nodemap[ arg ]
self.mn.terms += makeTerms( [ node ], term = term ) self.mn.terms += makeTerms( [ node ], term = term )
def do_x( self, line ):
"""Create an X11 tunnel to the given node,
optionally starting a client."""
args = line.split()
if not args:
error( 'usage: x node [cmd args]...\n' )
else:
node = self.mn[ args[ 0 ] ]
cmd = args[ 1: ]
self.mn.terms += runX11( node, cmd )
def do_gterm( self, line ): def do_gterm( self, line ):
"Spawn gnome-terminal(s) for the given node(s)." "Spawn gnome-terminal(s) for the given node(s)."
self.do_xterm( line, term='gterm' ) self.do_xterm( line, term='gterm' )
+6
View File
@@ -52,6 +52,12 @@ def makeTerm( node, title='Node', term='xterm', display=None ):
term = node.popen( cmds[ term ] + [ display, '-e', 'env TERM=ansi bash'] ) term = node.popen( cmds[ term ] + [ display, '-e', 'env TERM=ansi bash'] )
return [ tunnel, term ] if tunnel else [ term ] return [ tunnel, term ] if tunnel else [ term ]
def runX11( node, cmd ):
"Run an X11 client on a node"
display, tunnel = tunnelX11( node )
popen = node.popen( cmd )
return [ tunnel, popen ]
def cleanUpScreens(): def cleanUpScreens():
"Remove moldy socat X11 tunnels." "Remove moldy socat X11 tunnels."
errRun( "pkill -9 -f mnexec.*socat" ) errRun( "pkill -9 -f mnexec.*socat" )