From 739867067f3507e2de7cf2bca502d74feaaeb6bc Mon Sep 17 00:00:00 2001 From: samaity Date: Fri, 29 Sep 2017 11:26:55 -0700 Subject: [PATCH 1/3] Enhancement of 'show' commands and addition of 'debug', and 'undebug' hierarchy in CLI utilities > added script to get interface status. > added few subcommands under "show interfaces" command. > enhanced "show process" to get all processes sorted by CPU & memory. > added "show services" command to get all the running process from all the dockers. > added "show vlan" command. > enhanced multiple subcommands under > added debug', and 'undebug' CLI utilities. --- data/etc/bash_completion.d/debug | 8 ++ data/etc/bash_completion.d/undebug | 8 ++ debug/__init__.py | 0 debug/aliases.ini | 5 ++ debug/main.py | 139 +++++++++++++++++++++++++++++ scripts/interface_stat | 55 ++++++++++++ show/main.py | 138 +++++++++++++++++++++++++--- undebug/__init__.py | 0 undebug/aliases.ini | 5 ++ undebug/main.py | 137 ++++++++++++++++++++++++++++ 10 files changed, 481 insertions(+), 14 deletions(-) create mode 100644 data/etc/bash_completion.d/debug create mode 100644 data/etc/bash_completion.d/undebug create mode 100644 debug/__init__.py create mode 100644 debug/aliases.ini create mode 100644 debug/main.py create mode 100644 scripts/interface_stat mode change 100644 => 100755 show/main.py create mode 100644 undebug/__init__.py create mode 100644 undebug/aliases.ini create mode 100644 undebug/main.py diff --git a/data/etc/bash_completion.d/debug b/data/etc/bash_completion.d/debug new file mode 100644 index 0000000000..b6b4989767 --- /dev/null +++ b/data/etc/bash_completion.d/debug @@ -0,0 +1,8 @@ +_debug_completion() { + COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ + COMP_CWORD=$COMP_CWORD \ + _DEBUG_COMPLETE=complete $1 ) ) + return 0 +} + +complete -F _debug_completion -o default debug; diff --git a/data/etc/bash_completion.d/undebug b/data/etc/bash_completion.d/undebug new file mode 100644 index 0000000000..dccc68498d --- /dev/null +++ b/data/etc/bash_completion.d/undebug @@ -0,0 +1,8 @@ +_undebug_completion() { + COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ + COMP_CWORD=$COMP_CWORD \ + _UNDEBUG_COMPLETE=complete $1 ) ) + return 0 +} + +complete -F _undebug_completion -o default undebug; diff --git a/debug/__init__.py b/debug/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/debug/aliases.ini b/debug/aliases.ini new file mode 100644 index 0000000000..409231559c --- /dev/null +++ b/debug/aliases.ini @@ -0,0 +1,5 @@ +[aliases] +running-configuration=runningconfiguration +running-config=runningconfiguration +startup-configuration=startupconfiguration +startup-config=startupconfiguration diff --git a/debug/main.py b/debug/main.py new file mode 100644 index 0000000000..a8b7460854 --- /dev/null +++ b/debug/main.py @@ -0,0 +1,139 @@ +#! /usr/bin/python -u +# date: 07/12/17 + +import click +import os +import subprocess +from click_default_group import DefaultGroup + +try: + import ConfigParser as configparser +except ImportError: + import configparser + + +# This is from the aliases example: +# https://github.com/pallets/click/blob/57c6f09611fc47ca80db0bd010f05998b3c0aa95/examples/aliases/aliases.py +class Config(object): + """Object to hold CLI config""" + + def __init__(self): + self.path = os.getcwd() + self.aliases = {} + + def read_config(self, filename): + parser = configparser.RawConfigParser() + parser.read([filename]) + try: + self.aliases.update(parser.items('aliases')) + except configparser.NoSectionError: + pass + + +# Global Config object +_config = None + + +# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group. +# DefaultFroup is a superclass of click.Group which calls a default subcommand instead of showing +# a help message if no subcommand is passed +class AliasedGroup(DefaultGroup): + """This subclass of a DefaultGroup supports looking up aliases in a config + file and with a bit of magic. + """ + + def get_command(self, ctx, cmd_name): + global _config + + # If we haven't instantiated our global config, do it now and load current config + if _config is None: + _config = Config() + + # Load our config file + cfg_file = os.path.join(os.path.dirname(__file__), 'aliases.ini') + _config.read_config(cfg_file) + + # Try to get builtin commands as normal + rv = click.Group.get_command(self, ctx, cmd_name) + if rv is not None: + return rv + + # No builtin found. Look up an explicit command alias in the config + if cmd_name in _config.aliases: + actual_cmd = _config.aliases[cmd_name] + return click.Group.get_command(self, ctx, actual_cmd) + + # Alternative option: if we did not find an explicit alias we + # allow automatic abbreviation of the command. "status" for + # instance will match "st". We only allow that however if + # there is only one command. + matches = [x for x in self.list_commands(ctx) + if x.lower().startswith(cmd_name.lower())] + if not matches: + # No command name matched. Issue Default command. + ctx.arg0 = cmd_name + cmd_name = self.default_cmd_name + return DefaultGroup.get_command(self, ctx, cmd_name) + elif len(matches) == 1: + return DefaultGroup.get_command(self, ctx, matches[0]) + ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) + + +def run_command(command, pager=False): + if pager is True: + click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) + p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + click.echo_via_pager(p.stdout.read()) + else: + click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) + p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + click.echo(p.stdout.read()) + + +CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?']) + + +# +# 'cli' group (root group) ### +# + +@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS) +def cli(): + """SONiC command line - 'debug' command""" + pass + + +# +# 'bgp' group ### +# + +@cli.group(cls=AliasedGroup, default_if_no_args=True) +def bgp(): + """debug bgp on """ + pass + +@bgp.command(default=True) +def default(): + command = 'sudo vtysh -c "debug bgp"' + run_command(command) + + + +# Add 'bgp' group to both the root 'cli' group and the 'ip' subgroup +cli.add_command(bgp) + + +@bgp.command() +def events(): + """debug bgp events on """ + command = 'sudo vtysh -c "debug bgp events"' + run_command(command) + +@bgp.command() +def updates(): + """debug bgp events on """ + command = 'sudo vtysh -c "debug bgp updates"' + run_command(command) + +if __name__ == '__main__': + cli() diff --git a/scripts/interface_stat b/scripts/interface_stat new file mode 100644 index 0000000000..81095596ad --- /dev/null +++ b/scripts/interface_stat @@ -0,0 +1,55 @@ +#!/usr/bin/env python +import swsssdk +import sys +import re +from tabulate import tabulate +header = ['Iface', 'LANES', 'ALIAS', 'OPER', 'ADMIN', 'MTU'] + + +PORT_STATUS_TABLE_PREFIX = "PORT_TABLE:" +PORT_LANES_STATUS_FIELD = "lanes" +PORT_ALIAS_STATUS_FIELD = "alias" +PORT_OPER_STATUS_FIELD = "oper_status" +PORT_ADMIN_STATUS_FIELD = "admin_status" +PORT_MTU_STATUS_FIELD = "mtu" + +class Intstat(object): + table = [] + + def get_port_status(self, port_name, status_type): + """ + Get the port status + """ + full_table_id = PORT_STATUS_TABLE_PREFIX + port_name + status = self.db.get(self.db.APPL_DB, full_table_id, status_type) + if status is None: + return "N/A" + else: + return status + + def __init__(self): + self.db = swsssdk.SonicV2Connector(host='127.0.0.1') + self.db.connect(self.db.APPL_DB) + a = self.db.keys(self.db.APPL_DB) + #print(a) + tables = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*") + i={} + table = [] + key = [] + #print tabulate(header, tablefmt='simple', stralign='right') + for i in tables: + key = re.split(':', i, maxsplit=1)[-1].strip() + if key : + table.append((key, self.get_port_status(key, PORT_LANES_STATUS_FIELD), self.get_port_status(key, PORT_ALIAS_STATUS_FIELD), self.get_port_status(key, PORT_OPER_STATUS_FIELD), self.get_port_status(key, PORT_ADMIN_STATUS_FIELD), self.get_port_status(key, PORT_MTU_STATUS_FIELD))) + print tabulate(table, header, tablefmt="simple", stralign='right') + + + +def main(): + interface_stat = Intstat() + + # Now decide what information to display + sys.exit(0) + +if __name__ == "__main__": + main() diff --git a/show/main.py b/show/main.py old mode 100644 new mode 100755 index a0b2ff5771..12bed445b5 --- a/show/main.py +++ b/show/main.py @@ -107,8 +107,7 @@ def run_command(command): if proc.returncode != 0: sys.exit(proc.returncode) -CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '?']) - +CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?']) # # 'cli' group (root group) @@ -172,8 +171,8 @@ def alias(interfacename): click.echo(tabulate(body, header)) -# 'summary' subcommand ("show interfaces summary") -@interfaces.command() +# 'summary' subcommand ("show interfaces summary") -- called if no subcommands are passed +@interfaces.command(default=True) @click.argument('interfacename', required=False) def summary(interfacename): """Show interface status and information""" @@ -187,6 +186,38 @@ def summary(interfacename): command = cmd_ifconfig run_command(command) + +@interfaces.group(cls=AliasedGroup, default_if_no_args=True) +def transceiver(): + pass + +interfaces.add_command(transceiver) + +@transceiver.command(default=True) +@click.argument('interfacename', required=False) +def default(interfacename): + if interfacename is not None: + command = "sudo sfputil -p {}".format(interfacename) + else: + command = "sudo sfputil" + run_command(command) + +@transceiver.command() +@click.argument('interfacename', required=True) +def details(interfacename): + command="sudo sfputil --port {} --dom".format(interfacename) + run_command(command) + +@interfaces.command() +@click.argument('interfacename', required=False) +def description(interfacename): + if interfacename is not None: + command = "sudo vtysh -c 'show interface {}'".format(interfacename) + else: + command = "sudo vtysh -c 'show interface description'" + run_command(command) + + # 'counters' subcommand ("show interfaces counters") @interfaces.command() @click.option('-p', '--period') @@ -226,6 +257,11 @@ def sfp(interfacename): run_command(cmd) +@interfaces.command() +def status(): + """Show Interface status information""" + run_command("interface_stat") + # # 'mac' command ("show mac ...") # @@ -403,6 +439,7 @@ def summary(): # Clean up os.remove(PLATFORM_TEMPLATE_FILE) + # 'syseeprom' subcommand ("show platform syseeprom") @platform.command() def syseeprom(): @@ -482,18 +519,31 @@ def environment(): # 'processes' group ("show processes ...") # -@cli.group() +@cli.group(cls=AliasedGroup, default_if_no_args=True) def processes(): """Display process information""" pass +@processes.command(default=True) +def default(): + """Show processes info""" + # Run top batch mode to prevent unexpected newline after each newline + run_command('ps -eo pid,ppid,cmd,%mem,%cpu ') + + # 'cpu' subcommand ("show processes cpu") @processes.command() def cpu(): """Show processes CPU info""" # Run top in batch mode to prevent unexpected newline after each newline - run_command('top -bn 1') - + run_command('top -bn 1 -o %CPU') + +# 'memory' subcommand +@processes.command() +def memory(): + """Show processes memory info""" + # Run top batch mode to prevent unexpected newline after each newline + run_command('top -bn 1 -o %MEM') # # 'users' command ("show users") @@ -546,11 +596,15 @@ def interfaces(interfacename): # 'snmp' subcommand ("show runningconfiguration snmp") @runningconfiguration.command() -def snmp(): - """Show SNMP running configuration""" - command = 'sudo docker exec -it snmp cat /etc/snmp/snmpd.conf' - run_command(command) - +@click.argument('server', required=False) +def snmp(server): + """Show SNMP information""" + if server is not None: + command = 'sudo docker exec -it snmp cat /etc/snmp/snmpd.conf | grep -i agentAddress' + run_command(command) + else: + command = 'sudo docker exec -it snmp cat /etc/snmp/snmpd.conf' + run_command(command) # 'ntp' subcommand ("show runningconfiguration ntp") @runningconfiguration.command() @@ -573,8 +627,18 @@ def startupconfiguration(): @startupconfiguration.command() def bgp(): """Show BGP startup configuration""" - run_command('sudo docker exec -it bgp cat /etc/quagga/bgpd.conf') - + command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1" + proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) + result = proc.stdout.read().rstrip() + click.echo("Routing-Stack is: {}".format(result)) + if result == "quagga": + run_command('sudo docker exec -it bgp cat /etc/quagga/bgpd.conf') + elif result == "frr": + run_command('sudo docker exec -it bgp cat /etc/frr/bgpd.conf') + elif result == "gobgp": + run_command('sudo docker exec -it bgp cat /etc/gpbgp/bgpd.conf') + else: + click.echo("unidentified routing-stack") # # 'ntp' command ("show ntp") @@ -595,6 +659,52 @@ def uptime(): """Show system uptime""" run_command('uptime -p') +@cli.command() +def clock(): + """Show date and time""" + run_command('date') + +@cli.command('system-memory') +def system_memory(): + """Show memory information""" + command="free -m" + run_command(command) + +@click.group(cls=AliasedGroup, default_if_no_args=False) +def vlan(): + """Show VLAN information""" + pass + +cli.add_command(vlan) + +@vlan.command() +def brief(): + """Show all bridge information""" + command="sudo brctl show" + run_command(command) + +@vlan.command() +@click.argument('bridge_name', required=True) +def id(bridge_name): + """Show list of learned MAC addresses for particular bridge""" + command="sudo brctl showmacs {}".format(bridge_name) + run_command(command) + +@cli.command('services') +def services(): + """Show all daemon services""" + command = "sudo docker ps --format '{{.Names}}'" + proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) + while True: + line = proc.stdout.readline() + if line != '': + print(line.rstrip()+'\t'+"docker") + print("---------------------------") + command = "sudo docker exec -it {} ps -ef | sed '$d'".format(line.rstrip()) + proc1 = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) + print proc1.stdout.read() + else: + break if __name__ == '__main__': cli() diff --git a/undebug/__init__.py b/undebug/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/undebug/aliases.ini b/undebug/aliases.ini new file mode 100644 index 0000000000..409231559c --- /dev/null +++ b/undebug/aliases.ini @@ -0,0 +1,5 @@ +[aliases] +running-configuration=runningconfiguration +running-config=runningconfiguration +startup-configuration=startupconfiguration +startup-config=startupconfiguration diff --git a/undebug/main.py b/undebug/main.py new file mode 100644 index 0000000000..d78633662c --- /dev/null +++ b/undebug/main.py @@ -0,0 +1,137 @@ +import click +import os +import subprocess +from click_default_group import DefaultGroup + +try: + import ConfigParser as configparser +except ImportError: + import configparser + + +# This is from the aliases example: +# https://github.com/pallets/click/blob/57c6f09611fc47ca80db0bd010f05998b3c0aa95/examples/aliases/aliases.py +class Config(object): + """Object to hold CLI config""" + + def __init__(self): + self.path = os.getcwd() + self.aliases = {} + + def read_config(self, filename): + parser = configparser.RawConfigParser() + parser.read([filename]) + try: + self.aliases.update(parser.items('aliases')) + except configparser.NoSectionError: + pass + + +# Global Config object +_config = None + + +# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group. +# DefaultFroup is a superclass of click.Group which calls a default subcommand instead of showing +# a help message if no subcommand is passed +class AliasedGroup(DefaultGroup): + """This subclass of a DefaultGroup supports looking up aliases in a config + file and with a bit of magic. + """ + + def get_command(self, ctx, cmd_name): + global _config + + # If we haven't instantiated our global config, do it now and load current config + if _config is None: + _config = Config() + + # Load our config file + cfg_file = os.path.join(os.path.dirname(__file__), 'aliases.ini') + _config.read_config(cfg_file) + + # Try to get builtin commands as normal + rv = click.Group.get_command(self, ctx, cmd_name) + if rv is not None: + return rv + + # No builtin found. Look up an explicit command alias in the config + if cmd_name in _config.aliases: + actual_cmd = _config.aliases[cmd_name] + return click.Group.get_command(self, ctx, actual_cmd) + + # Alternative option: if we did not find an explicit alias we + # allow automatic abbreviation of the command. "status" for + # instance will match "st". We only allow that however if + # there is only one command. + matches = [x for x in self.list_commands(ctx) + if x.lower().startswith(cmd_name.lower())] + if not matches: + # No command name matched. Issue Default command. + ctx.arg0 = cmd_name + cmd_name = self.default_cmd_name + return DefaultGroup.get_command(self, ctx, cmd_name) + elif len(matches) == 1: + return DefaultGroup.get_command(self, ctx, matches[0]) + ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) + + +def run_command(command, pager=False): + if pager is True: + click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) + p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + click.echo_via_pager(p.stdout.read()) + else: + click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) + p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + click.echo(p.stdout.read()) + + +CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?']) + + +# +# 'cli' group (root group) ### +# + +@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS) +def cli(): + """SONiC command line - 'undebug' command""" + pass + + +# +# 'bgp' group ### +# + +# This allows us to add commands to both cli and ip groups, allowing for +@cli.group(cls=AliasedGroup, default_if_no_args=True) +def bgp(): + """undebug bgp on """ + pass + +@bgp.command(default=True) +def default(): + command = 'sudo vtysh -c "undebug bgp"' + run_command(command) + + + +# Add 'bgp' group to both the root 'cli' group and the 'ip' subgroup +cli.add_command(bgp) + + +@bgp.command() +def events(): + """undebug bgp events on """ + command = 'sudo vtysh -c "undebug bgp events"' + run_command(command) + +@bgp.command() +def updates(): + """undebug bgp events on """ + command = 'sudo vtysh -c "undebug bgp updates"' + run_command(command) + +if __name__ == '__main__': + cli() From 0347c46b53140490d85a493049cef674fe083a74 Mon Sep 17 00:00:00 2001 From: Sangita Maity Date: Sun, 1 Oct 2017 23:33:06 -0700 Subject: [PATCH 2/3] Updating patch with latest review-comments. --- debug/main.py | 31 ++++++++++++------------------- scripts/interface_stat | 25 ++++++++++++------------- show/main.py | 41 +++++++++++++++++------------------------ undebug/main.py | 30 ++++++++++++------------------ 4 files changed, 53 insertions(+), 74 deletions(-) mode change 100644 => 100755 debug/main.py mode change 100644 => 100755 scripts/interface_stat diff --git a/debug/main.py b/debug/main.py old mode 100644 new mode 100755 index a8b7460854..1b3a6dfc25 --- a/debug/main.py +++ b/debug/main.py @@ -99,9 +99,8 @@ def run_command(command, pager=False): @click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS) def cli(): - """SONiC command line - 'debug' command""" - pass - + """SONiC command line - 'debug' command""" + pass # # 'bgp' group ### @@ -109,31 +108,25 @@ def cli(): @cli.group(cls=AliasedGroup, default_if_no_args=True) def bgp(): - """debug bgp on """ - pass + """debug bgp on """ + pass @bgp.command(default=True) def default(): - command = 'sudo vtysh -c "debug bgp"' - run_command(command) - - - -# Add 'bgp' group to both the root 'cli' group and the 'ip' subgroup -cli.add_command(bgp) - + command = 'sudo vtysh -c "debug bgp"' + run_command(command) @bgp.command() def events(): - """debug bgp events on """ - command = 'sudo vtysh -c "debug bgp events"' - run_command(command) + """debug bgp events on """ + command = 'sudo vtysh -c "debug bgp events"' + run_command(command) @bgp.command() def updates(): - """debug bgp events on """ - command = 'sudo vtysh -c "debug bgp updates"' - run_command(command) + """debug bgp events on """ + command = 'sudo vtysh -c "debug bgp updates"' + run_command(command) if __name__ == '__main__': cli() diff --git a/scripts/interface_stat b/scripts/interface_stat old mode 100644 new mode 100755 index 81095596ad..d08bc21069 --- a/scripts/interface_stat +++ b/scripts/interface_stat @@ -30,19 +30,18 @@ class Intstat(object): def __init__(self): self.db = swsssdk.SonicV2Connector(host='127.0.0.1') self.db.connect(self.db.APPL_DB) - a = self.db.keys(self.db.APPL_DB) - #print(a) - tables = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*") - i={} - table = [] - key = [] - #print tabulate(header, tablefmt='simple', stralign='right') - for i in tables: - key = re.split(':', i, maxsplit=1)[-1].strip() - if key : - table.append((key, self.get_port_status(key, PORT_LANES_STATUS_FIELD), self.get_port_status(key, PORT_ALIAS_STATUS_FIELD), self.get_port_status(key, PORT_OPER_STATUS_FIELD), self.get_port_status(key, PORT_ADMIN_STATUS_FIELD), self.get_port_status(key, PORT_MTU_STATUS_FIELD))) - print tabulate(table, header, tablefmt="simple", stralign='right') - + a = self.db.keys(self.db.APPL_DB) + #print(a) + tables = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*") + i = {} + table = [] + key = [] + #print tabulate(header, tablefmt='simple', stralign='right') + for i in tables: + key = re.split(':', i, maxsplit=1)[-1].strip() + if key: + table.append((key, self.get_port_status(key, PORT_LANES_STATUS_FIELD), self.get_port_status(key, PORT_ALIAS_STATUS_FIELD), self.get_port_status(key, PORT_OPER_STATUS_FIELD), self.get_port_status(key, PORT_ADMIN_STATUS_FIELD), self.get_port_status(key, PORT_MTU_STATUS_FIELD))) + print tabulate(table, header, tablefmt="simple", stralign='right') def main(): diff --git a/show/main.py b/show/main.py index 12bed445b5..f5cb939ba2 100755 --- a/show/main.py +++ b/show/main.py @@ -171,8 +171,8 @@ def alias(interfacename): click.echo(tabulate(body, header)) -# 'summary' subcommand ("show interfaces summary") -- called if no subcommands are passed -@interfaces.command(default=True) +# 'summary' subcommand ("show interfaces summary") +@interfaces.command() @click.argument('interfacename', required=False) def summary(interfacename): """Show interface status and information""" @@ -191,21 +191,28 @@ def summary(interfacename): def transceiver(): pass -interfaces.add_command(transceiver) @transceiver.command(default=True) @click.argument('interfacename', required=False) def default(interfacename): + """Show interface transceiver information""" + + command = "sudo sfputil show eeprom" + if interfacename is not None: - command = "sudo sfputil -p {}".format(interfacename) - else: - command = "sudo sfputil" + command += " -p {}".format(interfacename) + run_command(command) @transceiver.command() @click.argument('interfacename', required=True) def details(interfacename): - command="sudo sfputil --port {} --dom".format(interfacename) + """Show interface transceiver details (Digital Optical Monitoring)""" + command = "sudo sfputil show eeprom --dom" + + if interfacename is not None: + command += " -p {}".format(interfacename) + run_command(command) @interfaces.command() @@ -215,7 +222,8 @@ def description(interfacename): command = "sudo vtysh -c 'show interface {}'".format(interfacename) else: command = "sudo vtysh -c 'show interface description'" - run_command(command) + + run_command(command) # 'counters' subcommand ("show interfaces counters") @@ -244,19 +252,6 @@ def portchannel(): """Show PortChannel information""" run_command("teamshow") -# 'sfp' subcommand ("show interfaces sfp") -@interfaces.command() -@click.argument('interfacename', required=False) -def sfp(interfacename): - """Show SFP Transceiver information""" - - cmd = "sudo sfputil show eeprom" - - if interfacename is not None: - cmd += " -p {}".format(interfacename) - - run_command(cmd) - @interfaces.command() def status(): """Show Interface status information""" @@ -670,13 +665,11 @@ def system_memory(): command="free -m" run_command(command) -@click.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup, default_if_no_args=False) def vlan(): """Show VLAN information""" pass -cli.add_command(vlan) - @vlan.command() def brief(): """Show all bridge information""" diff --git a/undebug/main.py b/undebug/main.py index d78633662c..8eea73b2e9 100644 --- a/undebug/main.py +++ b/undebug/main.py @@ -96,8 +96,8 @@ def run_command(command, pager=False): @click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS) def cli(): - """SONiC command line - 'undebug' command""" - pass + """SONiC command line - 'undebug' command""" + pass # @@ -107,31 +107,25 @@ def cli(): # This allows us to add commands to both cli and ip groups, allowing for @cli.group(cls=AliasedGroup, default_if_no_args=True) def bgp(): - """undebug bgp on """ - pass + """undebug bgp on """ + pass @bgp.command(default=True) def default(): - command = 'sudo vtysh -c "undebug bgp"' - run_command(command) - - - -# Add 'bgp' group to both the root 'cli' group and the 'ip' subgroup -cli.add_command(bgp) - + command = 'sudo vtysh -c "undebug bgp"' + run_command(command) @bgp.command() def events(): - """undebug bgp events on """ - command = 'sudo vtysh -c "undebug bgp events"' - run_command(command) + """undebug bgp events on """ + command = 'sudo vtysh -c "undebug bgp events"' + run_command(command) @bgp.command() def updates(): - """undebug bgp events on """ - command = 'sudo vtysh -c "undebug bgp updates"' - run_command(command) + """undebug bgp events on """ + command = 'sudo vtysh -c "undebug bgp updates"' + run_command(command) if __name__ == '__main__': cli() From c7ca151a119cc8929ef5ed0159767699ab6ece6b Mon Sep 17 00:00:00 2001 From: Sangita Maity Date: Mon, 2 Oct 2017 13:43:24 -0700 Subject: [PATCH 3/3] One more code-review comment to take care of. --- undebug/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/undebug/main.py b/undebug/main.py index 8eea73b2e9..0203d10d22 100644 --- a/undebug/main.py +++ b/undebug/main.py @@ -128,4 +128,4 @@ def updates(): run_command(command) if __name__ == '__main__': - cli() + cli()