diff --git a/napalm/ios/ios.py b/napalm/ios/ios.py index 322962c70..2934b6a55 100644 --- a/napalm/ios/ios.py +++ b/napalm/ios/ios.py @@ -3722,7 +3722,11 @@ def get_vlans(self): return self._get_vlan_all_ports(output) def _get_vlan_all_ports(self, output): - find_regexp = re.compile(r"^(\d+)\s+(\S+)\s+\S+(\s+[A-Z][a-z].*)?$") + 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].*)$") output = output.splitlines() vlans = {} @@ -3736,7 +3740,7 @@ def _get_vlan_all_ports(self, output): if vlan_m: was_vlan_or_cont = True vlan_id = vlan_m.group(1) - vlan_name = vlan_m.group(2) + vlan_name = vlan_m.group(2).strip() interfaces = vlan_m.group(3) or "" vlans[vlan_id] = {"name": vlan_name, "interfaces": []} @@ -3763,7 +3767,7 @@ def _get_vlan_all_ports(self, output): def _get_vlan_from_id(self): command = "show vlan brief" output = self._send_command(command) - vlan_regexp = r"^(\d+)\s+(\S+)\s+\S+.*$" + 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: diff --git a/test/ios/mocked_data/test_get_vlans/normal/expected_result.json b/test/ios/mocked_data/test_get_vlans/normal/expected_result.json index 9724b801b..96c41b948 100644 --- a/test/ios/mocked_data/test_get_vlans/normal/expected_result.json +++ b/test/ios/mocked_data/test_get_vlans/normal/expected_result.json @@ -1112,7 +1112,7 @@ ] }, "795": { - "name": "Vlan795", + "name": "Vlan 795", "interfaces": [ "Port-channel1", "Port-channel5", @@ -1194,5 +1194,10 @@ "1275": { "name": "Vlan1275", "interfaces": [] + }, + "1276": { + "name": "A1 - VIDEO", + "interfaces": ["Port-channel1"] } + } diff --git a/test/ios/mocked_data/test_get_vlans/normal/show_vlan_all_ports.txt b/test/ios/mocked_data/test_get_vlans/normal/show_vlan_all_ports.txt index 5f9850dd7..dd44f4549 100644 --- a/test/ios/mocked_data/test_get_vlans/normal/show_vlan_all_ports.txt +++ b/test/ios/mocked_data/test_get_vlans/normal/show_vlan_all_ports.txt @@ -64,12 +64,13 @@ VLAN Name Status Ports 790 Vlan790 active Po1, Po5, Po6, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 792 Vlan792 active Po1, Po2, Po5, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 794 Vlan794 active Po1, Po5, Po6, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 -795 Vlan795 active Po1, Po5, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 +795 Vlan 795 active Po1, Po5, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 1002 Vlan1002 act/unsup Po1, Po5, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 1003 Vlan1003 act/unsup Po1, Po5, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 1004 Vlan1004 act/unsup Po1, Po5, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 1005 Vlan1005 act/unsup Po1, Po5, Po21, Po22, Po23, Po24, Po25, Po26, Po27, Po28, Po30 1275 Vlan1275 active +1276 A1 - VIDEO active Po1 VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ @@ -141,6 +142,7 @@ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 1004 fdnet 101004 1500 - - - ieee - 0 0 1005 trnet 101005 1500 - - - ibm - 0 0 1275 enet 101275 1500 - - - - - 0 0 +1276 enet 101275 1500 - - - - - 0 0 Primary Secondary Type Ports ------- --------- ----------------- ------------------------------------------