04-07-2020 12:54 PM
In Exos, you can issue a “show port xx vlan” to get a short, simple list of vlan’s on a port. Is there a similar way to get a brief list of ports within a vlan (as opposed to “show vlan xx”, where it’s a small block of info at the bottom? I want to see all ports in V90 for example, nothing else. Would be cool with something like “show vlan xx members”.
Thanks!
Solved! Go to Solution.
04-15-2020 01:35 PM
I did a thing
#!/usr/bin/env python
'''
Shows ports in a vlan
Tested on EXOS 22.6.1.4
Execute with:
- run script vlanports.py
or
- Make an alias: alias vlanport "run script vlanports.py"
'''
import re
import sys
exsh.clicmd('disable clipaging', False)
# Input the tag or complete name of the vlan.
if len(sys.argv) < 2:
input_tag = raw_input("Vlan: ")
else:
input_tag = sys.argv[1]
# Get vlan name
vlan_name = exsh.clicmd('show vlan {} | inc name'.format(input_tag), True)
if not vlan_name:
print 'Error: No <vlan_list> found with ID {}'.format(input_tag)
exit()
vlan_name = vlan_name.split()[4]
# Extract vlan secction of the configuration
config_lines = exsh.clicmd('show configuration vlan', True).splitlines()
# Find the first line that matches "configure vlan <vlan_name> add ports"
regex = re.compile('configure vlan {} add ports'.format(vlan_name), re.IGNORECASE)
for i, line in enumerate(config_lines):
if regex.match(line):
line_field = line.split()
print 'Ports {tag}: {ports}'.format(tag = line_field[-1], ports = line_field[5])
# If there are tagged and untagged ports configured in the vlan, the next line in the configuration has them
if regex.match(config_lines[i+1]):
line_field = config_lines[i+1].split()
print 'Ports {tag}: {ports}'.format(tag = line_field[-1], ports = line_field[5])
exit()
print 'No ports in this vlan'
04-07-2020 06:39 PM
Perhaps a product enhancement suggestion? “show vlan vxxx members” with a tagged or untagged flag option to further narrow down the list?
04-07-2020 01:29 PM
Its an ugly solution, but what about “show config vlan | i “ <vlan name> add ports” ?
# show config vlan | i " Default add ports"
configure vlan Default add ports 1:1-7,1:9-15 untagged
04-07-2020 01:16 PM
Eric,
Not as far as I can tell. The only thing I could suggest is “sh vlan FOO | begin Ports:”, but that still gives you the entire “Flags” legend at the bottom
“grep” probably won’t do what you need - there can be line-breaks in the port list, grep-ing for parentheses would still include the “Flags”, and you can’t double-pipe.
I would guess someone could come up with a python script, but if there’s a better way, I’d be interested as well.