-
Notifications
You must be signed in to change notification settings - Fork 398
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
barfa1
wants to merge
2
commits into
CiscoTestAutomation:main
Choose a base branch
from
barfa1:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
changelog/undistributed/changelog_show_vlan_brief_iosxe_20220510143308.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-------------------------------------------------------------------------------- | ||
New | ||
-------------------------------------------------------------------------------- | ||
* <IOSXE> | ||
* Added ShowVlanBrief: | ||
* for 'show vlan brief' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,98 @@ | ||||||
""" | ||||||
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, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this would work better as a list instead of one long string. |
||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
|
||||||
|
||||||
# ============================ | ||||||
# 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 | ||||||
|
||||||
|
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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