diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-09-15 15:34:57 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-09-20 21:28:53 +0200 |
commit | 8fe9187419fc77df156bb0cbba3a5ca1d61cc36f (patch) | |
tree | 9f3cc41a56c8f6ead7a02922c99860b1404a9368 /python | |
parent | f56b4e190e741bdb2d19d14f2b7004fedc76951c (diff) | |
download | vyos-1x-8fe9187419fc77df156bb0cbba3a5ca1d61cc36f.tar.gz vyos-1x-8fe9187419fc77df156bb0cbba3a5ca1d61cc36f.zip |
Python/ifconfig: T1557: use proper inheritance levels on remove()
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 7ebe1248e..980577965 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -125,23 +125,14 @@ class Interface: >>> i = Interface('eth0') >>> 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() + # Ethernet interfaces can not be removed + if type(self) == type(EthernetIf): + return + # NOTE (Improvement): # after interface removal no other commands should be allowed # to be called and instead should raise an Exception: @@ -1009,6 +1000,31 @@ class VLANIf(Interface): def __init__(self, ifname, type=None): super().__init__(ifname, type) + def remove(self): + """ + Remove interface from operating system. Removing the interface + deconfigures all assigned IP addresses and clear possible DHCP(v6) + client processes. + + Example: + >>> from vyos.ifconfig import Interface + >>> i = Interface('eth0') + >>> 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 + super().remove() + + def add_vlan(self, vlan_id, ethertype='', ingress_qos='', egress_qos=''): """ A virtual LAN (VLAN) is any broadcast domain that is partitioned and @@ -1074,9 +1090,6 @@ class EthernetIf(VLANIf): def __init__(self, ifname): super().__init__(ifname) - def remove(self): - raise OSError('Ethernet interfaces can not be removed') - def get_driver_name(self): """ Return the driver name used by NIC. Some NICs don't support all |