summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_migrator.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-11-07 21:34:41 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-11-07 21:34:41 -0800
commit791598f2929a5b8b6bb380f7f16ec568db96aba6 (patch)
tree0cb1f07d25ab775e7db0dca660a1f5f8a15b49b3 /cloudinit/config/cc_migrator.py
parent1e6fc277a1c8d695c37741cc31f5ddab3d5b5600 (diff)
downloadvyos-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/config/cc_migrator.py')
-rw-r--r--cloudinit/config/cc_migrator.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/cloudinit/config/cc_migrator.py b/cloudinit/config/cc_migrator.py
new file mode 100644
index 00000000..b71d1d17
--- /dev/null
+++ b/cloudinit/config/cc_migrator.py
@@ -0,0 +1,53 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2012 Yahoo! Inc.
+#
+# Author: Joshua Harlow <harlowja@yahoo-inc.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import shutil
+
+from cloudinit import helpers
+from cloudinit import util
+
+from cloudinit.settings import PER_ALWAYS
+
+frequency = PER_ALWAYS
+
+
+def _migrate_canon_sems(cloud):
+ sem_path = cloud.paths.get_ipath('sem')
+ if not sem_path or not os.path.exists(sem_path):
+ return 0
+ am_adjusted = 0
+ for p in os.listdir(sem_path):
+ full_path = os.path.join(sem_path, p)
+ if os.path.isfile(full_path):
+ canon_p = helpers.canon_sem_name(p)
+ if canon_p != p:
+ new_path = os.path.join(sem_path, p)
+ shutil.move(full_path, new_path)
+ am_adjusted += 1
+ return am_adjusted
+
+
+def handle(name, cfg, cloud, log, _args):
+ do_migrate = util.get_cfg_option_str(cfg, "migrate", True)
+ if not util.translate_bool(do_migrate):
+ log.debug("Skipping module named %s, migration disabled", name)
+ return
+ sems_moved = _migrate_canon_sems(cloud)
+ log.debug("Migrated %s semaphore files to there canonicalized names",
+ sems_moved)