Statistics
| Branch: | Tag: | Revision:

mininet / mininet / xterm.py @ 80a8fa62

History | View | Annotate | Download (1.27 KB)

1
#!/usr/bin/env python
2

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

7
Requires xterm( 1 ) and GNU screen( 1 ).
8
"""
9

    
10
import re
11
from subprocess import Popen
12
from mininet.util import quietRun
13

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

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

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