vlans: allow specifying native VLAN for tagged interfaces
This commit is contained in:
parent
cbd930f76f
commit
797f26b58e
1 changed files with 16 additions and 19 deletions
35
vlans.py
35
vlans.py
|
@ -119,8 +119,13 @@ class SetVLANScript(Script):
|
||||||
|
|
||||||
def run(self, data, commit):
|
def run(self, data, commit):
|
||||||
all_ports = list(data['switch_ports'])
|
all_ports = list(data['switch_ports'])
|
||||||
|
untagged_vlan = data['untagged_vlan']
|
||||||
|
tagged_vlans = list(data['tagged_vlans'])
|
||||||
modified_switches = set()
|
modified_switches = set()
|
||||||
|
|
||||||
|
if not untagged_vlan and not tagged_vlans:
|
||||||
|
raise AbortScript('at least one VLAN must be specified')
|
||||||
|
|
||||||
# Trace doesn’t work rear ports for some reason, so do it manually.
|
# Trace doesn’t work rear ports for some reason, so do it manually.
|
||||||
# Assumes this layout (f=front port, r=rear port, i=interface, ---=cable):
|
# Assumes this layout (f=front port, r=rear port, i=interface, ---=cable):
|
||||||
# 1f:012.23:r1 --- 23r:panel-012:f23 --- 46i:sw-xyzzy
|
# 1f:012.23:r1 --- 23r:panel-012:f23 --- 46i:sw-xyzzy
|
||||||
|
@ -132,27 +137,19 @@ class SetVLANScript(Script):
|
||||||
|
|
||||||
for port in all_ports:
|
for port in all_ports:
|
||||||
port.enabled = data['enable']
|
port.enabled = data['enable']
|
||||||
match len(data['vlans']):
|
if tagged_vlans:
|
||||||
case 0:
|
self.log_info(f'{port.device.name} {port} is tagged')
|
||||||
port.mode = 'access'
|
port.mode = 'tagged'
|
||||||
port.save()
|
port.save()
|
||||||
port.tagged_vlans.clear()
|
port.tagged_vlans.set(tagged_vlans)
|
||||||
port.untagged_vlan = None
|
else:
|
||||||
case 1:
|
self.log_info(f'{port.device.name} {port} is access')
|
||||||
port.mode = 'access'
|
port.mode = 'access'
|
||||||
port.save()
|
port.save()
|
||||||
port.tagged_vlans.clear()
|
port.untagged_vlan = untagged_vlan
|
||||||
port.untagged_vlan = data['vlans'][0]
|
|
||||||
case _:
|
|
||||||
port.mode = 'tagged'
|
|
||||||
port.save()
|
|
||||||
port.tagged_vlans.set(data['vlans'])
|
|
||||||
port.untagged_vlan = None
|
|
||||||
port.full_clean()
|
port.full_clean()
|
||||||
port.save()
|
port.save()
|
||||||
modified_switches.add(port.device.name)
|
modified_switches.add(port.device.name)
|
||||||
|
self.log_info(f'{port.device.name} {port} is {port.mode} with untagged_vlan: {port.untagged_vlan} tagged_vlans: {[v.vid for v in port.tagged_vlans.all()]}')
|
||||||
self.log_info(f'{port.device.name} {port} is {port.mode} for {",".join(str(vlan.vid) for vlan in data["vlans"])}')
|
|
||||||
|
|
||||||
self.log_success(f'modified switches {",".join(sorted(modified_switches))}')
|
self.log_success(f'modified switches {",".join(sorted(modified_switches))}')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue