Skip to content

Commit

Permalink
Revert "Removed 'show interfaces alias'. (sonic-net#412)" (sonic-net#603
Browse files Browse the repository at this point in the history
)

This partially reverts commit 3d03c13.
  • Loading branch information
lguohan authored Aug 12, 2019
1 parent 5208ec1 commit e40d02d
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,43 @@ def interfaces():
"""Show details of the network interfaces"""
pass

# 'alias' subcommand ("show interfaces alias")
@interfaces.command()
@click.argument('interfacename', required=False)
def alias(interfacename):
"""Show Interface Name/Alias Mapping"""

cmd = 'sonic-cfggen -d --var-json "PORT"'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

port_dict = json.loads(p.stdout.read())

header = ['Name', 'Alias']
body = []

if interfacename is not None:
if get_interface_mode() == "alias":
interfacename = iface_alias_converter.alias_to_name(interfacename)

# If we're given an interface name, output name and alias for that interface only
if interfacename in port_dict:
if 'alias' in port_dict[interfacename]:
body.append([interfacename, port_dict[interfacename]['alias']])
else:
body.append([interfacename, interfacename])
else:
click.echo("Invalid interface name, '{0}'".format(interfacename))
return
else:
# Output name and alias for all interfaces
for port_name in natsorted(port_dict.keys()):
if 'alias' in port_dict[port_name]:
body.append([port_name, port_dict[port_name]['alias']])
else:
body.append([port_name, port_name])

click.echo(tabulate(body, header))

#
# 'neighbor' group ###
#
Expand Down Expand Up @@ -487,7 +524,6 @@ def expected(interfacename):

click.echo(tabulate(body, header))


@interfaces.group(cls=AliasedGroup, default_if_no_args=False)
def transceiver():
"""Show SFP Transceiver information"""
Expand Down

0 comments on commit e40d02d

Please sign in to comment.