Skip to content

Commit

Permalink
Vnet alias mapping (sonic-net#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
prsunny authored May 28, 2020
1 parent d03d151 commit b37135c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2989,6 +2989,38 @@ def tablelize(vnet_keys, vnet_data):

click.echo(tabulate(tablelize(vnet_keys, vnet_data), header))

@vnet.command()
@click.argument('vnet_alias', required=False)
def alias(vnet_alias):
"""Show vnet alias to name information"""
config_db = ConfigDBConnector()
config_db.connect()
header = ['Alias', 'Name']

# Fetching data from config_db for VNET
vnet_data = config_db.get_table('VNET')
vnet_keys = natsorted(vnet_data.keys())

def tablelize(vnet_keys, vnet_data, vnet_alias):
table = []
for k in vnet_keys:
r = []
if vnet_alias is not None:
if vnet_data[k].get('guid') == vnet_alias:
r.append(vnet_data[k].get('guid'))
r.append(k)
table.append(r)
return table
else:
continue

r.append(vnet_data[k].get('guid'))
r.append(k)
table.append(r)
return table

click.echo(tabulate(tablelize(vnet_keys, vnet_data, vnet_alias), header))

@vnet.command()
def interfaces():
"""Show vnet interfaces information"""
Expand Down

0 comments on commit b37135c

Please sign in to comment.