summaryrefslogtreecommitdiff
path: root/python/vyos/interfaces.py
diff options
context:
space:
mode:
authorRunar Borge <runar@borge.nu>2018-06-09 22:31:09 +0200
committerRunar Borge <runar@borge.nu>2018-06-09 22:31:09 +0200
commitf3b4cfecbe48c75c88b9396f68c4b9fc2d7babc1 (patch)
treea043804da4a0b841c86455ceb8c9e8d5f73f7717 /python/vyos/interfaces.py
parent06b807f9b898c6bef55c9c0888bf5fd1c96bc9bd (diff)
parente916c9a55ffdff970c1796829d1bee319802b353 (diff)
downloadvyos-1x-f3b4cfecbe48c75c88b9396f68c4b9fc2d7babc1.tar.gz
vyos-1x-f3b4cfecbe48c75c88b9396f68c4b9fc2d7babc1.zip
Merge branch 'current' of git://github.com/vyos/vyos-1x into current
Diffstat (limited to 'python/vyos/interfaces.py')
-rw-r--r--python/vyos/interfaces.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/python/vyos/interfaces.py b/python/vyos/interfaces.py
new file mode 100644
index 000000000..0759aaa2b
--- /dev/null
+++ b/python/vyos/interfaces.py
@@ -0,0 +1,30 @@
+import re
+import json
+
+import netifaces
+
+
+intf_type_data_file = '/usr/share/vyos/interface-types.json'
+
+def list_interfaces():
+ interfaces = netifaces.interfaces()
+
+ # Remove "fake" interfaces associated with drivers
+ for i in ["dummy0", "ip6tnl0", "tunl0", "ip_vti0", "ip6_vti0"]:
+ try:
+ interfaces.remove(i)
+ except ValueError:
+ pass
+
+ return interfaces
+
+def list_interfaces_of_type(typ):
+ with open(intf_type_data_file, 'r') as f:
+ types_data = json.load(f)
+
+ all_intfs = list_interfaces()
+ if not (typ in types_data.keys()):
+ raise ValueError("Unknown interface type: {0}".format(typ))
+ else:
+ r = re.compile('^{0}\d+'.format(types_data[typ]))
+ return list(filter(lambda i: re.match(r, i), all_intfs))