summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig/__init__.py1
-rw-r--r--python/vyos/ifconfig/bond.py9
-rw-r--r--python/vyos/ifconfig/ethernet.py8
-rw-r--r--python/vyos/ifconfig/macvlan.py5
-rw-r--r--python/vyos/ifconfig/vlan.py35
-rw-r--r--python/vyos/ifconfig/wireless.py5
-rw-r--r--python/vyos/ifconfig_vlan.py1
7 files changed, 38 insertions, 26 deletions
diff --git a/python/vyos/ifconfig/__init__.py b/python/vyos/ifconfig/__init__.py
index 7b89d4cad..d6584215b 100644
--- a/python/vyos/ifconfig/__init__.py
+++ b/python/vyos/ifconfig/__init__.py
@@ -24,7 +24,6 @@ from vyos.ifconfig.geneve import GeneveIf
from vyos.ifconfig.loopback import LoopbackIf
from vyos.ifconfig.macvlan import MACVLANIf
from vyos.ifconfig.stp import STPIf
-from vyos.ifconfig.vlan import VLANIf
from vyos.ifconfig.vxlan import VXLANIf
from vyos.ifconfig.wireguard import WireGuardIf
from vyos.ifconfig.vtun import VTunIf
diff --git a/python/vyos/ifconfig/bond.py b/python/vyos/ifconfig/bond.py
index af4082f8f..3c26b9b95 100644
--- a/python/vyos/ifconfig/bond.py
+++ b/python/vyos/ifconfig/bond.py
@@ -16,13 +16,14 @@
import os
from vyos.ifconfig.interface import Interface
-from vyos.ifconfig.vlan import VLANIf
+from vyos.ifconfig.vlan import VLAN
from vyos.validate import *
@Interface.register
-class BondIf(VLANIf):
+@VLAN.enable
+class BondIf(Interface):
"""
The Linux bonding driver provides a method for aggregating multiple network
interfaces into a single logical "bonded" interface. The behavior of the
@@ -44,7 +45,7 @@ class BondIf(VLANIf):
},
}
- _sysfs_set = {**VLANIf._sysfs_set, **{
+ _sysfs_set = {**Interface._sysfs_set, **{
'bond_hash_policy': {
'validate': lambda v: assert_list(v, ['layer2', 'layer2+3', 'layer3+4', 'encap2+3', 'encap3+4']),
'location': '/sys/class/net/{ifname}/bonding/xmit_hash_policy',
@@ -77,7 +78,7 @@ class BondIf(VLANIf):
},
}}
- _sysfs_get = {**VLANIf._sysfs_get, **{
+ _sysfs_get = {**Interface._sysfs_get, **{
'bond_arp_ip_target': {
'location': '/sys/class/net/{ifname}/bonding/arp_ip_target',
}
diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py
index 606161121..850bb34ae 100644
--- a/python/vyos/ifconfig/ethernet.py
+++ b/python/vyos/ifconfig/ethernet.py
@@ -16,14 +16,15 @@
import os
import re
-from vyos.ifconfig.vlan import VLANIf
from vyos.ifconfig.interface import Interface
+from vyos.ifconfig.vlan import VLAN
from vyos.validate import *
@Interface.register
-class EthernetIf(VLANIf):
+@VLAN.enable
+class EthernetIf(Interface):
"""
Abstraction of a Linux Ethernet Interface
"""
@@ -42,7 +43,8 @@ class EthernetIf(VLANIf):
}
}
- _command_set = {**VLANIf._command_set, **{
+
+ _command_set = {**Interface._command_set, **{
'gro': {
'validate': lambda v: assert_list(v, ['on', 'off']),
'shellcmd': '/sbin/ethtool -K {ifname} gro {value}',
diff --git a/python/vyos/ifconfig/macvlan.py b/python/vyos/ifconfig/macvlan.py
index a1dca5e41..4e4b563a1 100644
--- a/python/vyos/ifconfig/macvlan.py
+++ b/python/vyos/ifconfig/macvlan.py
@@ -15,11 +15,12 @@
from vyos.ifconfig.interface import Interface
-from vyos.ifconfig.vlan import VLANIf
+from vyos.ifconfig.vlan import VLAN
@Interface.register
-class MACVLANIf(VLANIf):
+@VLAN.enable
+class MACVLANIf(Interface):
"""
Abstraction of a Linux MACvlan interface
"""
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()
diff --git a/python/vyos/ifconfig/wireless.py b/python/vyos/ifconfig/wireless.py
index f94509c80..a1f50b71d 100644
--- a/python/vyos/ifconfig/wireless.py
+++ b/python/vyos/ifconfig/wireless.py
@@ -16,11 +16,12 @@
import os
from vyos.ifconfig.interface import Interface
-from vyos.ifconfig.vlan import VLANIf
+from vyos.ifconfig.vlan import VLAN
@Interface.register
-class WiFiIf(VLANIf):
+@VLAN.enable
+class WiFiIf(Interface):
"""
Handle WIFI/WLAN interfaces.
"""
diff --git a/python/vyos/ifconfig_vlan.py b/python/vyos/ifconfig_vlan.py
index 245453307..2b934cdfc 100644
--- a/python/vyos/ifconfig_vlan.py
+++ b/python/vyos/ifconfig_vlan.py
@@ -14,7 +14,6 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
from netifaces import interfaces
-from vyos.ifconfig import VLANIf
from vyos import ConfigError
def apply_vlan_config(vlan, config):