blob: 0759aaa2b10ee5eb428de2685fc93c9852db36d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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))
|