summaryrefslogtreecommitdiff
path: root/python/vyos/interfaces.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-20 11:54:12 +0200
committerChristian Poessinger <christian@poessinger.com>2019-08-20 11:55:07 +0200
commit34e69abedb61b293dee097e67ecda45457da1b75 (patch)
tree8f454d8396e041426c4dcd1513be8be2f70bb077 /python/vyos/interfaces.py
parentdc0f641956d002fa8588ef8d1213791cf36e92f2 (diff)
downloadvyos-1x-34e69abedb61b293dee097e67ecda45457da1b75.tar.gz
vyos-1x-34e69abedb61b293dee097e67ecda45457da1b75.zip
vyos.interfaces: T1595: add method to query for interface type
As of now we only could list the available interfaces for a given interface type. There was no reverse mapping available which told us that interface eth0.201 is an ethernet interface or vtun0 is openvpn.
Diffstat (limited to 'python/vyos/interfaces.py')
-rw-r--r--python/vyos/interfaces.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/python/vyos/interfaces.py b/python/vyos/interfaces.py
index 2e8ee4feb..d69ce9d04 100644
--- a/python/vyos/interfaces.py
+++ b/python/vyos/interfaces.py
@@ -43,3 +43,14 @@ def list_interfaces_of_type(typ):
else:
r = re.compile('^{0}\d+'.format(types_data[typ]))
return list(filter(lambda i: re.match(r, i), all_intfs))
+
+def get_type_of_interface(intf):
+ with open(intf_type_data_file, 'r') as f:
+ types_data = json.load(f)
+
+ for key,val in types_data.items():
+ r = re.compile('^{0}\d+'.format(val))
+ if re.match(r, intf):
+ return key
+
+ raise ValueError("No type found for interface name: {0}".format(intf))