Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement cli code for lab 5 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6921,5 +6921,29 @@ def del_subinterface(ctx, subinterface_name):
except JsonPatchConflict as e:
ctx.fail("{} is invalid vlan subinterface. Error: {}".format(subinterface_name, e))

#
# 'txargs_threshold' command
#
@config.command('txargs_threshold')
@click.argument('new_threshold', metavar='<new_threshold>', required=True)
def txargs_threshold(new_threshold):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment that describes what this function do


config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry("TX_ERROR_MONITOR", 'config_tx_threshold',
{'threshold': new_threshold})

#
# 'txargs_duration' command
#
@config.command('txargs_duration')
@click.argument('new_duration', metavar='<new_duration>', required=True)
def txargs_duration(new_duration):

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry("TX_ERROR_MONITOR", 'config_tx_duration',
{'duration': new_duration})

if __name__ == '__main__':
config()
46 changes: 46 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,52 @@ def peer(db, peer_ip):

click.echo(tabulate(bfd_body, bfd_headers))

#
# 'tx_monitor_interface' group ("show tx_monitor_interface ...")
#

@cli.group(name='tx_monitor_interface', cls=clicommon.AliasedGroup)
def tx_monitor_interface():
"""Show management interface parameters"""
pass

# 'tx_fields' subcommand ("show tx_monitor_interface tx_fields")
@tx_monitor_interface.command()
def data ():
"""Show data configured for tx_monitor interface"""

config_db = ConfigDBConnector()
config_db.connect()

# Fetching data from config_db for TX_ERROR_MONITOR
tx_monitor_data = config_db.get_table('TX_ERROR_MONITOR')
for key in natsorted(list(tx_monitor_data.keys())):
click.echo("{0}".format(tx_monitor_data[key]))


#
# 'txstate' group ("show txstate ...")
#
@cli.group(cls=clicommon.AliasedGroup)
def txstate():
"""Show details of the txstate sessions"""
pass

# 'summary' subcommand ("show txstate summary")
@txstate.command()
@clicommon.pass_db
def summary(db):
"""Show txstate session information"""
txstate_keys = db.db.get_all(db.db.STATE_DB, "TX_ERROR_TABLE")
txstate_headers = ["Interface Name", "Tx State"]
txstate_body = []
if txstate_keys is not None:
for key in sorted(txstate_keys.keys()):
txstate_body.append([key, txstate_keys[key]])
else:
click.echo("EMPTY DATA")
click.echo(tabulate(txstate_body, txstate_headers, tablefmt="grid"))


# Load plugins and register them
helper = util_base.UtilHelper()
Expand Down