From 79abc95eff245c7bedf496781bbe74a6e40c9ce5 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sat, 8 Jul 2023 17:27:42 +0200 Subject: vyos.utils: T5195: add network namespace helper interface_exists_in_netns() --- python/vyos/utils/network.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'python/vyos/utils') diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py index 72b7ca6da..7386d44f0 100644 --- a/python/vyos/utils/network.py +++ b/python/vyos/utils/network.py @@ -15,7 +15,6 @@ import os - def get_protocol_by_name(protocol_name): """Get protocol number by protocol name @@ -28,3 +27,10 @@ def get_protocol_by_name(protocol_name): return protocol_number except socket.error: return protocol_name + +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 -- cgit v1.2.3