summaryrefslogtreecommitdiff
path: root/cloudinit/helpers.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2012-11-10 22:02:19 -0500
committerScott Moser <smoser@ubuntu.com>2012-11-10 22:02:19 -0500
commitcec15471c0fc7008cad607da222dd3c177e764b6 (patch)
tree72ccc6fafd7bbaf7d18f0b2f92d0413c7a4cb8ac /cloudinit/helpers.py
parentefa2dfa699bc9222105850641a2820ceda9bfe67 (diff)
parent196badd4cfa5f9f76be1138fb2d073649af3e031 (diff)
downloadvyos-cloud-init-cec15471c0fc7008cad607da222dd3c177e764b6.tar.gz
vyos-cloud-init-cec15471c0fc7008cad607da222dd3c177e764b6.zip
Add 'migrator' for handling config name changes and consistency
This migrator module does a few things * fixes filename markers that were written with a '-' in them to have an '_' instead * support renaming modules. Explicitly this handles the name change of 'apt-update-upgrade' to 'apt-configure' and 'package-update-upgrade-install' Also, just be more consistent everywhere where writing semaphore/marker files and use '_' instead of '-' (canon_sem_name).
Diffstat (limited to 'cloudinit/helpers.py')
-rw-r--r--cloudinit/helpers.py9
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