Skip to content

Commit

Permalink
sonic-utilities: Format show vlan config output (#210)
Browse files Browse the repository at this point in the history
* Format the output of show vlan config

Signed-off-by: chenhu <chenhu@didichuxing.com>
  • Loading branch information
richard28530 authored and lguohan committed Mar 2, 2018
1 parent 1009c99 commit 924dd38
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,20 +763,29 @@ def config(redis_unix_socket_path):
data = config_db.get_table('VLAN')
keys = data.keys()

def mode(key, data):
info = []
for m in data.get('members', []):
entry = config_db.get_entry('VLAN_MEMBER', (key, m))
mode = entry.get('tagging_mode')
if mode == None:
info.append('?')
else:
info.append(mode)
return '\n'.join(info)
def tablelize(keys, data):
table = []

header = ['Name', 'VID', 'Member', 'Mode']
click.echo(tabulate([ [k, data[k]['vlanid'], '\n'.join(data[k].get('members', [])), mode(k, data[k])] for k in keys ], header))
for k in keys:
for m in data[k].get('members', []):
r = []
r.append(k)
r.append(data[k]['vlanid'])
r.append(m)

entry = config_db.get_entry('VLAN_MEMBER', (k, m))
mode = entry.get('tagging_mode')
if mode == None:
r.append('?')
else:
r.append(mode)

table.append(r)

return table

header = ['Name', 'VID', 'Member', 'Mode']
click.echo(tabulate(tablelize(keys, data), header))

@cli.command('services')
def services():
Expand Down

0 comments on commit 924dd38

Please sign in to comment.