diff options
| author | Zhongyue Luo <zhongyue.nah@intel.com> | 2013-05-11 21:25:16 +0800 |
|---|---|---|
| committer | Zhongyue Luo <zhongyue.nah@intel.com> | 2013-05-14 15:01:45 +0800 |
| commit | 3c36cbdbc83c1fe1e83fb0733101f84a7a61a0f7 (patch) | |
| tree | d3a556517225e3ab5451dbcb4a0bda8ac6568c72 /nova/openstack | |
| parent | 966c6fbdfc038ff5d5d01b7ea29e83bddbb083bf (diff) | |
| download | nova-3c36cbdbc83c1fe1e83fb0733101f84a7a61a0f7.tar.gz nova-3c36cbdbc83c1fe1e83fb0733101f84a7a61a0f7.tar.xz nova-3c36cbdbc83c1fe1e83fb0733101f84a7a61a0f7.zip | |
Hide lock_prefix argument using synchronized_with_prefix()
The lockfile module has a new convenience API which sets the lockfile prefix.
Using this API, the prefix is not required everytime synchronized is used.
Change-Id: Iac1cfcc83b59108164de924d20127c1cf4dd7dcd
Diffstat (limited to 'nova/openstack')
| -rw-r--r-- | nova/openstack/common/lockutils.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/nova/openstack/common/lockutils.py b/nova/openstack/common/lockutils.py index 672e7ad7d..e8b5af78b 100644 --- a/nova/openstack/common/lockutils.py +++ b/nova/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) |
