summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-09-06 10:06:00 +0200
committerChristian Poessinger <christian@poessinger.com>2019-09-06 10:13:12 +0200
commitfca8166ba0837add065d3756d4e0919f5a159a4d (patch)
treea19dcdf324ffa1ed8a507c602c2d1d299fdd447a /python
parent1bac4362d007135f91daffc4b0d51783658c10cf (diff)
downloadvyos-1x-fca8166ba0837add065d3756d4e0919f5a159a4d.tar.gz
vyos-1x-fca8166ba0837add065d3756d4e0919f5a159a4d.zip
Python/ifconfig: T1557: recursively delete VLAN interfaces on remove()
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig.py13
1 files changed, 13 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
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()