summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-04-15 15:29:53 +0200
committerChristian Breunig <christian@breunig.cc>2023-04-15 15:29:53 +0200
commit7700da10b8d1d1b3d0db914ab48aebf8ff536da1 (patch)
treea7551fc3207481b6e01e338536f974c01b687978 /python
parentdcc72b28815421b119e63c5164ecb7948dd73ab3 (diff)
downloadvyos-1x-7700da10b8d1d1b3d0db914ab48aebf8ff536da1.tar.gz
vyos-1x-7700da10b8d1d1b3d0db914ab48aebf8ff536da1.zip
vyos.ifconfig: T2104: support adding and removing VLANs in one call.
VLANIf('eth0.10').remove() will create and remove the VLAN in one command. Thus one can ensure when calling remove() on a VLAN it will always succeed.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig/interface.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index fc33430eb..f62b9f7d2 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -1709,6 +1709,14 @@ class VLANIf(Interface):
if self.exists(f'{self.ifname}'):
return
+ # If source_interface or vlan_id was not explicitly defined (e.g. when
+ # calling VLANIf('eth0.1').remove() we can define source_interface and
+ # vlan_id here, as it's quiet obvious that it would be eth0 in that case.
+ if 'source_interface' not in self.config:
+ self.config['source_interface'] = '.'.join(self.ifname.split('.')[:-1])
+ if 'vlan_id' not in self.config:
+ self.config['vlan_id'] = self.ifname.split('.')[-1]
+
cmd = 'ip link add link {source_interface} name {ifname} type vlan id {vlan_id}'
if 'protocol' in self.config:
cmd += ' protocol {protocol}'