Skip to content

New parser for 'show vlan brief' on Cisco IOSXE #658

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--------------------------------------------------------------------------------
New
--------------------------------------------------------------------------------
* <IOSXE>
* Added ShowVlanBrief:
* for 'show vlan brief'
98 changes: 98 additions & 0 deletions src/genie/libs/parser/iosxe/show_vlan_brief.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have show_vlan for iosxe please add the parser to that file instead of creating a new one

IOSXE C9300 parsers for the following show commands:
* show vlan brief
"""
# Python
import re
import logging

# Metaparser
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Schema, Any, Or, Optional


# ============================
# Schema for 'show vlan brief'
# ============================
class ShowVlanBriefSchema(MetaParser):

""" Schema for:
* show vlan brief
"""
schema = {

Any():{
'vlan_id': int,
'name': str,
'status': str,
Optional('ports'): str,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Optional('ports'): str,
Optional('ports'): list,

I think this would work better as a list instead of one long string.
If there are no ports, just don't assign anything to the per_vlan_dict['ports'] key, and since it's optional it won't cause an issue.

}

}



# ============================
# Parser for 'show vlan brief'
# ============================
class ShowVlanBrief(ShowVlanBriefSchema):
"""
Parser for :
* show vlan brief
"""

cli_command = 'show vlan brief'

def cli(self, output=None):
if output is None:
out = self.device.execute(self.cli_command)
else:
out = output

parsed_dict = {}

# --------------------------------------------------------------
# Regex patterns
# --------------------------------------------------------------
# 1 default active Gi1/0/2, Gi1/0/3, Gi1/0/4, Gi1/0/5, Gi1/0/6, Gi1/0/7, Gi1/0/8, Gi1/0/9, Gi1/0/10, Gi1/0/11, Gi1/0/12, Gi1/0/13, Gi1/0/14, Gi1/0/15, Gi1/0/17, Gi1/0/21, Gi1/0/22, Gi1/0/23, Gi1/0/24, Gi1/0/25, Gi1/0/26, Gi1/0/27, Gi1/0/28, Gi1/0/29, Gi1/0/30, Gi1/0/38, Gi1/0/39, Gi1/0/40, Gi1/0/47, Te1/1/3, Te1/1/4, Te1/1/5, Te1/1/6, Te1/1/7, Te1/1/8, Ap1/0/1
p1 = re.compile(r'(?P<vlan_id>\d+)\s+(?P<name>\S+)\s+(?P<status>\S+)\s+(?P<ports>(?:\S+\s)+\d?)')

# 2 VLAN0002 active
p2 = re.compile(r'(?P<vlan_id>\d+)\s+(?P<name>\S+)\s+(?P<status>\S+)')

# --------------------------------------------------------------
# Build the parsed output
# --------------------------------------------------------------
for line in out.splitlines():
per_vlan_dict = {}
line = line.strip()

m = p1.match(line)
if m:
group = m.groupdict()

per_vlan_dict = parsed_dict.setdefault(group['vlan_id'],{})

per_vlan_dict['vlan_id'] = int(group['vlan_id'])
per_vlan_dict['name'] = group['name']
per_vlan_dict['status'] = group['status']
per_vlan_dict['ports'] = group['ports']

continue

m = p2.match(line)
if m:
group = m.groupdict()

per_vlan_dict = parsed_dict.setdefault(group['vlan_id'],{})

per_vlan_dict['vlan_id'] = int(group['vlan_id'])
per_vlan_dict['name'] = group['name']
per_vlan_dict['status'] = group['status']
per_vlan_dict['ports'] = ""

continue

return parsed_dict


Loading