summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-07-08 17:27:42 +0200
committerChristian Breunig <christian@breunig.cc>2023-07-08 17:27:42 +0200
commit79abc95eff245c7bedf496781bbe74a6e40c9ce5 (patch)
tree0c906e5c6915f0a672f031301bed76263b10ff33
parentedf9186cee3b6360ecd2692c7bd79e4503e7f69d (diff)
downloadvyos-1x-79abc95eff245c7bedf496781bbe74a6e40c9ce5.tar.gz
vyos-1x-79abc95eff245c7bedf496781bbe74a6e40c9ce5.zip
vyos.utils: T5195: add network namespace helper interface_exists_in_netns()
-rw-r--r--python/vyos/utils/network.py8
1 files changed, 7 insertions, 1 deletions
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