Statistics
| Branch: | Tag: | Revision:

mininet / mininet / xterm.py @ fcf6a16f

History | View | Annotate | Download (1.27 KB)

1
#!/usr/bin/env python
2
"""XTerm creation and cleanup.
3

4
Utility functions to run an xterm (connected via screen(1)) on each host.
5

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

    
9
import os
10
import re
11
from subprocess import Popen
12

    
13
from mininet.util import quietRun
14

    
15
def makeXterm(node, title):
16
    '''Run screen on a node, and hook up an xterm.
17

18
    @param node Node object
19
    @param title base title
20
    @return process created
21
    '''
22
    title += ': ' + node.name
23
    if not node.inNamespace:
24
        title += ' (root)'
25
    cmd = ['xterm', '-title', title, '-e']
26
    if not node.execed:
27
        node.cmdPrint('screen -dmS ' + node.name)
28
        cmd += ['screen', '-D', '-RR', '-S', node.name]
29
    else:
30
        cmd += ['sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log']
31
    return Popen(cmd)
32

    
33

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

    
43

    
44
def makeXterms(nodes, title):
45
    '''Create XTerms.
46

47
    @param nodes list of Node objects
48
    @param title base title for each
49
    @return list of created xterm processes
50
    '''
51
    return [makeXterm(node, title) for node in nodes]