Revision 723d068c bin/mn_clean.py

View differences:

bin/mn_clean.py
12 12
"""
13 13

  
14 14
from subprocess import Popen, PIPE
15
import re
16 15

  
17
from mininet.util import quietRun
18 16
from mininet.xterm import cleanUpScreens
19 17

  
20
def sh( cmd ): 
21
   "Print a command and send it to the shell"
22
   print cmd
23
   return Popen( [ '/bin/sh', '-c', cmd ], 
24
      stdout=PIPE ).communicate()[ 0 ]
25 18

  
26
 
19
def sh(cmd):
20
    "Print a command and send it to the shell"
21
    print cmd
22
    return Popen(['/bin/sh', '-c', cmd], stdout=PIPE).communicate()[0]
23

  
24

  
27 25
def cleanup():
28
   """Clean up junk which might be left over from old runs;
29
      do fast stuff before slow dp and link removal!"""
30
      
31
   print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
32
   zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
33
   zombies += 'udpbwtest'
34
   # Note: real zombie processes can't actually be killed, since they 
35
   # are already (un)dead. Then again,
36
   # you can't connect to them either, so they're mostly harmless.
37
   sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
38

  
39
   print "*** Removing junk from /tmp"
40
   sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
41

  
42
   print "*** Removing old screen sessions"
43
   cleanUpScreens()
44

  
45
   print "*** Removing excess kernel datapaths"
46
   dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n')
47
   for dp in dps: 
48
      if dp != '': sh( 'dpctl deldp ' + dp )
49
      
50
   print "*** Removing all links of the pattern foo-ethX"
51
   links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
52
   for link in links: 
53
      if link != '': sh( "ip link del " + link )
54

  
55
   print "*** Cleanup complete."
26
    """Clean up junk which might be left over from old runs;
27
       do fast stuff before slow dp and link removal!"""
28

  
29
    print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
30
    zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
31
    zombies += 'udpbwtest'
32
    # Note: real zombie processes can't actually be killed, since they
33
    # are already (un)dead. Then again,
34
    # you can't connect to them either, so they're mostly harmless.
35
    sh('killall -9 ' + zombies + ' 2> /dev/null')
36

  
37
    print "*** Removing junk from /tmp"
38
    sh('rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log')
39

  
40
    print "*** Removing old screen sessions"
41
    cleanUpScreens()
42

  
43
    print "*** Removing excess kernel datapaths"
44
    dps = sh("ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'").split('\n')
45
    for dp in dps:
46
        if dp != '':
47
            sh('dpctl deldp ' + dp)
48

  
49
    print "*** Removing all links of the pattern foo-ethX"
50
    links = sh("ip link show | egrep -o '(\w+-eth\w+)'").split('\n')
51
    for link in links:
52
        if link != '':
53
            sh("ip link del " + link)
54

  
55
    print "*** Cleanup complete."
56 56

  
57 57
if __name__ == "__main__":
58
   cleanup()
58
    cleanup()

Also available in: Unified diff