From e01dd89c930b6218e0062becf20e0dc594d00569 Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Tue, 9 Jan 2018 20:11:55 +0100 Subject: [PATCH] CLOUDSTACK-10217: Clean up old MAC addresses from DHCP lease file (#2393) When the IPv4 address of a Instance changes we need to make sure the old entry is removed from the DHCP lease file on the Virtual Router otherwise the Instance will still get the old lease. Signed-off-by: Wido den Hollander --- systemvm/debian/opt/cloud/bin/cs_dhcp.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/cs_dhcp.py b/systemvm/debian/opt/cloud/bin/cs_dhcp.py index b85e650d90a..88b4b7568c5 100755 --- a/systemvm/debian/opt/cloud/bin/cs_dhcp.py +++ b/systemvm/debian/opt/cloud/bin/cs_dhcp.py @@ -25,12 +25,18 @@ def merge(dbag, data): if data['ipv4_address'] in dbag: del(dbag[data['ipv4_address']]) else: - remove_key = None + remove_keys = set() for key, entry in dbag.iteritems(): if key != 'id' and entry['host_name'] == data['host_name']: - remove_key = key + remove_keys.add(key) break - if remove_key is not None: + + for key, entry in dbag.iteritems(): + if key != 'id' and entry['mac_address'] == data['mac_address']: + remove_keys.add(key) + break + + for remove_key in remove_keys: del(dbag[remove_key]) dbag[data['ipv4_address']] = data