From fca8166ba0837add065d3756d4e0919f5a159a4d Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 6 Sep 2019 10:06:00 +0200 Subject: Python/ifconfig: T1557: recursively delete VLAN interfaces on remove() --- python/vyos/ifconfig.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'python/vyos/ifconfig.py') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 084339408..c5d3e447b 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -14,6 +14,7 @@ # License along with this library. If not, see . import os +import re import subprocess import jinja2 @@ -97,6 +98,18 @@ class Interface: >>> i.remove() """ + # do we have sub interfaces (VLANs)? + # we apply a regex matching subinterfaces (indicated by a .) of a + # parent interface. 'bond0(?:\.\d+){1,2}' will match vif and vif-s/vif-c + # subinterfaces + vlan_ifs = [f for f in os.listdir(r'/sys/class/net') \ + if re.match(self._ifname + r'(?:\.\d+){1,2}', f)] + + for vlan in vlan_ifs: + Interface(vlan).remove() + + # All subinterfaces are now removed, continue on the physical interface + # stop DHCP(v6) if running self.del_dhcp() self.del_dhcpv6() -- cgit v1.2.3