From fbd598b9ab5fdcb1db253a1e9115d65112989775 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Mon, 26 Aug 2013 21:11:59 +0200 Subject: [PATCH] Add a DB API to swap two resources between stacks When rolling back a stack update, we will need to swap the current and previous (backup) resources so that the former moves to the backup stack while the latter returns to the current stack. This API allows us to effect the switch using a database transaction (thus avoiding having to create a *third* stack). Change-Id: I2b7247e384e3914778179260e198e5ae5c701525 --- heat/db/api.py | 4 ++++ heat/db/sqlalchemy/api.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/heat/db/api.py b/heat/db/api.py index c815a805..aea21db8 100644 --- a/heat/db/api.py +++ b/heat/db/api.py @@ -95,6 +95,10 @@ def resource_create(context, values): return IMPL.resource_create(context, values) +def resource_exchange_stacks(context, resource_id1, resource_id2): + return IMPL.resource_exchange_stacks(context, resource_id1, resource_id2) + + def resource_get_all_by_stack(context, stack_id): return IMPL.resource_get_all_by_stack(context, stack_id) diff --git a/heat/db/sqlalchemy/api.py b/heat/db/sqlalchemy/api.py index b72d09c3..a3f61786 100644 --- a/heat/db/sqlalchemy/api.py +++ b/heat/db/sqlalchemy/api.py @@ -144,6 +144,19 @@ def resource_data_set(resource, key, value, redact=False): return current +def resource_exchange_stacks(context, resource_id1, resource_id2): + query = model_query(context, models.Resource) + session = query.session + session.begin() + + res1 = query.get(resource_id1) + res2 = query.get(resource_id2) + + res1.stack, res2.stack = res2.stack, res1.stack + + session.commit() + + def resource_data_delete(resource, key): result = resource_data_get_by_key(resource.context, resource.id, key) result.delete() -- 2.45.2