summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-07-21 15:59:06 +0200
committerChristian Poessinger <christian@poessinger.com>2020-07-25 15:35:06 +0200
commit1a85e758b105d493bb9d95916816bd206345bc5d (patch)
treed8b3e5aa12a539e84f5dc1554adb76811513257c /python/vyos
parent61dccd81a1037c06ae883020db51409dda3e41f9 (diff)
downloadvyos-1x-1a85e758b105d493bb9d95916816bd206345bc5d.tar.gz
vyos-1x-1a85e758b105d493bb9d95916816bd206345bc5d.zip
vyos.util: add common helper to load kernel modules
l2tpv3, wireguard, wirelessmodem, nat all require additional Kernel modules to be present on the system. Each and every interface implemented their own way of loading a module - by copying code. Use a generic function, vyos.util.check_kmod() to load any arbitrary kernel module passed as string or list.
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/util.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 924df6b3a..7234be6cb 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -652,3 +652,12 @@ def get_bridge_member_config(conf, br, intf):
conf.set_level(old_level)
return memberconf
+
+def check_kmod(k_mod):
+ """ Common utility function to load required kernel modules on demand """
+ 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')