summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-03-23 16:47:15 +0100
committerGitHub <noreply@github.com>2024-03-23 16:47:15 +0100
commita72102b89566451bce40beb1ffdb5d2bf0b1dcc2 (patch)
tree56bc8c3d10036bc92822389ff2349144399cf40b /python/vyos
parent9cc20ffadc74d4e5e082e9335547f6fe14492b5c (diff)
parent6c5153fc6adad069b428d7337c0afa88e5f39c55 (diff)
downloadvyos-1x-a72102b89566451bce40beb1ffdb5d2bf0b1dcc2.tar.gz
vyos-1x-a72102b89566451bce40beb1ffdb5d2bf0b1dcc2.zip
Merge pull request #3174 from vyos/mergify/bp/sagitta/pr-3173
vyos.configverify: T6131: verify_interface_exists() checks CLI interfaces, too (backport #3173)
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/configverify.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py
index 5d3723876..6508ccdd9 100644
--- a/python/vyos/configverify.py
+++ b/python/vyos/configverify.py
@@ -269,14 +269,33 @@ def verify_bridge_delete(config):
raise ConfigError(f'Interface "{interface}" cannot be deleted as it '
f'is a member of bridge "{bridge_name}"!')
-def verify_interface_exists(ifname):
+def verify_interface_exists(ifname, warning_only=False):
"""
Common helper function used by interface implementations to perform
- recurring validation if an interface actually exists.
+ recurring validation if an interface actually exists. We first probe
+ if the interface is defined on the CLI, if it's not found we try if
+ it exists at the OS level.
"""
import os
- if not os.path.exists(f'/sys/class/net/{ifname}'):
- raise ConfigError(f'Interface "{ifname}" does not exist!')
+ from vyos.base import Warning
+ from vyos.configquery import ConfigTreeQuery
+ from vyos.utils.dict import dict_search_recursive
+
+ # Check if interface is present in CLI config
+ config = ConfigTreeQuery()
+ tmp = config.get_config_dict(['interfaces'], get_first_key=True)
+ if bool(list(dict_search_recursive(tmp, ifname))):
+ return True
+
+ # Interface not found on CLI, try Linux Kernel
+ if os.path.exists(f'/sys/class/net/{ifname}'):
+ return True
+
+ message = f'Interface "{ifname}" does not exist!'
+ if warning_only:
+ Warning(message)
+ return False
+ raise ConfigError(message)
def verify_source_interface(config):
"""