summaryrefslogtreecommitdiff
path: root/heat/objects
diff options
context:
space:
mode:
authorZane Bitter <zbitter@redhat.com>2017-10-30 16:42:15 -0400
committerrabi <ramishra@redhat.com>2017-11-03 09:14:46 +0530
commitc9792b96d29b5492cba114db9bd3092f2cbd5274 (patch)
treef4217d2044f48d02cb2be8b092b048bbbccf0c7d /heat/objects
parent86fcc11b80e8d1c1f36d3c71fdaa10fd022dc8e3 (diff)
downloadheat-c9792b96d29b5492cba114db9bd3092f2cbd5274.tar.gz
Create replacement resource atomically
Use a single transaction to create the replacement resource and set it as the replaced_by link in the old resource. Also, ensure that no other traversal has taken a lock on the old resource before we modify it. If we end up bailing out and not creating a replacement or sending an RPC message to check it, make sure we retrigger any new traversal. Change-Id: I23db4f06a4060f3d26a78f7b26700de426f355e3 Closes-Bug: #1727128
Diffstat (limited to 'heat/objects')
-rw-r--r--heat/objects/resource.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/heat/objects/resource.py b/heat/objects/resource.py
index 1f2e2bbdf..67cc24a0c 100644
--- a/heat/objects/resource.py
+++ b/heat/objects/resource.py
@@ -200,6 +200,21 @@ class Resource(
db_api.resource_create(context, values))
@classmethod
+ def replacement(cls, context,
+ existing_res_id, existing_res_values,
+ new_res_values,
+ atomic_key=0, expected_engine_id=None):
+ replacement = db_api.resource_create_replacement(context,
+ existing_res_id,
+ existing_res_values,
+ new_res_values,
+ atomic_key,
+ expected_engine_id)
+ if replacement is None:
+ return None
+ return cls._from_db_object(cls(context), context, replacement)
+
+ @classmethod
def delete(cls, context, resource_id):
db_api.resource_delete(context, resource_id)