summaryrefslogtreecommitdiffstats
path: root/nova
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
parent043e3f5981d89d35aa8bb8f1c42561c38451dfc4 (diff)
downloadnova-244a5e8d72e89f9f0e6ded73038109f1e4ebbada.tar.gz
nova-244a5e8d72e89f9f0e6ded73038109f1e4ebbada.tar.xz
nova-244a5e8d72e89f9f0e6ded73038109f1e4ebbada.zip
Revert "Remove unused add_network_to_project() method"
This reverts commit d8e39cb775a872c46d067bee8febc40dee799369. Change-Id: I22f0692814ff029b4960ab32cbee63bbf4922106
Diffstat (limited to 'nova')
-rw-r--r--nova/db/sqlalchemy/api.py21
-rw-r--r--nova/network/api.py6
-rw-r--r--nova/network/manager.py5
-rw-r--r--nova/network/quantumv2/api.py4
-rw-r--r--nova/tests/policy.json1
5 files changed, 32 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)
diff --git a/nova/network/api.py b/nova/network/api.py
index d2c311f95..ae230455f 100644
--- a/nova/network/api.py
+++ b/nova/network/api.py
@@ -278,6 +278,12 @@ class API(base.Base):
{'method': 'remove_fixed_ip_from_instance',
'args': args})
+ def add_network_to_project(self, context, project_id):
+ """Force adds another network to a project."""
+ rpc.call(context, FLAGS.network_topic,
+ {'method': 'add_network_to_project',
+ 'args': {'project_id': project_id}})
+
@refresh_cache
def get_instance_nw_info(self, context, instance):
"""Returns all network info related to an instance."""
diff --git a/nova/network/manager.py b/nova/network/manager.py
index f81004fed..116413007 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -1906,6 +1906,11 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager):
self._setup_network_on_host(context, network)
return address
+ @wrap_check_policy
+ def add_network_to_project(self, context, project_id):
+ """Force adds another network to a project."""
+ self.db.network_associate(context, project_id, force=True)
+
def _get_networks_for_instance(self, context, instance_id, project_id,
requested_networks=None):
"""Determine which networks an instance should connect to."""
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py
index 16dba96fa..50042278b 100644
--- a/nova/network/quantumv2/api.py
+++ b/nova/network/quantumv2/api.py
@@ -244,6 +244,10 @@ class API(base.Base):
it is associated with."""
raise NotImplementedError()
+ def add_network_to_project(self, context, project_id):
+ """Force add a network to the project."""
+ raise NotImplementedError()
+
def _build_network_info_model(self, context, instance, networks=None):
search_opts = {'tenant_id': instance['project_id'],
'device_id': instance['uuid'], }
diff --git a/nova/tests/policy.json b/nova/tests/policy.json
index 4836a33b4..c2388d411 100644
--- a/nova/tests/policy.json
+++ b/nova/tests/policy.json
@@ -170,6 +170,7 @@
"network:get_fixed_ip": [],
"network:add_fixed_ip_to_instance": [],
"network:remove_fixed_ip_from_instance": [],
+ "network:add_network_to_project": [],
"network:get_instance_nw_info": [],
"network:get_dns_domains": [],