From b37135c85aedcc9a4aa1bceb354491bad96544ba Mon Sep 17 00:00:00 2001 From: Prince Sunny Date: Thu, 28 May 2020 11:07:30 -0700 Subject: [PATCH] Vnet alias mapping (#924) --- show/main.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/show/main.py b/show/main.py index 45a1e1c185b4..1a6fd8028422 100755 --- a/show/main.py +++ b/show/main.py @@ -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"""