Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOS][get_vlans()] Parse VLAN IDs when private VLANs are implemented #1994

Draft
wants to merge 47 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a395045
Parse Private VLANs
vvas1lev Aug 24, 2023
8525937
add tests
vvas1lev Aug 24, 2023
590e3ce
Update mock data
vvas1lev Aug 24, 2023
bff8d13
run black
vvas1lev Aug 24, 2023
35817fe
fix typo
vvas1lev Aug 24, 2023
c747d1c
fix more typos
vvas1lev Aug 24, 2023
90a7b96
s/name/'name'/
vvas1lev Aug 24, 2023
d51968c
fix json encoding
vvas1lev Aug 24, 2023
6e54189
refactor VLAN match logic
vvas1lev Aug 25, 2023
9980dc6
fix tests
vvas1lev Aug 25, 2023
399670f
fixing a typo
vvas1lev Aug 25, 2023
0ee9432
Preserve private VLAN names
vvas1lev Aug 28, 2023
a0f8f56
fix a typo
vvas1lev Aug 28, 2023
42454d2
fix ident
vvas1lev Aug 28, 2023
7094e96
fix typo
vvas1lev Aug 28, 2023
ae45820
Merge branch 'develop' into develop
vvas1lev Sep 4, 2023
a8f97f1
Merge branch 'develop' into develop
vvas1lev Sep 11, 2023
9a30c62
Merge branch 'develop' into develop
vvas1lev Mar 23, 2024
808eca9
black
vvas1lev Mar 23, 2024
ca3acb0
rebase
vvas1lev Mar 23, 2024
f1054af
empty commit / re-run tests
vvas1lev Mar 23, 2024
07c6ae4
black 24.3.0
vvas1lev Mar 23, 2024
d41df1d
Merge branch 'develop' into develop
mirceaulinic May 21, 2024
09d96ab
Merge branch 'develop' into develop
vvas1lev Aug 10, 2024
4e373e9
remove ws
vvas1lev Aug 10, 2024
2a42429
refactor _get_vlan_all_ports()
vvas1lev Aug 10, 2024
f33e1cf
fix typo
vvas1lev Aug 10, 2024
870434d
update unittest
vvas1lev Aug 10, 2024
3df3890
remove wrongly entered PVLANs in mocked data
vvas1lev Aug 10, 2024
cf4c517
update mocked data
vvas1lev Aug 10, 2024
1fa6d76
update mocked data
vvas1lev Aug 10, 2024
f45c248
update tests
vvas1lev Aug 10, 2024
c3597ca
update tests
vvas1lev Aug 10, 2024
d1f7e1e
update tests
vvas1lev Aug 10, 2024
5053858
add new mock data
vvas1lev Aug 12, 2024
e1598b4
rename mock file
vvas1lev Aug 12, 2024
25dad20
fix logic
vvas1lev Aug 12, 2024
20e94b1
fixes
vvas1lev Aug 12, 2024
cb52b09
fixes
vvas1lev Aug 12, 2024
923035d
black
vvas1lev Aug 12, 2024
9b4023d
fixes
vvas1lev Aug 12, 2024
3740b64
add mock data
vvas1lev Aug 12, 2024
f546560
fixes
vvas1lev Aug 12, 2024
423e623
fixes
vvas1lev Aug 12, 2024
34e90aa
black
vvas1lev Aug 12, 2024
a850cd5
fixes
vvas1lev Aug 12, 2024
7680d42
fixes
vvas1lev Aug 12, 2024
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
27 changes: 22 additions & 5 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -3741,15 +3741,18 @@ def get_vlans(self):
if output.find("Invalid input detected") >= 0:
return self._get_vlan_from_id()
else:
return self._get_vlan_all_ports(output)
return self._get_vlan_all_ports(output, _vlan_id=None, _vlan_name=None)

def _get_vlan_all_ports(self, output):
def _get_vlan_all_ports(self, output, _vlan_id, _vlan_name):
find_regexp = re.compile(
r"^(\d+)\s+" # vlan id
r"(.*?(?=active|act\/[isl]{1}shut|act\/unsup))" # vlan name
r"\w+(?:\/\w+)?\S+(\s+[A-Z][a-z].*)?$" # ports
)
continuation_regexp = re.compile(r"^\s+([A-Z][a-z].*)$")
match_pvlan_regexp = re.compile(
r"^(\d+)\s+(\S+)\s+(community|isolated)?\s+(\s+[A-Z][a-z].*)?$"
)
output = output.splitlines()
vlans = {}

