diff options
| author | Michael Still <mikal@stillhq.com> | 2012-09-03 22:23:24 +1000 |
|---|---|---|
| committer | Michael Still <mikal@stillhq.com> | 2012-09-04 21:33:06 +1000 |
| commit | 0bd4a04afb35d7e60b34b8a1aaab45b7805cad15 (patch) | |
| tree | a4893c05cf54883eaa4b7af96a1eefd78454effe | |
| parent | 0318efe625682ee8703b91f363a966200503782f (diff) | |
Speed up creating floating ips.
Previously, we would make two separate DB calls for each floating ip
we created in floating_ip_bulk_create. This was just a little slow
(several hours to create a /16). This patch speeds up floating ip
creation just a little:
$ time bin/nova-manage floating create --ip_range=10.250.0.0/16
real 0m48.766s
user 0m34.342s
sys 0m1.984s
Resolves bug 1023560.
Change-Id: Ie3663440d414b102111178899db0c571769edba8
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 106c8b8ed..797516ac9 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -716,10 +716,21 @@ def floating_ip_allocate_address(context, project_id, pool): @require_context def floating_ip_bulk_create(context, ips): + existing_ips = {} + for floating in _floating_ip_get_all(context).all(): + existing_ips[floating['address']] = floating + session = get_session() with session.begin(): for ip in ips: - floating_ip_create(context, ip, session) + addr = ip['address'] + if (addr in existing_ips and + ip.get('id') != existing_ips[addr]['id']): + raise exception.FloatingIpExists(**dict(existing_ips[addr])) + + model = models.FloatingIp() + model.update(ip) + session.add(model) @require_context |
