PATH:
usr
/
lib
/
python3.6
/
site-packages
/
cloudinit
/
config
# Copyright (C) 2012 Yahoo! Inc. # # Author: Joshua Harlow <harlowja@yahoo-inc.com> # # This file is part of cloud-init. See LICENSE file for license information. """Migrator: Migrate old versions of cloud-init data to new""" import logging import os import shutil from cloudinit import helpers, util from cloudinit.cloud import Cloud from cloudinit.config import Config from cloudinit.config.schema import MetaSchema, get_meta_doc from cloudinit.settings import PER_ALWAYS MODULE_DESCRIPTION = """\ This module handles moving old versions of cloud-init data to newer ones. Currently, it only handles renaming cloud-init's per-frequency semaphore files to canonicalized name and renaming legacy semaphore names to newer ones. This module is enabled by default, but can be disabled by specifying ``migrate: false`` in config. """ distros = ["all"] frequency = PER_ALWAYS meta: MetaSchema = { "id": "cc_migrator", "name": "Migrator", "title": "Migrate old versions of cloud-init data to new", "description": MODULE_DESCRIPTION, "distros": distros, "examples": ["# Do not migrate cloud-init semaphores\nmigrate: false\n"], "frequency": frequency, "activate_by_schema_keys": [], } __doc__ = get_meta_doc(meta) LOG = logging.getLogger(__name__) def _migrate_canon_sems(cloud): paths = (cloud.paths.get_ipath("sem"), cloud.paths.get_cpath("sem")) am_adjusted = 0 for sem_path in paths: if not sem_path or not os.path.exists(sem_path): continue for p in os.listdir(sem_path): full_path = os.path.join(sem_path, p) if os.path.isfile(full_path): (name, ext) = os.path.splitext(p) canon_name = helpers.canon_sem_name(name) if canon_name != name: new_path = os.path.join(sem_path, canon_name + ext) shutil.move(full_path, new_path) am_adjusted += 1 return am_adjusted def _migrate_legacy_sems(cloud): legacy_adjust = { "apt-update-upgrade": [ "apt_configure", "package_update_upgrade_install", ], } paths = (cloud.paths.get_ipath("sem"), cloud.paths.get_cpath("sem")) for sem_path in paths: if not sem_path or not os.path.exists(sem_path): continue sem_helper = helpers.FileSemaphores(sem_path) for (mod_name, migrate_to) in legacy_adjust.items(): possibles = [mod_name, helpers.canon_sem_name(mod_name)] old_exists = [] for p in os.listdir(sem_path): (name, _ext) = os.path.splitext(p) if name in possibles and os.path.isfile(p): old_exists.append(p) for p in old_exists: util.del_file(os.path.join(sem_path, p)) (_name, freq) = os.path.splitext(p) for m in migrate_to: LOG.debug( "Migrating %s => %s with the same frequency", p, m ) with sem_helper.lock(m, freq): pass def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: 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 ) _migrate_legacy_sems(cloud)
[-] cc_scripts_per_once.py
[edit]
[-] cc_wireguard.py
[edit]
[-] cc_bootcmd.py
[edit]
[-] cc_timezone.py
[edit]
[-] cc_ntp.py
[edit]
[+]
schemas
[-] cc_update_etc_hosts.py
[edit]
[-] cc_install_hotplug.py
[edit]
[-] cc_disable_ec2_metadata.py
[edit]
[-] cc_salt_minion.py
[edit]
[-] cc_resolv_conf.py
[edit]
[-] cc_keyboard.py
[edit]
[-] cc_migrator.py
[edit]
[-] cc_scripts_per_instance.py
[edit]
[-] cc_chef.py
[edit]
[-] cc_rightscale_userdata.py
[edit]
[-] cc_users_groups.py
[edit]
[-] cc_snap.py
[edit]
[-] cc_keys_to_console.py
[edit]
[-] cc_landscape.py
[edit]
[-] cc_apt_pipelining.py
[edit]
[-] cc_zypper_add_repo.py
[edit]
[-] cc_apt_configure.py
[edit]
[-] cc_write_files.py
[edit]
[-] cc_power_state_change.py
[edit]
[-] cc_seed_random.py
[edit]
[-] __init__.py
[edit]
[-] cc_ssh_authkey_fingerprints.py
[edit]
[-] cc_final_message.py
[edit]
[-] cc_fan.py
[edit]
[-] cc_lxd.py
[edit]
[-] cc_mcollective.py
[edit]
[-] cc_mounts.py
[edit]
[-] cc_scripts_vendor.py
[edit]
[-] cc_write_files_deferred.py
[edit]
[-] cc_update_hostname.py
[edit]
[-] cc_scripts_user.py
[edit]
[-] cc_growpart.py
[edit]
[-] cc_ubuntu_autoinstall.py
[edit]
[-] cc_yum_add_repo.py
[edit]
[-] cc_package_update_upgrade_install.py
[edit]
[+]
__pycache__
[-] cc_runcmd.py
[edit]
[-] cc_ansible.py
[edit]
[-] cc_ca_certs.py
[edit]
[-] schema.py
[edit]
[-] cc_phone_home.py
[edit]
[-] cc_disk_setup.py
[edit]
[-] cc_apk_configure.py
[edit]
[-] cc_ssh_import_id.py
[edit]
[-] cc_ssh.py
[edit]
[-] cc_rsyslog.py
[edit]
[-] cc_ubuntu_drivers.py
[edit]
[-] cc_resizefs.py
[edit]
[-] cc_locale.py
[edit]
[-] cc_puppet.py
[edit]
[-] cc_grub_dpkg.py
[edit]
[-] cc_set_hostname.py
[edit]
[-] cc_rh_subscription.py
[edit]
[-] cc_scripts_per_boot.py
[edit]
[-] cc_ubuntu_advantage.py
[edit]
[-] cc_set_passwords.py
[edit]
[+]
..
[-] cc_reset_rmc.py
[edit]
[-] cc_byobu.py
[edit]
[-] modules.py
[edit]
[-] cc_spacewalk.py
[edit]