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
This commit is contained in:
Zane Bitter 2013-08-26 21:11:59 +02:00
parent 83bbb975ca
commit fbd598b9ab
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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()