/snap/core24/1643/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.py137980644editdlrm
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.py34360644editdlrm
cc_spacewalk.py27080644editdlrm
cc_ssh.py112240644editdlrm
cc_ssh_authkey_fingerprints.py38500644editdlrm
cc_ssh_import_id.py55710644editdlrm
cc_timezone.py11570644editdlrm
cc_ubuntu_autoinstall.py13040644editdlrm
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: /snap/core24/1643/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_drivers.py (4174B)
# This file is part of cloud-init. See LICENSE file for license information. """Ubuntu Drivers: Interact with third party drivers in Ubuntu.""" import logging import os from cloudinit.cloud import Cloud from cloudinit.distros import Distro try: import debconf HAS_DEBCONF = True except ImportError: debconf = None HAS_DEBCONF = False from cloudinit import subp, temp_utils, type_utils, util from cloudinit.config import Config from cloudinit.config.schema import MetaSchema from cloudinit.settings import PER_INSTANCE LOG = logging.getLogger(__name__) meta: MetaSchema = { "id": "cc_ubuntu_drivers", "distros": ["ubuntu"], "frequency": PER_INSTANCE, "activate_by_schema_keys": ["drivers"], } OLD_UBUNTU_DRIVERS_STDERR_NEEDLE = ( "ubuntu-drivers: error: argument : invalid choice: 'install'" ) # Use a debconf template to configure a global debconf variable # (linux/nvidia/latelink) setting this to "true" allows the # 'linux-restricted-modules' deb to accept the NVIDIA EULA and the package # will automatically link the drivers to the running kernel. NVIDIA_DEBCONF_CONTENT = """\ Template: linux/nvidia/latelink Type: boolean Default: true Description: Late-link NVIDIA kernel modules? Enable this to link the NVIDIA kernel modules in cloud-init and make them available for use. """ X_LOADTEMPLATEFILE = "X_LOADTEMPLATEFILE" def install_drivers(cfg, pkg_install_func, distro: Distro): if not isinstance(cfg, dict): raise TypeError( "'drivers' config expected dict, found '%s': %s" % (type_utils.obj_name(cfg), cfg) ) cfgpath = "nvidia/license-accepted" # Call translate_bool to ensure that we treat string values like "yes" as # acceptance and _don't_ treat string values like "nah" as acceptance # because they're True-ish nv_acc = util.translate_bool(util.get_cfg_by_path(cfg, cfgpath)) if not nv_acc: LOG.debug("Not installing NVIDIA drivers. %s=%s", cfgpath, nv_acc) return if not subp.which("ubuntu-drivers"): LOG.debug( "'ubuntu-drivers' command not available. " "Installing ubuntu-drivers-common" ) pkg_install_func(["ubuntu-drivers-common"]) driver_arg = "nvidia" version_cfg = util.get_cfg_by_path(cfg, "nvidia/version") if version_cfg: driver_arg += ":{}".format(version_cfg) LOG.debug( "Installing and activating NVIDIA drivers (%s=%s, version=%s)", cfgpath, nv_acc, version_cfg if version_cfg else "latest", ) # Register and set debconf selection linux/nvidia/latelink = true tdir = temp_utils.mkdtemp(dir=distro.get_tmp_exec_path(), needs_exe=True) debconf_file = os.path.join(tdir, "nvidia.template") try: util.write_file(debconf_file, NVIDIA_DEBCONF_CONTENT) with debconf.DebconfCommunicator("cloud-init") as dc: dc.command(X_LOADTEMPLATEFILE, debconf_file) except Exception as e: util.logexc( LOG, "Failed to register NVIDIA debconf template: %s", str(e) ) raise finally: if os.path.isdir(tdir): util.del_dir(tdir) try: subp.subp(["ubuntu-drivers", "install", "--gpgpu", driver_arg]) except subp.ProcessExecutionError as exc: if OLD_UBUNTU_DRIVERS_STDERR_NEEDLE in exc.stderr: LOG.warning( "the available version of ubuntu-drivers is" " too old to perform requested driver installation" ) elif "No drivers found for installation." in exc.stdout: LOG.warning("ubuntu-drivers found no drivers for installation") raise def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: if "drivers" not in cfg: LOG.debug("Skipping module named %s, no 'drivers' key in config", name) return if not HAS_DEBCONF: LOG.warning( "Skipping module named %s, 'python3-debconf' is not installed", name, ) return install_drivers( cfg["drivers"], cloud.distro.install_packages, cloud.distro )