Commit 7996a135 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a simple decorator for instance methods

This is just a simple, hardcoded decorator for object methods needing
synchronization on the _lock instance attribute.

Reviewed-by: ultrotter
parent c8549bfd
......@@ -28,6 +28,7 @@ from ganeti import constants
from ganeti import workerpool
from ganeti import errors
from ganeti import mcpu
from ganeti import utils
......@@ -1063,3 +1063,22 @@ def CheckVolumeGroupSize(vglist, vgname, minsize):
return ("volume group '%s' too small (%s MiB required, %d MiB found)" %
(vgname, minsize, vgsize))
return None
def LockedMethod(fn):
"""Synchronized object access decorator.
This decorator is intended to protect access to an object using the
object's own lock which is hardcoded to '_lock'.
def wrapper(self, *args, **kwargs):
assert hasattr(self, '_lock')
lock = self._lock
result = fn(self, *args, **kwargs)
return result
return wrapper
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment