diff options
| author | Grant Slater <github@firefishy.com> | 2025-11-10 15:16:38 +0000 |
|---|---|---|
| committer | Grant Slater <github@firefishy.com> | 2026-01-14 15:01:01 +0000 |
| commit | 88b0c27a8d359d992e97c6043207dd877370295e (patch) | |
| tree | bfe3985eecb2c7319440029ccaae5a2bc5746e99 /python | |
| parent | 0c373c7c9cf0fff573e5acc5642f6af63c311da2 (diff) | |
| download | vyos-1x-88b0c27a8d359d992e97c6043207dd877370295e.tar.gz vyos-1x-88b0c27a8d359d992e97c6043207dd877370295e.zip | |
T7101: Add support for hardware watchdog support via systemd
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/utils/kernel.py | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/python/vyos/utils/kernel.py b/python/vyos/utils/kernel.py index 4255d88d5..48a7e88ea 100644 --- a/python/vyos/utils/kernel.py +++ b/python/vyos/utils/kernel.py @@ -19,16 +19,48 @@ import os # https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/net/wireguard/messages.h?h=linux-6.6.y#n45 WIREGUARD_REKEY_AFTER_TIME = 120 + +def load_module(name: str, quiet: bool = True, dry_run: bool = False) -> int: + """Load a kernel module via modprobe. + + Returns the modprobe return code. + """ + + from vyos.utils.process import run + + if is_module_loaded(name): + return 0 + + cmd = ['modprobe'] + if dry_run: + cmd.append('-n') + if quiet: + cmd.append('-q') + cmd.append(name) + return run(cmd) + + +def unload_module(name: str) -> int: + """Unload a kernel module via rmmod. + + Returns the rmmod return code. + """ + + from vyos.utils.process import run + + if not is_module_loaded(name): + return 0 + + return run(['rmmod', name]) + def check_kmod(k_mod): """ Common utility function to load required kernel modules on demand """ from vyos import ConfigError - from vyos.utils.process import call if isinstance(k_mod, str): k_mod = k_mod.split() for module in k_mod: - if not os.path.exists(f'/sys/module/{module}'): - if call(f'modprobe {module}') != 0: - raise ConfigError(f'Loading Kernel module {module} failed') + if load_module(module) != 0: + raise ConfigError(f'Loading Kernel module {module} failed') def is_module_loaded(module): @@ -38,13 +70,11 @@ def is_module_loaded(module): def unload_kmod(k_mod): """ Common utility function to unload required kernel modules on demand """ from vyos import ConfigError - from vyos.utils.process import call if isinstance(k_mod, str): k_mod = k_mod.split() for module in k_mod: - if is_module_loaded(module): - if call(f'rmmod {module}') != 0: - raise ConfigError(f'Unloading Kernel module {module} failed') + if unload_module(module) != 0: + raise ConfigError(f'Unloading Kernel module {module} failed') def list_loaded_modules(): """ Returns the list of currently loaded kernel modules """ |
