summaryrefslogtreecommitdiff
path: root/nova/context.py
diff options
context:
space:
mode:
authorDan Smith <dms@danplanet.com>2017-02-13 15:04:44 -0800
committerDan Smith <dansmith@redhat.com>2017-02-22 10:33:51 -0800
commit799cb967660c61585b34f61455e0d6cb7106df2f (patch)
treec61ea6b3812df9cbaefa03b480147ab27c48f94a /nova/context.py
parent6a0f091d9afc83e7bd94b0515108ac3a664367b0 (diff)
downloadnova-799cb967660c61585b34f61455e0d6cb7106df2f.tar.gz
Make servers API use cell-targeted context
This makes the servers API look up the CellMapping for the instance in question and target the context to the appropriate cell for the subsequent call into compute/api. Note that just as with get() and get_all(), we need to avoid going direct to the cell database and thus short-circuiting the replication in the case of cellsv1. Related to blueprint cells-aware-api Change-Id: If63a4fa7349890a6e7ac0fa3fe12917dc53334d0
Diffstat (limited to 'nova/context.py')
-rw-r--r--nova/context.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/nova/context.py b/nova/context.py
index 02549f31b1..bc5a21a92e 100644
--- a/nova/context.py
+++ b/nova/context.py
@@ -358,19 +358,35 @@ def authorize_quota_class_context(context, class_name):
raise exception.Forbidden()
-@contextmanager
-def target_cell(context, cell_mapping):
+def set_target_cell(context, cell_mapping):
"""Adds database connection information to the context
- for communicating with the given target cell.
+ for communicating with the given target_cell.
+
+ This is used for permanently targeting a cell in a context.
+ Use this when you want all subsequent code to target a cell.
:param context: The RequestContext to add connection information
- :param cell_mapping: A objects.CellMapping object
+ :param cell_mapping: An objects.CellMapping object
"""
- original_db_connection = context.db_connection
# avoid circular import
from nova import db
db_connection_string = cell_mapping.database_connection
context.db_connection = db.create_context_manager(db_connection_string)
+
+
+@contextmanager
+def target_cell(context, cell_mapping):
+ """Temporarily adds database connection information to the context
+ for communicating with the given target cell.
+
+ This context manager makes a temporary change to the context
+ and restores it when complete.
+
+ :param context: The RequestContext to add connection information
+ :param cell_mapping: A objects.CellMapping object
+ """
+ original_db_connection = context.db_connection
+ set_target_cell(context, cell_mapping)
try:
yield context
finally: