mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
fix ebtable cleanup issue: on ubuntu, it's not got deleted if vm is stopped
This commit is contained in:
parent
cb981e6682
commit
ad5162ef86
@ -88,7 +88,7 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
|
|||||||
if vm_name.startswith('i-') or vm_name.startswith('r-'):
|
if vm_name.startswith('i-') or vm_name.startswith('r-'):
|
||||||
vmchain_default = '-'.join(vm_name.split('-')[:-1]) + "-def"
|
vmchain_default = '-'.join(vm_name.split('-')[:-1]) + "-def"
|
||||||
|
|
||||||
destroy_ebtables_rules(vmchain)
|
destroy_ebtables_rules(vmchain, vif)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if vmchain_default != None:
|
if vmchain_default != None:
|
||||||
@ -129,10 +129,28 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
|
|||||||
|
|
||||||
return 'true'
|
return 'true'
|
||||||
|
|
||||||
def destroy_ebtables_rules(vm_name):
|
def destroy_ebtables_rules(vm_name, vif):
|
||||||
delcmd = "ebtables-save | grep ROUTING | grep " + vm_name + " | sed 's/-A/-D/'"
|
if vif is None:
|
||||||
delcmds = execute(delcmd).split('\n')
|
return
|
||||||
delcmds.pop()
|
delcmd = "ebtables -t nat -L PREROUTING | grep " + vif
|
||||||
|
delcmds = []
|
||||||
|
try:
|
||||||
|
delcmds = execute(delcmd).split('\n')
|
||||||
|
delcmds.pop()
|
||||||
|
delcmds = ["-D PREROUTING " + x for x in delcmds ]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
postcmds = []
|
||||||
|
try:
|
||||||
|
postcmd = "ebtables -t nat -L POSTROUTING | grep " + vif
|
||||||
|
postcmds = execute(postcmd).split('\n')
|
||||||
|
postcmds.pop()
|
||||||
|
postcmds = ["-D POSTROUTING " + x for x in postcmds]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
delcmds += postcmds
|
||||||
|
|
||||||
for cmd in delcmds:
|
for cmd in delcmds:
|
||||||
try:
|
try:
|
||||||
execute("ebtables -t nat " + cmd)
|
execute("ebtables -t nat " + cmd)
|
||||||
@ -231,7 +249,7 @@ def default_network_rules(vm_name, vm_id, vm_ip, vm_mac, vif, brname):
|
|||||||
vmchain = vm_name
|
vmchain = vm_name
|
||||||
vmchain_default = '-'.join(vmchain.split('-')[:-1]) + "-def"
|
vmchain_default = '-'.join(vmchain.split('-')[:-1]) + "-def"
|
||||||
|
|
||||||
destroy_ebtables_rules(vmName)
|
destroy_ebtables_rules(vmName, vif)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
execute("iptables -N " + vmchain)
|
execute("iptables -N " + vmchain)
|
||||||
@ -284,7 +302,7 @@ def post_default_network_rules(vm_name, vm_id, vm_ip, vm_mac, vif, brname, dhcpS
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
execute("ebtables -t nat -A PREROUTING -i " + vif + " -p IPv4 --ip-protocol tcp --ip-destination-port 80 --ip-dst " + dhcpSvr + " -j dnat --to-destination " + hostMacAddr)
|
execute("ebtables -t nat -I " + vmchain_in + " -p IPv4 --ip-protocol tcp --ip-destination-port 80 --ip-dst " + dhcpSvr + " -j dnat --to-destination " + hostMacAddr)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@ -590,7 +590,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||||||
// Check if host is ready for removal
|
// Check if host is ready for removal
|
||||||
Status currentState = host.getStatus();
|
Status currentState = host.getStatus();
|
||||||
Status nextState = currentState.getNextStatus(Status.Event.Remove);
|
Status nextState = currentState.getNextStatus(Status.Event.Remove);
|
||||||
if (nextState == null) {
|
if (nextState == null && !isForced) {
|
||||||
s_logger.debug("There is no transition from state " + currentState.toString() + " to state " + Status.Event.Remove.toString());
|
s_logger.debug("There is no transition from state " + currentState.toString() + " to state " + Status.Event.Remove.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user