diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-03-24 18:33:42 +0000 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-03-24 18:33:42 +0000 |
commit | 1a57edcb8e3052a70296808d394c3d166bcda275 (patch) | |
tree | bc8032579545e8233d6c3f6be578d49f41e7ae8c /python/vyos/ifconfig/vlan.py | |
parent | 8f02c42286ba92f1aa54502ebb22acd67c2a934d (diff) | |
download | vyos-1x-1a57edcb8e3052a70296808d394c3d166bcda275.tar.gz vyos-1x-1a57edcb8e3052a70296808d394c3d166bcda275.zip |
ifconfig: T2057: convert VLAN to adapter
Diffstat (limited to 'python/vyos/ifconfig/vlan.py')
-rw-r--r-- | python/vyos/ifconfig/vlan.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/python/vyos/ifconfig/vlan.py b/python/vyos/ifconfig/vlan.py index 607e9aeaf..7b1e00d87 100644 --- a/python/vyos/ifconfig/vlan.py +++ b/python/vyos/ifconfig/vlan.py @@ -20,15 +20,23 @@ import re from vyos.ifconfig.interface import Interface -class VLANIf(Interface): +# This is an internal implementation class +class VLAN: """ This class handels the creation and removal of a VLAN interface. It serves as base class for BondIf and EthernetIf. """ - default = { - 'type': 'vlan', - } + _novlan_remove = lambda : None + + @classmethod + def enable (cls,adaptee): + adaptee._novlan_remove = adaptee.remove + adaptee.remove = cls.remove + adaptee.add_vlan = cls.add_vlan + adaptee.del_vlan = cls.del_vlan + adaptee.definition['vlan'] = True + return adaptee def remove(self): """ @@ -61,10 +69,11 @@ class VLANIf(Interface): if re.match(ifname + r'(?:\.\d+)', f)] for vlan in vlan_ifs: - Interface(vlan).remove() + # self.__class__ is already VLAN.enabled + self.__class__(vlan)._novlan_remove() # All subinterfaces are now removed, continue on the physical interface - super().remove() + self._novlan_remove() def add_vlan(self, vlan_id, ethertype='', ingress_qos='', egress_qos=''): """ @@ -87,8 +96,8 @@ class VLANIf(Interface): to VLAN header prio field but for outgoing frames. Example: - >>> from vyos.ifconfig import VLANIf - >>> i = VLANIf('eth0') + >>> from vyos.ifconfig import MACVLANIf + >>> i = MACVLANIf('eth0') >>> i.add_vlan(10) """ vlan_ifname = self.config['ifname'] + '.' + str(vlan_id) @@ -116,7 +125,7 @@ class VLANIf(Interface): # return new object mapping to the newly created interface # we can now work on this object for e.g. IP address setting # or interface description and so on - return VLANIf(vlan_ifname) + return self.__class__(vlan_ifname) def del_vlan(self, vlan_id): """ @@ -125,9 +134,9 @@ class VLANIf(Interface): client processes. Example: - >>> from vyos.ifconfig import VLANIf - >>> i = VLANIf('eth0.10') + >>> from vyos.ifconfig import MACVLANIf + >>> i = MACVLANIf('eth0.10') >>> i.del_vlan() """ - vlan_ifname = self.config['ifname'] + '.' + str(vlan_id) - VLANIf(vlan_ifname).remove() + ifname = self.config['ifname'] + self.__class__(f'{ifname}.{vlan_id}')._novlan_remove() |