summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_ubuntu_drivers.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/config/cc_ubuntu_drivers.py')
-rw-r--r--cloudinit/config/cc_ubuntu_drivers.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/cloudinit/config/cc_ubuntu_drivers.py b/cloudinit/config/cc_ubuntu_drivers.py
index 15f621a7..a962bce3 100644
--- a/cloudinit/config/cc_ubuntu_drivers.py
+++ b/cloudinit/config/cc_ubuntu_drivers.py
@@ -5,6 +5,14 @@
import os
from textwrap import dedent
+try:
+ import debconf
+
+ HAS_DEBCONF = True
+except ImportError:
+ debconf = None
+ HAS_DEBCONF = False
+
from cloudinit import log as logging
from cloudinit import subp, temp_utils, type_utils, util
from cloudinit.config.schema import MetaSchema, get_meta_doc
@@ -48,10 +56,6 @@ OLD_UBUNTU_DRIVERS_STDERR_NEEDLE = (
# 'linux-restricted-modules' deb to accept the NVIDIA EULA and the package
# will automatically link the drivers to the running kernel.
-# EOL_XENIAL: can then drop this script and use python3-debconf which is only
-# available in Bionic and later. Can't use python3-debconf currently as it
-# isn't in Xenial and doesn't yet support X_LOADTEMPLATEFILE debconf command.
-
NVIDIA_DEBCONF_CONTENT = """\
Template: linux/nvidia/latelink
Type: boolean
@@ -61,13 +65,8 @@ Description: Late-link NVIDIA kernel modules?
make them available for use.
"""
-NVIDIA_DRIVER_LATELINK_DEBCONF_SCRIPT = """\
-#!/bin/sh
-# Allow cloud-init to trigger EULA acceptance via registering a debconf
-# template to set linux/nvidia/latelink true
-. /usr/share/debconf/confmodule
-db_x_loadtemplatefile "$1" cloud-init
-"""
+
+X_LOADTEMPLATEFILE = "X_LOADTEMPLATEFILE"
def install_drivers(cfg, pkg_install_func):
@@ -108,15 +107,10 @@ def install_drivers(cfg, pkg_install_func):
# Register and set debconf selection linux/nvidia/latelink = true
tdir = temp_utils.mkdtemp(needs_exe=True)
debconf_file = os.path.join(tdir, "nvidia.template")
- debconf_script = os.path.join(tdir, "nvidia-debconf.sh")
try:
util.write_file(debconf_file, NVIDIA_DEBCONF_CONTENT)
- util.write_file(
- debconf_script,
- util.encode_text(NVIDIA_DRIVER_LATELINK_DEBCONF_SCRIPT),
- mode=0o755,
- )
- subp.subp([debconf_script, debconf_file])
+ 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)
@@ -143,5 +137,11 @@ def handle(name, cfg, cloud, log, _args):
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)