bug CS-16112: During unplug nic iptables rules are cleaned up in both cloud_nic.sh and vpc_netusage.sh. Consolidated this code in cloud_nic.sh

status CS-16112: resolved fixed

Conflicts:
	patches/systemvm/debian/config/opt/cloud/bin/vpc_netusage.sh
This commit is contained in:
kishan 2012-08-21 20:16:35 +05:30
parent 95347d2a5e
commit b42a813ff1
3 changed files with 12 additions and 35 deletions

View File

@ -17,13 +17,21 @@ unplug_nic() {
sudo sed -i /"$tableNo $tableName"/d /etc/iproute2/rt_tables 2>/dev/null sudo sed -i /"$tableNo $tableName"/d /etc/iproute2/rt_tables 2>/dev/null
sudo ip route flush cache sudo ip route flush cache
# remove network usage rules # remove network usage rules
sudo iptables -t mangle -F NETWORK_STATS_$dev 2>/dev/null sudo iptables -F NETWORK_STATS_$dev 2>/dev/null
iptables-save -t mangle | grep NETWORK_STATS_$dev | grep "\-A" | while read rule iptables-save | grep NETWORK_STATS_$dev | grep "\-A" | while read rule
do
rule=$(echo $rule | sed 's/\-A/\-D/')
sudo iptables $rule
done
sudo iptables -X NETWORK_STATS_$dev 2>/dev/null
# remove vpn network usage rules
sudo iptables -t mangle -F VPN_STATS_$dev 2>/dev/null
iptables-save -t mangle | grep VPN_STATS_$dev | grep "\-A" | while read rule
do do
rule=$(echo $rule | sed 's/\-A/\-D/') rule=$(echo $rule | sed 's/\-A/\-D/')
sudo iptables -t mangle $rule sudo iptables -t mangle $rule
done done
sudo iptables -t mangle -X NETWORK_STATS_$dev 2>/dev/null sudo iptables -t mangle -X VPN_STATS_$dev 2>/dev/null
# remove rules on this dev # remove rules on this dev
iptables-save -t mangle | grep $dev | grep "\-A" | while read rule iptables-save -t mangle | grep $dev | grep "\-A" | while read rule
do do

View File

@ -53,31 +53,11 @@ create_vpn_usage_rules () {
} }
remove_usage_rules () { remove_usage_rules () {
echo $ethDev >> /root/removedVifs return 0
return $?
} }
get_usage () { get_usage () {
iptables -L NETWORK_STATS_$ethDev -n -v -x 2> /dev/null | awk '$1 ~ /^[0-9]+$/ { printf "%s:", $2}'; > /dev/null iptables -L NETWORK_STATS_$ethDev -n -v -x 2> /dev/null | awk '$1 ~ /^[0-9]+$/ { printf "%s:", $2}'; > /dev/null
if [ -f /root/removedVifs ]
then
var=`cat /root/removedVifs`
# loop through vifs to be cleared
for i in $var; do
# Make sure vif doesn't exist
if [ ! -f /sys/class/net/$i ]
then
# flush rules and remove chain
iptables -F NETWORK_STATS_$i > /dev/null;
iptables -D FORWARD -j NETWORK_STATS_$i > /dev/null;
iptables -X NETWORK_STATS_$i > /dev/null;
iptables -t mangle -F VPN_STATS_$i > /dev/null;
iptables -t mangle -D FORWARD -j VPN_STATS_$i > /dev/null;
iptables -t mangle -X VPN_STATS_$i > /dev/null;
fi
done
rm /root/removedVifs
fi
return 0 return 0
} }

View File

@ -366,10 +366,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (router.getState() == State.Running) { if (router.getState() == State.Running) {
try { try {
Commands cmds = new Commands(OnError.Stop); Commands cmds = new Commands(OnError.Stop);
if(network.getTrafficType() == TrafficType.Public){
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), "remove", true, nic.getIp());
cmds.addCommand(netUsageCmd);
}
UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, vm.getName()); UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, vm.getName());
cmds.addCommand("unplugnic", unplugNicCmd); cmds.addCommand("unplugnic", unplugNicCmd);
_agentMgr.send(dest.getHost().getId(), cmds); _agentMgr.send(dest.getHost().getId(), cmds);
@ -378,13 +374,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) { if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
s_logger.warn("Unable to unplug nic from router " + router); s_logger.warn("Unable to unplug nic from router " + router);
result = false; result = false;
} else {
if(network.getTrafficType() == TrafficType.Public){
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), "remove", true, nic.getIp());
cmds = new Commands(OnError.Stop);
cmds.addCommand(netUsageCmd);
_agentMgr.send(dest.getHost().getId(), cmds);
}
} }
} catch (OperationTimedoutException e) { } catch (OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network,