Statistics
| Branch: | Tag: | Revision:

mininet / mininet / xterm.py @ e540ab57

History | View | Annotate | Download (1.25 KB)

1
"""
2
XTerm creation and cleanup.
3
Utility functions to run an xterm (connected via screen(1)) on each host.
4

5
Requires xterm(1) and GNU screen(1).
6
"""
7

    
8
import re
9
from subprocess import Popen
10
from mininet.util import quietRun
11

    
12
def makeXterm( node, title = '' ):
13
    """Run screen on a node, and hook up an xterm.
14
       node: Node object
15
       title: base title
16
       returns: process created"""
17
    title += ': ' + node.name
18
    if not node.inNamespace:
19
        title += ' (root)'
20
    cmd = [ 'xterm', '-title', title, '-e' ]
21
    if not node.execed:
22
        node.cmd( 'screen -dmS ' + node.name )
23
        cmd += [ 'screen', '-D', '-RR', '-S', node.name ]
24
    else:
25
        cmd += [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
26
    return Popen( cmd )
27

    
28
def cleanUpScreens():
29
    "Remove moldy old screen sessions."
30
    r = r'(\d+.[hsc]\d+)'
31
    output = quietRun( 'screen -ls' ).split( '\n' )
32
    for line in output:
33
        m = re.search( r, line )
34
        if m:
35
            quietRun( 'screen -S ' + m.group( 1 ) + ' -X quit' )
36

    
37
def makeXterms( nodes, title = '' ):
38
    """Create XTerms.
39
       nodes: list of Node objects
40
       title: base title for each
41
       returns: list of created xterm processes"""
42
    return [ makeXterm( node, title ) for node in nodes ]