summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-09-11 23:32:03 -0700
committerVishvananda Ishaya <vishvananda@yahoo.com>2010-09-11 23:32:03 -0700
commite45a5dd2cbcfe5d43cc59c6a20e3d065d43ee161 (patch)
tree24a934899deb7018bd479257f84ac2fa03423fdc
parent53bba81d1e9774eefadd4f0f2b25638838a7ad07 (diff)
downloadnova-e45a5dd2cbcfe5d43cc59c6a20e3d065d43ee161.tar.gz
nova-e45a5dd2cbcfe5d43cc59c6a20e3d065d43ee161.tar.xz
nova-e45a5dd2cbcfe5d43cc59c6a20e3d065d43ee161.zip
speed up generation of dhcp_hosts and don't run into None errors if instance is deleted
-rw-r--r--nova/db/sqlalchemy/api.py1
-rw-r--r--nova/network/linux_net.py11
2 files changed, 7 insertions, 5 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index cc496e558..4cc086006 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -437,6 +437,7 @@ def network_get(_context, network_id):
def network_get_associated_fixed_ips(_context, network_id):
session = get_session()
return session.query(models.FixedIp
+ ).options(joinedload_all('instance')
).filter_by(network_id=network_id
).filter(models.FixedIp.instance_id != None
).filter_by(deleted=False
diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py
index 41aeb5da7..621ae54ea 100644
--- a/nova/network/linux_net.py
+++ b/nova/network/linux_net.py
@@ -132,8 +132,9 @@ def ensure_bridge(bridge, interface, net_attrs=None):
def get_dhcp_hosts(context, network_id):
"""Get a string containing a network's hosts config in dnsmasq format"""
hosts = []
- for fixed_ip in db.network_get_associated_fixed_ips(context, network_id):
- hosts.append(_host_dhcp(fixed_ip['str_id']))
+ for fixed_ip_ref in db.network_get_associated_fixed_ips(context,
+ network_id):
+ hosts.append(_host_dhcp(fixed_ip_ref))
return '\n'.join(hosts)
@@ -171,12 +172,12 @@ def update_dhcp(context, network_id):
_execute(command, addl_env=env)
-def _host_dhcp(address):
+def _host_dhcp(fixed_ip_ref):
"""Return a host string for an address"""
- instance_ref = db.fixed_ip_get_instance(None, address)
+ instance_ref = fixed_ip_ref['instance']
return "%s,%s.novalocal,%s" % (instance_ref['mac_address'],
instance_ref['hostname'],
- address)
+ fixed_ip_ref['str_id'])
def _execute(cmd, *args, **kwargs):