Adds running_deleted_instance_reaper task.

This adds a periodic task to cleanup erroneously running instances. The
impetus of the patch was a XenServer specific issue bug #911366, where deleted
instances would remain running on the host machine.

The patch however is hypervisor agnostic and is generally useful as a
housekeeping task to make sure these 'zombied' instances are detected.

Change-Id: Iddc6a88920a537a3a115f8b9bc0039ec0e24a194
This commit is contained in:
Rick Harris 2011-12-21 22:40:23 +00:00
parent 1e28f07d03
commit f4fb500c53

@ -1181,3 +1181,31 @@ def read_cached_file(filename, cache_info):
cache_info['data'] = data
cache_info['mtime'] = mtime
return data
@contextlib.contextmanager
def temporary_mutation(obj, **kwargs):
"""Temporarily set the attr on a particular object to a given value then
revert when finished.
One use of this is to temporarily set the read_deleted flag on a context
object:
with temporary_mutation(context, read_deleted="yes"):
do_something_that_needed_deleted_objects()
"""
NOT_PRESENT = object()
old_values = {}
for attr, new_value in kwargs.items():
old_values[attr] = getattr(obj, attr, NOT_PRESENT)
setattr(obj, attr, new_value)
try:
yield
finally:
for attr, old_value in old_values.items():
if old_value is NOT_PRESENT:
del obj[attr]
else:
setattr(obj, attr, old_value)