diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-11-07 21:34:41 -0800 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-11-07 21:34:41 -0800 |
commit | 791598f2929a5b8b6bb380f7f16ec568db96aba6 (patch) | |
tree | 0cb1f07d25ab775e7db0dca660a1f5f8a15b49b3 /cloudinit/helpers.py | |
parent | 1e6fc277a1c8d695c37741cc31f5ddab3d5b5600 (diff) | |
download | vyos-cloud-init-791598f2929a5b8b6bb380f7f16ec568db96aba6.tar.gz vyos-cloud-init-791598f2929a5b8b6bb380f7f16ec568db96aba6.zip |
Start adding a 'migrator' module
that can be used to aid in the moving
of older versions of cloud-inits data
to newer versions of cloud-inits data.
1. Move the semaphores for the current instance
to there canonicalized names and use the
canonicalized in the file 'locking' code
Diffstat (limited to 'cloudinit/helpers.py')
-rw-r--r-- | cloudinit/helpers.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py index 985ce3e5..d26625a0 100644 --- a/cloudinit/helpers.py +++ b/cloudinit/helpers.py @@ -71,12 +71,17 @@ class FileLock(object): return "<%s using file %r>" % (util.obj_name(self), self.fn) +def canon_sem_name(name): + return name.replace("-", "_") + + class FileSemaphores(object): - def __init__(self, sem_path): + def __init__(self, sem_path): self.sem_path = sem_path @contextlib.contextmanager def lock(self, name, freq, clear_on_fail=False): + name = canon_sem_name(name) try: yield self._acquire(name, freq) except: @@ -85,6 +90,7 @@ class FileSemaphores(object): raise def clear(self, name, freq): + name = canon_sem_name(name) sem_file = self._get_path(name, freq) try: util.del_file(sem_file) @@ -119,6 +125,7 @@ class FileSemaphores(object): def has_run(self, name, freq): if not freq or freq == PER_ALWAYS: return False + name = canon_sem_name(name) sem_file = self._get_path(name, freq) # This isn't really a good atomic check # but it suffices for where and when cloudinit runs |