summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig/interface.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-09-03 14:33:22 +0200
committerChristian Breunig <christian@breunig.cc>2023-09-03 14:33:22 +0200
commit725b6e0454427b8c2b3a507c61d6192ca7522a7e (patch)
treefa8f84eafe4951d4e5081bbd8462ce5447ccae3f /python/vyos/ifconfig/interface.py
parent6ef163baa783c4bbda06493347b845529ae6b3e4 (diff)
downloadvyos-1x-725b6e0454427b8c2b3a507c61d6192ca7522a7e.tar.gz
vyos-1x-725b6e0454427b8c2b3a507c61d6192ca7522a7e.zip
netns: T5241: provide is_netns_interface utility helper
Diffstat (limited to 'python/vyos/ifconfig/interface.py')
-rw-r--r--python/vyos/ifconfig/interface.py14
1 files changed, 3 insertions, 11 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 20ea66953..e24485132 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -38,6 +38,7 @@ from vyos.utils.dict import dict_search
from vyos.utils.file import read_file
from vyos.utils.network import get_interface_config
from vyos.utils.network import get_interface_namespace
+from vyos.utils.network import is_netns_interface
from vyos.utils.process import is_systemd_service_active
from vyos.utils.process import run
from vyos.template import is_ipv4
@@ -61,15 +62,6 @@ from netaddr import mac_unix_expanded
link_local_prefix = 'fe80::/64'
-
-def _interface_exists_in_netns(interface_name, netns):
- from vyos.util import rc_cmd
- rc, out = rc_cmd(f'ip netns exec {netns} ip link show dev {interface_name}')
- if rc == 0:
- return True
- return False
-
-
class Interface(Control):
# This is the class which will be used to create
# self.operational, it allows subclasses, such as
@@ -572,7 +564,7 @@ class Interface(Control):
return None
# Check if interface realy exists in namespace
- if _interface_exists_in_netns(self.ifname, netns):
+ if is_netns_interface(self.ifname, netns):
self._cmd(f'ip netns exec {netns} ip link del dev {self.ifname}')
return
@@ -1514,7 +1506,7 @@ class Interface(Control):
# Since the interface is pushed onto a separate logical stack
# Configure NETNS
if dict_search('netns', config) != None:
- if not _interface_exists_in_netns(self.ifname, self.config['netns']):
+ if not is_netns_interface(self.ifname, self.config['netns']):
self.set_netns(config.get('netns', ''))
else:
self.del_netns(config.get('netns', ''))