Skip to content

Commit

Permalink
Gives cisco-8000 more flexibility to easily add subcommnads under sho…
Browse files Browse the repository at this point in the history
…w platform (#2213)

What I did
Gave cisco-8000 the ability to add sub-commands under show platform <> in our downstream repo. Currently every time we want to add/remove/update a cli, we must raise a PR upstream.

How I did it
I have the cisco-8000.py module import a list of click commands that are written in a module that is located in our platform code.

How to verify it
Run show platform -h to see all commands. We will be able to see show platform inventory. This is only available on cisco devices.
  • Loading branch information
nathcohe authored Jun 20, 2022
1 parent 9f2607d commit 248ddd5
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions show/plugins/cisco-8000.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
#!/usr/bin/env python
#########################################################
# Copyright 2021 Cisco Systems, Inc.
# Copyright 2021-2022 Cisco Systems, Inc.
# All rights reserved.
#
# CLI Extensions for show command
#########################################################

try:
import click
import yaml
from show import platform
from sonic_py_common import device_info
import utilities_common.cli as clicommon
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
raise ImportError("%s - required module not found".format(str(e)))

PLATFORM_PY = '/opt/cisco/bin/platform.py'

@click.command()
def inventory():
"""Show Platform Inventory"""
args = [ PLATFORM_PY, 'inventoryshow' ]
clicommon.run_command(args)
try:
from sonic_platform.cli import PLATFORM_CLIS
except ImportError:
PLATFORM_CLIS = []

@click.command()
def idprom():
"""Show Platform Idprom Inventory"""
args = [ PLATFORM_PY, 'idprom' ]
clicommon.run_command(args)

def register(cli):
version_info = device_info.get_sonic_version_info()
if (version_info and version_info.get('asic_type') == 'cisco-8000'):
cli.commands['platform'].add_command(inventory)
cli.commands['platform'].add_command(idprom)
version_info = device_info.get_sonic_version_info()
if version_info and version_info.get("asic_type") == "cisco-8000":
for c in PLATFORM_CLIS:
cli.commands["platform"].add_command(c)

0 comments on commit 248ddd5

Please sign in to comment.