From fa07179ae7f1dc07e6ccc1b20d2b81384b6efe07 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Wed, 26 Jul 2023 23:14:19 +0200 Subject: openvpn: T4974: dynamically load/unload kernel module --- python/vyos/utils/kernel.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'python/vyos/utils') diff --git a/python/vyos/utils/kernel.py b/python/vyos/utils/kernel.py index 0eb113174..1f3bbdffe 100644 --- a/python/vyos/utils/kernel.py +++ b/python/vyos/utils/kernel.py @@ -25,3 +25,14 @@ def check_kmod(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') + +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 os.path.exists(f'/sys/module/{module}'): + if call(f'rmmod {module}') != 0: + raise ConfigError(f'Unloading Kernel module {module} failed') -- cgit v1.2.3