summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorAlessio Ababilov <aababilov@griddynamics.com>2012-08-10 11:06:56 +0300
committerAlessio Ababilov <aababilov@griddynamics.com>2012-08-10 11:13:41 +0300
commit244a5e8d72e89f9f0e6ded73038109f1e4ebbada (patch)
tree4f6c5a9638cf6343929074045db68c19cd678804 /nova/db
parent043e3f5981d89d35aa8bb8f1c42561c38451dfc4 (diff)
Revert "Remove unused add_network_to_project() method"
This reverts commit d8e39cb775a872c46d067bee8febc40dee799369. Change-Id: I22f0692814ff029b4960ab32cbee63bbf4922106
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/sqlalchemy/api.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 2993aaaf3..a55e7ab80 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1995,12 +1995,20 @@ def key_pair_count_by_user(context, user_id):
@require_admin_context
-def network_associate(context, project_id):
+def network_associate(context, project_id, force=False):
"""Associate a project with a network.
called by project_get_networks under certain conditions
+ and network manager add_network_to_project()
only associate if the project doesn't already have a network
+ or if force is True
+
+ force solves race condition where a fresh project has multiple instance
+ builds simultaneously picked up by multiple network hosts which attempt
+ to associate the project with multiple networks
+ force should only be used as a direct consequence of user request
+ all automated requests should not use force
"""
session = get_session()
with session.begin():
@@ -2012,10 +2020,13 @@ def network_associate(context, project_id):
with_lockmode('update').\
first()
- # find out if project has a network
- network_ref = network_query(project_id)
- if not network_ref:
- # project doesn't have a network so associate with a new network
+ if not force:
+ # find out if project has a network
+ network_ref = network_query(project_id)
+
+ if force or not network_ref:
+ # in force mode or project doesn't have a network so associate
+ # with a new network
# get new network
network_ref = network_query(None)