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 <wido@widodh.nl>
This commit is contained in:
Wido den Hollander 2018-01-09 20:11:55 +01:00 committed by Rohit Yadav
parent c9afa8e5b4
commit e01dd89c93

View File

@ -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