Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions annet/rulebook/cisco/vlandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ def _process_vlandb(rule, key, diff, hw, explicit_changing, multi_chunk):
if not prefix:
prefix = prefix2

if len(diff[Op.ADDED]) == 1 and len(new) == 0:
# switchport trunk allowed vlan none
yield (True, "%s none" % prefix, None)
return
if explicit_changing and not new:
if diff[Op.ADDED] and not diff[Op.UNCHANGED]:
# switchport trunk allowed vlan none
yield (True, "%s none" % prefix, None)
return
if diff[Op.REMOVED] and not diff[Op.UNCHANGED]:
# no switchport trunk allowed vlan
yield (False, "no %s" % prefix, None)
return

for vlan_id in (set(old_blocks.keys()) - set(new_blocks)) & new:
# Удалено содержимое блока vlan, но сам влан остался
yield (True, "%s %s" % (prefix, vlan_id), old_blocks[vlan_id])
Expand All @@ -47,12 +53,23 @@ def _process_vlandb(rule, key, diff, hw, explicit_changing, multi_chunk):
if removed:
collapsed = collapse_vlandb(removed, hw.Catalyst)
for chunk in _chunked(collapsed, multi_chunk):
yield (False, "no %s%s%s" % (prefix, " remove " if explicit_changing else " ", ",".join(chunk)), None)
if explicit_changing:
yield (True, "%s%s%s" % (prefix, " remove ", ",".join(chunk)), None)
else:
yield (False, "no %s%s%s" % (prefix, " ", ",".join(chunk)), None)

if added:
collapsed = collapse_vlandb(added, hw.Catalyst)
if explicit_changing and not old:
# by default all vlans are allowed
# switchport trunk allowed vlan none
yield (True, "%s none" % prefix, None)
for chunk in _chunked(collapsed, multi_chunk):
yield (True, "%s%s%s" % (prefix, " add " if explicit_changing else " ", ",".join(chunk)), None)
if explicit_changing:
yield (True, "%s%s%s" % (prefix, " add ", ",".join(chunk)), None)
else:
yield (True, "%s%s%s" % (prefix, " ", ",".join(chunk)), None)

if new_blocks:
for vlan_id, block in new_blocks.items():
yield (True, "%s %s" % (prefix, vlan_id), block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ patch: |
interface Ethernet1/2
no channel-group
switchport mode trunk
switchport trunk allowed vlan none
switchport trunk allowed vlan add 2
switchport
mtu 1500
Expand Down
200 changes: 200 additions & 0 deletions tests/annet/test_patch/cisco_switchport_trunk_allowed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
- vendor: cisco
diff: |
interface FastEthernet0/30
+ switchport access vlan 2612
+ switchport mode access

patch: |
conf t
interface FastEthernet0/30
switchport access vlan 2612
switchport mode access
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface FastEthernet0/30
- switchport access vlan 2612
- switchport mode access

patch: |
conf t
interface FastEthernet0/30
no switchport access vlan
no switchport mode
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface FastEthernet0/30
+ switchport trunk native vlan 2612
+ switchport trunk allowed vlan 2600-2602,2612,2670
+ switchport mode trunk

patch: |
conf t
interface FastEthernet0/30
switchport mode trunk
switchport trunk allowed vlan none
switchport trunk allowed vlan add 2600-2602,2612,2670
switchport trunk native vlan 2612
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface FastEthernet0/30
- switchport trunk native vlan 2612
- switchport trunk allowed vlan 2600-2602,2612,2670
- switchport mode trunk

patch: |
conf t
interface FastEthernet0/30
no switchport mode
no switchport trunk allowed vlan
no switchport trunk native vlan
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
- switchport access vlan 462
- switchport mode access
+ switchport trunk native vlan 410
+ switchport mode trunk
+ switchport trunk allowed vlan 410,2423,2433,2443

patch: |
conf t
interface GigabitEthernet1/0/38
no switchport access vlan
switchport mode trunk
switchport trunk allowed vlan none
switchport trunk allowed vlan add 410,2423,2433,2443
switchport trunk native vlan 410
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
- switchport trunk native vlan 410
- switchport trunk allowed vlan 410,2423,2433,2443
- switchport mode trunk
+ switchport access vlan 462
+ switchport mode access

patch: |
conf t
interface GigabitEthernet1/0/38
switchport access vlan 462
switchport mode access
no switchport trunk allowed vlan
no switchport trunk native vlan
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
- switchport trunk native vlan 410
- switchport trunk allowed vlan 410,2423,2433,2443
+ switchport trunk native vlan 400
+ switchport trunk allowed vlan 400,2423,2433,2443

patch: |
conf t
interface GigabitEthernet1/0/38
switchport trunk allowed vlan remove 410
switchport trunk allowed vlan add 400
switchport trunk native vlan 400
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
+ switchport mode trunk
+ switchport trunk allowed vlan 10,20,30,40,50,60,70,80,90,100,110,120,130,140
+ switchport trunk allowed vlan add 150,160,170

patch: |
conf t
interface GigabitEthernet1/0/38
switchport mode trunk
switchport trunk allowed vlan none
switchport trunk allowed vlan add 10,20,30,40,50
switchport trunk allowed vlan add 60,70,80,90,100
switchport trunk allowed vlan add 110,120,130,140,150
switchport trunk allowed vlan add 160,170
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
- switchport mode trunk
- switchport trunk allowed vlan 10,20,30,40,50,60,70,80,90,100,110,120,130,140
- switchport trunk allowed vlan add 150,160,170

patch: |
conf t
interface GigabitEthernet1/0/38
no switchport mode
no switchport trunk allowed vlan
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
switchport mode trunk
switchport trunk allowed vlan 10,20,30,40,50,60,70,80,90,100,110,120,130,140
- switchport trunk allowed vlan add 150,160,170

patch: |
conf t
interface GigabitEthernet1/0/38
switchport trunk allowed vlan remove 150,160,170
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
+ switchport trunk allowed vlan none

patch: |
conf t
interface GigabitEthernet1/0/38
switchport trunk allowed vlan none
exit
exit
copy running-config startup-config

- vendor: cisco
diff: |
interface GigabitEthernet1/0/38
- switchport trunk allowed vlan none

patch: |
conf t
interface GigabitEthernet1/0/38
no switchport trunk allowed vlan
exit
exit
copy running-config startup-config
Loading