Skip to content

Commit ad5162e

Browse files
committed
fix ebtable cleanup issue: on ubuntu, it's not got deleted if vm is stopped
1 parent cb981e6 commit ad5162e

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎scripts/vm/network/security_group.py‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
8888
if vm_name.startswith('i-') or vm_name.startswith('r-'):
8989
vmchain_default = '-'.join(vm_name.split('-')[:-1]) + "-def"
9090

91-
destroy_ebtables_rules(vmchain)
91+
destroy_ebtables_rules(vmchain, vif)
9292

9393
try:
9494
if vmchain_default != None:
@@ -129,10 +129,28 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
129129

130130
return 'true'
131131

132-
def destroy_ebtables_rules(vm_name):
133-
delcmd = "ebtables-save | grep ROUTING | grep " + vm_name + " | sed 's/-A/-D/'"
134-
delcmds = execute(delcmd).split('\n')
135-
delcmds.pop()
132+
def destroy_ebtables_rules(vm_name, vif):
133+
if vif is None:
134+
return
135+
delcmd = "ebtables -t nat -L PREROUTING | grep " + vif
136+
delcmds = []
137+
try:
138+
delcmds = execute(delcmd).split('\n')
139+
delcmds.pop()
140+
delcmds = ["-D PREROUTING " + x for x in delcmds ]
141+
except:
142+
pass
143+
postcmds = []
144+
try:
145+
postcmd = "ebtables -t nat -L POSTROUTING | grep " + vif
146+
postcmds = execute(postcmd).split('\n')
147+
postcmds.pop()
148+
postcmds = ["-D POSTROUTING " + x for x in postcmds]
149+
except:
150+
pass
151+
152+
delcmds += postcmds
153+
136154
for cmd in delcmds:
137155
try:
138156
execute("ebtables -t nat " + cmd)
@@ -231,7 +249,7 @@ def default_network_rules(vm_name, vm_id, vm_ip, vm_mac, vif, brname):
231249
vmchain = vm_name
232250
vmchain_default = '-'.join(vmchain.split('-')[:-1]) + "-def"
233251

234-
destroy_ebtables_rules(vmName)
252+
destroy_ebtables_rules(vmName, vif)
235253

236254
try:
237255
execute("iptables -N " + vmchain)
@@ -284,7 +302,7 @@ def post_default_network_rules(vm_name, vm_id, vm_ip, vm_mac, vif, brname, dhcpS
284302
pass
285303

286304
try:
287-
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)
305+
execute("ebtables -t nat -I " + vmchain_in + " -p IPv4 --ip-protocol tcp --ip-destination-port 80 --ip-dst " + dhcpSvr + " -j dnat --to-destination " + hostMacAddr)
288306
except:
289307
pass
290308

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ public boolean deleteHost(long hostId, boolean isForced, User caller) {
590590
// Check if host is ready for removal
591591
Status currentState = host.getStatus();
592592
Status nextState = currentState.getNextStatus(Status.Event.Remove);
593-
if (nextState == null) {
593+
if (nextState == null && !isForced) {
594594
s_logger.debug("There is no transition from state " + currentState.toString() + " to state " + Status.Event.Remove.toString());
595595
return false;
596596
}

0 commit comments

Comments
 (0)