mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
95347d2a5e
commit
b42a813ff1
@ -17,13 +17,21 @@ unplug_nic() {
|
||||
sudo sed -i /"$tableNo $tableName"/d /etc/iproute2/rt_tables 2>/dev/null
|
||||
sudo ip route flush cache
|
||||
# remove network usage rules
|
||||
sudo iptables -t mangle -F NETWORK_STATS_$dev 2>/dev/null
|
||||
iptables-save -t mangle | grep NETWORK_STATS_$dev | grep "\-A" | while read rule
|
||||
sudo iptables -F NETWORK_STATS_$dev 2>/dev/null
|
||||
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
|
||||
rule=$(echo $rule | sed 's/\-A/\-D/')
|
||||
sudo iptables -t mangle $rule
|
||||
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
|
||||
iptables-save -t mangle | grep $dev | grep "\-A" | while read rule
|
||||
do
|
||||
|
||||
@ -53,31 +53,11 @@ create_vpn_usage_rules () {
|
||||
}
|
||||
|
||||
remove_usage_rules () {
|
||||
echo $ethDev >> /root/removedVifs
|
||||
return $?
|
||||
return 0
|
||||
}
|
||||
|
||||
get_usage () {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -366,10 +366,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
||||
if (router.getState() == State.Running) {
|
||||
try {
|
||||
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());
|
||||
cmds.addCommand("unplugnic", unplugNicCmd);
|
||||
_agentMgr.send(dest.getHost().getId(), cmds);
|
||||
@ -378,13 +374,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
||||
if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
|
||||
s_logger.warn("Unable to unplug nic from router " + router);
|
||||
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) {
|
||||
throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user