summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-04-01 20:38:56 +0200
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-04-02 16:33:59 +0000
commitb3fb51cd799d231d16425faa1495bc6b9188d814 (patch)
tree2c16e8b4d441308462f18644efa6d0270ff826c2 /python/vyos
parent9f831714ef0f32264e7046a5ecb86d74f24ec4ac (diff)
downloadvyos-1x-b3fb51cd799d231d16425faa1495bc6b9188d814.tar.gz
vyos-1x-b3fb51cd799d231d16425faa1495bc6b9188d814.zip
utils: T5738: always use vyos.utils.network.interface_exists over os.path.exists
(cherry picked from commit 5bb27f0c6220fd940b63cdd37a60c312c0ac3efd)
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/configverify.py9
-rw-r--r--python/vyos/template.py3
2 files changed, 7 insertions, 5 deletions
diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py
index 6508ccdd9..894dc3286 100644
--- a/python/vyos/configverify.py
+++ b/python/vyos/configverify.py
@@ -206,13 +206,13 @@ def verify_mirror_redirect(config):
It makes no sense to mirror traffic back at yourself!
"""
- import os
+ from vyos.utils.network import interface_exists
if {'mirror', 'redirect'} <= set(config):
raise ConfigError('Mirror and redirect can not be enabled at the same time!')
if 'mirror' in config:
for direction, mirror_interface in config['mirror'].items():
- if not os.path.exists(f'/sys/class/net/{mirror_interface}'):
+ if not interface_exists(mirror_interface):
raise ConfigError(f'Requested mirror interface "{mirror_interface}" '\
'does not exist!')
@@ -222,7 +222,7 @@ def verify_mirror_redirect(config):
if 'redirect' in config:
redirect_ifname = config['redirect']
- if not os.path.exists(f'/sys/class/net/{redirect_ifname}'):
+ if not interface_exists(redirect_ifname):
raise ConfigError(f'Requested redirect interface "{redirect_ifname}" '\
'does not exist!')
@@ -280,6 +280,7 @@ def verify_interface_exists(ifname, warning_only=False):
from vyos.base import Warning
from vyos.configquery import ConfigTreeQuery
from vyos.utils.dict import dict_search_recursive
+ from vyos.utils.network import interface_exists
# Check if interface is present in CLI config
config = ConfigTreeQuery()
@@ -288,7 +289,7 @@ def verify_interface_exists(ifname, warning_only=False):
return True
# Interface not found on CLI, try Linux Kernel
- if os.path.exists(f'/sys/class/net/{ifname}'):
+ if interface_exists(ifname):
return True
message = f'Interface "{ifname}" does not exist!'
diff --git a/python/vyos/template.py b/python/vyos/template.py
index d1b3e8fa8..ffccae9a1 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -294,7 +294,8 @@ def network_from_ipv4(address):
@register_filter('is_interface')
def is_interface(interface):
""" Check if parameter is a valid local interface name """
- return os.path.exists(f'/sys/class/net/{interface}')
+ from vyos.utils.network import interface_exists
+ return interface_exists(interface)
@register_filter('is_ip')
def is_ip(addr):