First crack at converting cleanup to Python.

This commit is contained in:
Bob Lantz
2009-12-15 18:49:46 -08:00
parent 2708cadd40
commit ea420ee29f
+48 -24
View File
@@ -1,33 +1,57 @@
#!/bin/bash #!/usr/bin/python
# Unfortunately, Mininet and OpenFlow don't always clean up """
# properly after themselves. Until they do (or until cleanup Unfortunately, Mininet and OpenFlow don't always clean up
# functionality is integrated into the python code), this properly after themselves. Until they do (or until cleanup
# script may be used to get rid of unwanted garbage. It may functionality is integrated into the python code), this
# also get rid of "false positives", but hopefully nothing script may be used to get rid of unwanted garbage. It may
# irreplaceable! also get rid of 'false positives', but hopefully nothing
irreplaceable!
"""
echo "Removing all links of the pattern foo-ethX" from subprocess import Popen, PIPE
import re
for f in `ip link show | egrep -o '(\w+-eth\w+)' ` ; do def sh( cmd ):
cmd="ip link del $f" "Print a command and send it to the shell"
echo $smd print cmd
$cmd return Popen( [ '/bin/sh', '-c', cmd ],
done stdout=PIPE ).communicate()[ 0 ]
echo "Removing excess controllers/ofprotocols/ofdatapaths/pings" def cleanUpScreens():
killall -9 controller ofprotocol ofdatapath ping 2> /dev/null "Remove moldy old screen sessions."
r = r'(\d+.[hsc]\d+)'
output = sh( 'screen -ls' ).split( '\n' )
for line in output:
m = re.search( r, line )
if m is not None:
quietRun( 'screen -S ' + m.group( 1 ) + ' -X kill' )
def cleanup():
print "*** Removing all links of the pattern foo-ethX"
links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
for link in links:
if link: sh( "ip link del " + link )
echo "Removing excess kernel datapath processes" print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/' | xargs -l1 echo dpctl deldp zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core'
# Note: real zombie processes can't actually be killed, since they
# are already (un)dead. Then again,
# you can't connect to them either, so they're mostly harmless.
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
echo "Removing junk in /tmp" print "*** Removing excess kernel datapaths"
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n')
for dp in dps:
if dp: sh( 'ip link del ' + link )
echo "Killing nox" print "*** Removing junk from /tmp"
killall lt-nox_core sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
killall nox_core
echo "Removing old screen sessions" print "*** Removing old screen sessions"
screen -ls | egrep -o '[0-9]+\.[hsc][0-9]+' | sed 's/\.[hsc][0-9]*//g' | kill -9 cleanUpScreens()
print "*** Cleanup complete."
if __name__ == "__main__":
cleanup()