/usr/lib/python3/dist-packages/cloudinit/config
NameSizeModeActions
schemas/-0755rm
__pycache__/-0755rm
cc_ansible.py107270644editdlrm
cc_apk_configure.py43310644editdlrm
cc_apt_configure.py391700644editdlrm
cc_apt_pipelining.py19090644editdlrm
cc_bootcmd.py16900644editdlrm
cc_byobu.py28000644editdlrm
cc_ca_certs.py91260644editdlrm
cc_chef.py135020644editdlrm
cc_disable_ec2_metadata.py16420644editdlrm
cc_disk_setup.py526220644editdlrm
cc_fan.py19970644editdlrm
cc_final_message.py25610644editdlrm
cc_growpart.py188090644editdlrm
cc_grub_dpkg.py55240644editdlrm
cc_install_hotplug.py32600644editdlrm
cc_keyboard.py15270644editdlrm
cc_keys_to_console.py21380644editdlrm
cc_landscape.py31310644editdlrm
cc_locale.py12110644editdlrm
cc_lxd.py137610644editdlrm
cc_mcollective.py42070644editdlrm
cc_mounts.py193220644editdlrm
cc_ntp.py195280644editdlrm
cc_package_update_upgrade_install.py39090644editdlrm
cc_phone_home.py38290644editdlrm
cc_power_state_change.py61330644editdlrm
cc_puppet.py109760644editdlrm
cc_raspberry_pi.py65990644editdlrm
cc_reset_rmc.py44320644editdlrm
cc_resizefs.py108800644editdlrm
cc_resolv_conf.py32060644editdlrm
cc_rh_subscription.py165450644editdlrm
cc_rsyslog.py117450644editdlrm
cc_runcmd.py16400644editdlrm
cc_salt_minion.py40530644editdlrm
cc_scripts_per_boot.py12980644editdlrm
cc_scripts_per_instance.py12950644editdlrm
cc_scripts_per_once.py12710644editdlrm
cc_scripts_user.py12820644editdlrm
cc_scripts_vendor.py12920644editdlrm
cc_seed_random.py30680644editdlrm
cc_set_hostname.py34810644editdlrm
cc_set_passwords.py105660644editdlrm
cc_snap.py34000644editdlrm
cc_spacewalk.py27080644editdlrm
cc_ssh.py112240644editdlrm
cc_ssh_authkey_fingerprints.py38500644editdlrm
cc_ssh_import_id.py55710644editdlrm
cc_timezone.py11570644editdlrm
cc_ubuntu_autoinstall.py12670644editdlrm
cc_ubuntu_drivers.py41740644editdlrm
cc_ubuntu_pro.py139710644editdlrm
cc_update_etc_hosts.py25220644editdlrm
cc_update_hostname.py22300644editdlrm
cc_users_groups.py29300644editdlrm
cc_wireguard.py68250644editdlrm
cc_write_files.py62960644editdlrm
cc_write_files_deferred.py13080644editdlrm
cc_yum_add_repo.py46410644editdlrm
cc_zypper_add_repo.py50520644editdlrm
modules.py136430644editdlrm
schema.py520490644editdlrm
__init__.py400644editdlrm
Edit: /usr/lib/python3/dist-packages/cloudinit/config/cc_raspberry_pi.py (6599B)
# Copyright (C) 2024-2025, Raspberry Pi Ltd. # # Author: Paul Oberosler # # This file is part of cloud-init. See LICENSE file for license information. import logging from typing import Union from cloudinit import subp from cloudinit.cloud import Cloud from cloudinit.config import Config from cloudinit.config.schema import MetaSchema from cloudinit.settings import PER_INSTANCE LOG = logging.getLogger(__name__) RPI_BASE_KEY = "rpi" RPI_INTERFACES_KEY = "interfaces" ENABLE_RPI_CONNECT_KEY = "enable_rpi_connect" SUPPORTED_INTERFACES = { "spi": "do_spi", "i2c": "do_i2c", "serial": "do_serial", "onewire": "do_onewire", } RASPI_CONFIG_SERIAL_CONS_FN = "do_serial_cons" RASPI_CONFIG_SERIAL_HW_FN = "do_serial_hw" meta: MetaSchema = { "id": "cc_raspberry_pi", "distros": ["raspberry-pi-os"], "frequency": PER_INSTANCE, "activate_by_schema_keys": [RPI_BASE_KEY], } def configure_rpi_connect(enable: bool) -> None: LOG.debug("Configuring rpi-connect: %s", enable) num = 0 if enable else 1 try: subp.subp(["/usr/bin/raspi-config", "do_rpi_connect", str(num)]) except subp.ProcessExecutionError as e: LOG.error("Failed to configure rpi-connect: %s", e) def is_pifive() -> bool: try: subp.subp(["/usr/bin/raspi-config", "nonint", "is_pifive"]) return True except subp.ProcessExecutionError: return False def configure_serial_interface( cfg: Union[dict, bool], instCfg: Config, cloud: Cloud ) -> None: def get_bool_field(cfg_dict: dict, name: str, default=False): val = cfg_dict.get(name, default) if not isinstance(val, bool): LOG.warning( "Invalid value for %s.serial.%s: %s", RPI_INTERFACES_KEY, name, val, ) return default return val enable_console = False enable_hw = False if isinstance(cfg, dict): enable_console = get_bool_field(cfg, "console") enable_hw = get_bool_field(cfg, "hardware") elif isinstance(cfg, bool): # default to enabling console as if < pi5 # this will also enable the hardware enable_console = cfg if not is_pifive() and enable_console: # only pi5 has 2 usable UARTs # on other models, enabling the console # will also block the other UART enable_hw = True try: subp.subp( [ "/usr/bin/raspi-config", "nonint", RASPI_CONFIG_SERIAL_CONS_FN, str(0 if enable_console else 1), ] ) try: subp.subp( [ "/usr/bin/raspi-config", "nonint", RASPI_CONFIG_SERIAL_HW_FN, str(0 if enable_hw else 1), ] ) except subp.ProcessExecutionError as e: LOG.error("Failed to configure serial hardware: %s", e) # Reboot to apply changes cmd = cloud.distro.shutdown_command( mode="reboot", delay="now", message="Rebooting to apply serial console changes", ) subp.subp(cmd) except subp.ProcessExecutionError as e: LOG.error("Failed to configure serial console: %s", e) def configure_interface(iface: str, enable: bool) -> None: assert ( iface in SUPPORTED_INTERFACES.keys() and iface != "serial" ), f"Unsupported interface: {iface}" try: subp.subp( [ "/usr/bin/raspi-config", "nonint", SUPPORTED_INTERFACES[iface], str(0 if enable else 1), ] ) except subp.ProcessExecutionError as e: LOG.error("Failed to configure %s: %s", iface, e) def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: if RPI_BASE_KEY not in cfg: return elif not isinstance(cfg[RPI_BASE_KEY], dict): LOG.warning( "Invalid value for %s: %s", RPI_BASE_KEY, cfg[RPI_BASE_KEY], ) return elif not cfg[RPI_BASE_KEY]: LOG.debug("Empty value for %s. Skipping...", RPI_BASE_KEY) return for key in cfg[RPI_BASE_KEY]: if key == ENABLE_RPI_CONNECT_KEY: enable = cfg[RPI_BASE_KEY][key] if isinstance(enable, bool): configure_rpi_connect(enable) else: LOG.warning( "Invalid value for %s: %s", ENABLE_RPI_CONNECT_KEY, enable ) continue elif key == RPI_INTERFACES_KEY: if not isinstance(cfg[RPI_BASE_KEY][key], dict): LOG.warning( "Invalid value for %s: %s", RPI_BASE_KEY, cfg[RPI_BASE_KEY][key], ) return elif not cfg[RPI_BASE_KEY][key]: LOG.debug("Empty value for %s. Skipping...", key) return subkeys = list(cfg[RPI_BASE_KEY][key].keys()) # Move " serial" to the end if it exists if "serial" in subkeys: subkeys.append(subkeys.pop(subkeys.index("serial"))) # check for supported ARM interfaces for subkey in subkeys: if subkey not in SUPPORTED_INTERFACES.keys(): LOG.warning( "Invalid key for %s: %s", RPI_INTERFACES_KEY, subkey ) continue enable = cfg[RPI_BASE_KEY][key][subkey] if subkey == "serial": if not isinstance(enable, (dict, bool)): LOG.warning( "Invalid value for %s.%s: %s", RPI_INTERFACES_KEY, subkey, enable, ) else: configure_serial_interface(enable, cfg, cloud) continue if isinstance(enable, bool): configure_interface(subkey, enable) else: LOG.warning( "Invalid value for %s.%s: %s", RPI_INTERFACES_KEY, subkey, enable, ) else: LOG.warning("Unsupported key: %s", key) continue