Revision 55dd9368 examples/xterms.py

View differences:

examples/xterms.py
1 1
#!/usr/bin/python
2 2

  
3 3
"""
4
Create a network and run an xterm (connected via screen(1) ) on each host.
5
Requires xterm(1) and GNU screen(1).
4
Create a network and run an xterm (connected via screen(1) ) on each
5
host. Requires xterm(1) and GNU screen(1).
6 6
"""
7 7

  
8
import os
8
import os, re
9 9
from subprocess import Popen
10 10
from mininet import init, TreeNet, Cli, quietRun
11 11

  
......
13 13
   "Run screen on a node, and hook up an xterm."
14 14
   node.cmdPrint( 'screen -dmS ' + node.name )
15 15
   title += ': ' + node.name
16
   if not node.inNamespace:
17
      title += ' (root namespace)'
16
   if not node.inNamespace: title += ' (root)'
18 17
   cmd = [ 'xterm', '-title', title ]
19 18
   cmd += [ '-e', 'screen', '-D', '-RR', '-S', node.name ]
20 19
   return Popen( cmd )
21 20

  
22 21
def cleanUpScreens():
23 22
   "Remove moldy old screen sessions."      
24
   # XXX We need to implement this - otherwise those darned
25
   # screen sessions will just accumulate
26
   output = quietRun( 'screen -ls' )
27
   pass
23
   r = r'(\d+.[hsc]\d+)'
24
   output = quietRun( 'screen -ls' ).split( '\n' )
25
   for line in output:
26
      m = re.search( r, line )
27
      if m is not None:
28
         quietRun( 'screen -S ' + m.group( 1 ) + ' -X kill' )
28 29
   
29 30
def makeXterms( nodes, title ):
30 31
   terms = []
......
34 35
   return terms
35 36

  
36 37
def xterms( controllers, switches, hosts ):
38
   cleanUpScreens()
37 39
   terms = []
38 40
   terms += makeXterms( controllers, 'controller' )
39 41
   terms += makeXterms( switches, 'switch' )
40 42
   terms += makeXterms( hosts, 'host' )
41 43
   # Wait for xterms to exit
42
   for term in terms:
44
   for term in terms: 
43 45
      os.waitpid( term.pid, 0 )
46
   cleanUpScreens()
44 47
   
45 48
if __name__ == '__main__':
46 49
   init()
47 50
   print "Running xterms on", os.environ[ 'DISPLAY' ]
48
   cleanUpScreens()
49 51
   network = TreeNet( depth=2, fanout=2, kernel=True )
50 52
   network.run( xterms )
51
   cleanUpScreens()

Also available in: Unified diff