summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-04-05 15:36:44 +0200
committerChristian Poessinger <christian@poessinger.com>2021-04-05 15:37:04 +0200
commit23598fc082fcf0c02e113586bfc615583a05d2f3 (patch)
treede2198d7d2ed9d2c9659367a6fd473af060a1f23 /python
parent49cfd4e0c56a8b7a85128bfdb4a4e19157137129 (diff)
downloadvyos-1x-23598fc082fcf0c02e113586bfc615583a05d2f3.tar.gz
vyos-1x-23598fc082fcf0c02e113586bfc615583a05d2f3.zip
vyos.template: T3418: add new is_interface helper function
Diffstat (limited to 'python')
-rw-r--r--python/vyos/template.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 85e4d12b3..7810f5edd 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -207,6 +207,11 @@ def network_from_ipv4(address):
cidr_prefix = ip_interface(f'{address}/{netmask}').network
return address_from_cidr(cidr_prefix)
+@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}')
+
@register_filter('is_ip')
def is_ip(addr):
""" Check addr if it is an IPv4 or IPv6 address """