summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-09-03 18:58:27 +0200
committerChristian Poessinger <christian@poessinger.com>2019-09-04 11:25:31 +0200
commit1fc4c201d7771ac4164e9480d55a654b7674d098 (patch)
tree62d08c1c8843bc6031278cfa824c74f98e757b78 /python
parent029085250c4e2dea8a98f3031cf6b8037ffdd534 (diff)
downloadvyos-1x-1fc4c201d7771ac4164e9480d55a654b7674d098.tar.gz
vyos-1x-1fc4c201d7771ac4164e9480d55a654b7674d098.zip
bonding: T1614: T1557: add vif/vif-s VLAN interface support
Support for vif-c interfaces is still missing
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig.py47
1 files changed, 46 insertions, 1 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index 1d03e4e74..bb2d23d0d 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -87,7 +87,9 @@ class Interface:
def remove(self):
"""
- Remove system interface
+ 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
@@ -964,10 +966,53 @@ class BridgeIf(Interface):
.format(self._ifname, interface), priority)
+
class EthernetIf(Interface):
def __init__(self, ifname, type=None):
super().__init__(ifname, type)
+ def add_vlan(self, vlan_id, ethertype=''):
+ """
+ A virtual LAN (VLAN) is any broadcast domain that is partitioned and
+ isolated in a computer network at the data link layer (OSI layer 2).
+ Use this function to create a new VLAN interface on a given physical
+ interface.
+
+ This function creates both 802.1q and 802.1ad (Q-in-Q) interfaces. Proto
+ parameter is used to indicate VLAN type.
+
+ A new object of type EthernetIf is returned once the interface has been
+ created.
+ """
+ vlan_ifname = self._ifname + '.' + str(vlan_id)
+ if not os.path.exists('/sys/class/net/{}'.format(vlan_ifname)):
+ self._vlan_id = int(vlan_id)
+
+ if ethertype:
+ self._ethertype = ethertype
+ ethertype='proto {}'.format(ethertype)
+
+ # create interface in the system
+ cmd = 'ip link add link {intf} name {intf}.{vlan} type vlan {proto} id {vlan}'.format(intf=self._ifname, vlan=self._vlan_id, proto=ethertype)
+ self._cmd(cmd)
+
+ # 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 EthernetIf(vlan_ifname)
+
+
+ def del_vlan(self, vlan_id):
+ """
+ Remove VLAN interface from operating system. Removing the interface
+ deconfigures all assigned IP addresses and clear possible DHCP(v6)
+ client processes.
+ """
+ vlan_ifname = self._ifname + '.' + str(vlan_id)
+ tmp = EthernetIf(vlan_ifname)
+ tmp.remove()
+
+
class BondIf(EthernetIf):
"""
The Linux bonding driver provides a method for aggregating multiple network