Expand All @@ -3759,20 +3762,31 @@ def _get_vlan_all_ports(self, output):
interfaces = ""
for line in output:
vlan_m = find_regexp.match(line)
p_vlan_m = match_pvlan_regexp.match(line)
if vlan_m:
was_vlan_or_cont = True
vlan_id = vlan_m.group(1)
vlan_name = vlan_m.group(2).strip()
interfaces = vlan_m.group(3) or ""
vlans[vlan_id] = {"name": vlan_name, "interfaces": []}
if p_vlan_m:
was_vlan_or_cont = True
p_vlan_id = p_vlan_m.group(2)
vlan_name = (
vlans.get(vlan_id)["name"]
if vlans.get(vlan_id)
else p_vlan_m.group(2)
)
interfaces = p_vlan_m.group(4) or ""
vlans[p_vlan_id] = {"name": vlan_name, "interfaces": []}

cont_m = None
if was_vlan_or_cont:
cont_m = continuation_regexp.match(line)
if cont_m:
interfaces = cont_m.group(1)

if not cont_m and not vlan_m:
if not cont_m and not (vlan_m or p_vlan_m):
was_vlan_or_cont = False
continue

Expand All @@ -3784,17 +3798,20 @@ def _get_vlan_all_ports(self, output):
]
)

if vlans and len(vlans) > 1:
del vlans[vlan_id]

return vlans

def _get_vlan_from_id(self):
command = "show vlan brief"
command = "show vlan"
output = self._send_command(command)
vlan_regexp = r"^(\d+)\W+(.*?(?=active|act\/[isl]{1}shut|act\/unsup))"
find_vlan = re.findall(vlan_regexp, output, re.MULTILINE)
vlans = {}
for vlan_id, vlan_name in find_vlan:
output = self._send_command("show vlan id {}".format(vlan_id))
_vlans = self._get_vlan_all_ports(output)
_vlans = self._get_vlan_all_ports(output, vlan_id, vlan_name)
if len(_vlans) == 0:
vlans[vlan_id] = {"name": vlan_name.strip(), "interfaces": []}
elif len(_vlans) == 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@
"GigabitEthernet0/20"
]
},
"500": {
"name": "VLAN500",
"interfaces": [
"GigabitEthernet1/1",
"GigabitEthernet1/2",
"GigabitEthernet1/3"
]
},
"501": {
"name": "Vlan501",
"interfaces": [
"GigabitEthernet1/1",
"GigabitEthernet1/2"
]
},
"502": {
"name": "VLAN502",
"interfaces": [
"GigabitEthernet1/1",
"GigabitEthernet1/3"
]
},
"710": {
"name": "Vlan710",
"interfaces": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Gi0/17, Gi0/18, Gi0/19, Gi0/20
500 VLAN500 active
501 Vlan501 active
502 VLAN502 active
710 Vlan710 active
736 Vlan736 active
748 Vlan748 active
Expand All @@ -11,4 +14,6 @@ VLAN Name Status Ports
1002 Vlan1002 act/unsup
1003 Vlan1003 act/unsup
1004 Vlan1004 act/unsup
1005 Vlan1005 act/unsup
1005 Vlan1005 act/unsup
500 501 community Gi1/1, Gi1/2
500 502 isolated Gi1/1, Gi1/3
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
500 VLAN0500 active

VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
500 enet 100500 1500 - - - - - 0 0

Remote SPAN VLAN
----------------
Disabled

Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
500 501 community Gi1/1, Gi1/2
500 502 isolated Gi1/1, Gi1/3
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
501 VLAN0501 active

VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
501 enet 100501 1500 - - - - - 0 0

Remote SPAN VLAN
----------------
Disabled

Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
500 501 community Gi1/1, Gi1/2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
502 VLAN0502 active

VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
502 enet 100502 1500 - - - - - 0 0

Remote SPAN VLAN
----------------
Disabled

Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
500 502 isolated Gi1/1, Gi1/3
Loading