summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Lee <aaron.lee@rackspace.com>2011-10-27 17:37:34 -0500
committerAaron Lee <aaron.lee@rackspace.com>2011-10-27 17:37:34 -0500
commitfcbb8780386b3ff48653da23a1ffb3f5aa0c8b13 (patch)
tree539bae59237f36bb447dcbf3077a78b0d49d4172
parent16bacc3252b9a792159b247dcf9d2f3ebb6842ac (diff)
downloadnova-fcbb8780386b3ff48653da23a1ffb3f5aa0c8b13.tar.gz
nova-fcbb8780386b3ff48653da23a1ffb3f5aa0c8b13.tar.xz
nova-fcbb8780386b3ff48653da23a1ffb3f5aa0c8b13.zip
Adding bulk create fixed ips. The true issue here
is the creation of IPs in the DB that are not currently used(we are building the entire block). This fix is just a bandaid, but it does cut ~25 seconds off of the quantum tests on my laptop. (pre)$ ./run_tests.sh -N nova.tests.test_quantum:QuantumNovaIPAMTestCase QuantumNovaIPAMTestCase test_allocate_and_deallocate_instance_dynamic OK 11.36 test_allocate_and_deallocate_instance_static OK 11.27 test_create_and_delete_nets OK 10.35 test_validate_bad_network OK 0.10 (post)$ ./run_tests.sh -N nova.tests.test_quantum:QuantumNovaIPAMTestCase QuantumNovaIPAMTestCase test_allocate_and_deallocate_instance_dynamic OK 2.94 test_allocate_and_deallocate_instance_static OK 3.12 test_create_and_delete_nets OK 1.86 test_validate_bad_network OK 0.11 Change-Id: I46b629f9ca6e019c7c4c6aa8e869c551e5c13fb8
-rw-r--r--nova/db/api.py5
-rw-r--r--nova/db/sqlalchemy/api.py10
-rw-r--r--nova/network/manager.py9
3 files changed, 21 insertions, 3 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 601bdcee0..915589fb3 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -357,6 +357,11 @@ def fixed_ip_create(context, values):
return IMPL.fixed_ip_create(context, values)
+def fixed_ip_bulk_create(context, ips):
+ """Create a lot of fixed ips from the values dictionary."""
+ return IMPL.fixed_ip_bulk_create(context, ips)
+
+
def fixed_ip_disassociate(context, address):
"""Disassociate a fixed ip from an instance by address."""
return IMPL.fixed_ip_disassociate(context, address)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 983c48145..47efb9019 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -768,6 +768,16 @@ def fixed_ip_create(_context, values):
@require_context
+def fixed_ip_bulk_create(_context, ips):
+ session = get_session()
+ with session.begin():
+ for ip in ips:
+ model = models.FixedIp()
+ model.update(ip)
+ session.add(model)
+
+
+@require_context
def fixed_ip_disassociate(context, address):
session = get_session()
with session.begin():
diff --git a/nova/network/manager.py b/nova/network/manager.py
index ea6bdb5d4..79bb0eda1 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -1015,15 +1015,18 @@ class NetworkManager(manager.SchedulerDependentManager):
top_reserved = self._top_reserved_ips
project_net = netaddr.IPNetwork(network['cidr'])
num_ips = len(project_net)
+ ips = []
for index in range(num_ips):
address = str(project_net[index])
if index < bottom_reserved or num_ips - index < top_reserved:
reserved = True
else:
reserved = False
- self.db.fixed_ip_create(context, {'network_id': network_id,
- 'address': address,
- 'reserved': reserved})
+
+ ips.append({'network_id': network_id,
+ 'address': address,
+ 'reserved': reserved})
+ self.db.fixed_ip_bulk_create(context, ips)
def _allocate_fixed_ips(self, context, instance_id, host, networks,
**kwargs):