Skip to content

Script to delete all rules from floodlight

by on January 24, 2013

While I was playing with OVS and FL I checked some rules and had to add and remove rules frequently.

so – here a small script (old style with awk and sed…) to delete all rules from FL.

I checked it on small number of rules – as the output of all rules is in a single line, sed might fail for very long lines.

cat del_all_rules.sh

#!/bin/bash
rulesfile=/tmp/rules_`date +%Y%m%d_%H%M%S`.lst
curl http://localhost:8080//wm/firewall/rules/json > $rulesfile

sed 's/\[//g' $rulesfile | sed 's/\]//g' | sed 's/\}//g' | sed 's/{/\n/g' > ${rulesfile}.sed

awk -F, '
NF {for(i=1;i<=NF;i++) {split($i,a,":");printf("%s,",a[2]);}printf("\n");}
' ${rulesfile}.sed > ${rulesfile}.awk

ls -l ${rulesfile}*

echo "echo deleting rules" > ${rulesfile}.sh

awk -F, -v ff=\' 'BEGIN{cc="curl -X DELETE -d " ff "{\"ruleid\":";hh="}" ff " http://localhost:8080/wm/firewall/rules/json";}
{print cc $1 hh}
' ${rulesfile}.awk >> ${rulesfile}.sh

bash -x ${rulesfile}.sh
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: