filter the dhcp to only respond to requests from this host

This commit is contained in:
Vishvananda Ishaya 2011-07-05 16:06:20 -07:00
parent 9b5adcbe92
commit 8e1a74e560
2 changed files with 16 additions and 10 deletions

View File

@ -91,7 +91,7 @@ def init_leases(interface):
"""Get the list of hosts for an interface."""
ctxt = context.get_admin_context()
network_ref = db.network_get_by_bridge(ctxt, interface)
return linux_net.get_dhcp_leases(ctxt, network_ref['id'])
return linux_net.get_dhcp_leases(ctxt, network_ref)
def main():

View File

@ -551,21 +551,27 @@ def ensure_bridge(bridge, interface, net_attrs=None):
bridge)
def get_dhcp_leases(context, network_id):
def get_dhcp_leases(context, network_ref):
"""Return a network's hosts config in dnsmasq leasefile format."""
hosts = []
for fixed_ip_ref in db.network_get_associated_fixed_ips(context,
network_id):
hosts.append(_host_lease(fixed_ip_ref))
for fixed_ref in db.network_get_associated_fixed_ips(context,
network_ref['id']):
host = fixed_ref['instance']['host']
if network_ref['multi_host'] and FLAGS.host != host:
continue
hosts.append(_host_lease(fixed_ref))
return '\n'.join(hosts)
def get_dhcp_hosts(context, network_id):
def get_dhcp_hosts(context, network_ref):
"""Get network's hosts config in dhcp-host format."""
hosts = []
for fixed_ip_ref in db.network_get_associated_fixed_ips(context,
network_id):
hosts.append(_host_dhcp(fixed_ip_ref))
for fixed_ref in db.network_get_associated_fixed_ips(context,
network_ref['id']):
host = fixed_ref['instance']['host']
if network_ref['multi_host'] and FLAGS.host != host:
continue
hosts.append(_host_dhcp(fixed_ref))
return '\n'.join(hosts)
@ -582,7 +588,7 @@ def update_dhcp(context, network_ref):
"""
conffile = _dhcp_file(network_ref['bridge'], 'conf')
with open(conffile, 'w') as f:
f.write(get_dhcp_hosts(context, network_ref['id']))
f.write(get_dhcp_hosts(context, network_ref))
# Make sure dnsmasq can actually read it (it setuid()s to "nobody")
os.chmod(conffile, 0644)