summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-05-10 12:49:51 +0000
committerGerrit Code Review <review@openstack.org>2013-05-10 12:49:51 +0000
commit89d1f8b51d05f3282d11b3928443897e28459c7a (patch)
treeb4607e851c61f96902c3b6eeaf67361864957d3a /openstack
parent26335f492fdc07d333f7baa78e4711d958405509 (diff)
parentb873454819df6ef35b22b92445bfb8675b7ac7c1 (diff)
downloadoslo-89d1f8b51d05f3282d11b3928443897e28459c7a.tar.gz
oslo-89d1f8b51d05f3282d11b3928443897e28459c7a.tar.xz
oslo-89d1f8b51d05f3282d11b3928443897e28459c7a.zip
Merge "Added convenience APIs for lockutils"
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/lockutils.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/openstack/common/lockutils.py b/openstack/common/lockutils.py
index 892d821..79d1905 100644
--- a/openstack/common/lockutils.py
+++ b/openstack/common/lockutils.py
@@ -49,6 +49,10 @@ CONF = cfg.CONF
CONF.register_opts(util_opts)
+def set_defaults(lock_path):
+ cfg.set_defaults(util_opts, lock_path=lock_path)
+
+
class _InterProcessLock(object):
"""Lock implementation which allows multiple locks, working around
issues like bugs.debian.org/cgi-bin/bugreport.cgi?bug=632857 and does
@@ -247,3 +251,28 @@ def synchronized(name, lock_file_prefix, external=False, lock_path=None):
return retval
return inner
return wrap
+
+
+def synchronized_with_prefix(lock_file_prefix):
+ """Partial object generator for the synchronization decorator.
+
+ Redefine @synchronized in each project like so::
+
+ (in nova/utils.py)
+ from nova.openstack.common import lockutils
+
+ synchronized = lockutils.synchronized_with_prefix('nova-')
+
+
+ (in nova/foo.py)
+ from nova import utils
+
+ @utils.synchronized('mylock')
+ def bar(self, *args):
+ ...
+
+ The lock_file_prefix argument is used to provide lock files on disk with a
+ meaningful prefix. The prefix should end with a hyphen ('-') if specified.
+ """
+
+ return functools.partial(synchronized, lock_file_prefix=lock_file_prefix)