router: support multi-homed VMs in VPC (#3373)

This does not remove VM entries in dbags when hostnames match. The
current codebase already removes entry when a VM is stopped/removed so
we don't need to handle lazy removal. This will allow a VM on
multiple-tiers in a VPC to get dns/dhcp rules as expected.

This also fixes the issue of dhcp_release based on a specific interface and
removes dhcp/dns entry when a nic is removed on a guest VM.

Fixes #3273

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2019-06-05 08:47:05 +05:30 committed by GitHub
parent 41f569e8a8
commit 8fb388e931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 10 deletions

View File

@ -895,6 +895,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor, RedundantResource, DnsServ
@Override @Override
public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException, public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException { ResourceUnavailableException {
removeDhcpEntry(network, nic, vm);
return true; return true;
} }

View File

@ -118,7 +118,6 @@ class CsDhcp(CsDataBag):
def delete_leases(self): def delete_leases(self):
macs_dhcphosts = [] macs_dhcphosts = []
interfaces = filter(lambda x: x.startswith('eth'), os.listdir('/sys/class/net'))
try: try:
logging.info("Attempting to delete entries from dnsmasq.leases file for VMs which are not on dhcphosts file") logging.info("Attempting to delete entries from dnsmasq.leases file for VMs which are not on dhcphosts file")
for host in open(DHCP_HOSTS): for host in open(DHCP_HOSTS):
@ -130,10 +129,9 @@ class CsDhcp(CsDataBag):
mac = lease[1] mac = lease[1]
ip = lease[2] ip = lease[2]
if mac not in macs_dhcphosts: if mac not in macs_dhcphosts:
for interface in interfaces: cmd = "dhcp_release $(ip route get %s | grep eth | head -1 | awk '{print $3}') %s %s" % (ip, ip, mac)
cmd = "dhcp_release %s %s %s" % (interface, ip, mac) logging.info(cmd)
logging.info(cmd) CsHelper.execute(cmd)
CsHelper.execute(cmd)
removed = removed + 1 removed = removed + 1
self.del_host(ip) self.del_host(ip)
logging.info("Deleted %s entries from dnsmasq.leases file" % str(removed)) logging.info("Deleted %s entries from dnsmasq.leases file" % str(removed))

View File

@ -27,11 +27,6 @@ def merge(dbag, data):
del(dbag[data['ipv4_address']]) del(dbag[data['ipv4_address']])
else: else:
remove_keys = set() remove_keys = set()
for key, entry in dbag.iteritems():
if key != 'id' and entry['host_name'] == data['host_name']:
remove_keys.add(key)
break
for key, entry in dbag.iteritems(): for key, entry in dbag.iteritems():
if key != 'id' and entry['mac_address'] == data['mac_address']: if key != 'id' and entry['mac_address'] == data['mac_address']:
remove_keys.add(key) remove_keys.add(key)