From 9a86a2c7951bf4a3299f63ab210dc24436a6fc5d Mon Sep 17 00:00:00 2001 From: Amit Abel Date: Mon, 28 Jul 2025 16:43:30 +0300 Subject: [PATCH 1/2] lab5 developement --- config/main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- show/main.py | 16 ++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/config/main.py b/config/main.py index 45224de7b83..ef71eaba860 100644 --- a/config/main.py +++ b/config/main.py @@ -5871,7 +5871,6 @@ def frequency(ctx, interface_name, frequency): clicommon.run_command(command) - # # 'tx_power' subcommand ('config interface transceiver tx_power ...') # For negative float use:- @@ -7157,8 +7156,54 @@ def remove_vrrp_v6(ctx, interface_name, vrrp_id): # -# 'vrf' group ('config vrf ...') +# 'tx_error_status' command ("config tx_tx_error_status") # +@config.group(cls=clicommon.AbbreviationGroup, name='tx_error_status') +@click.pass_context +def tx_error_status(): + config_db = ConfigDBConnector() + config_db.connect() + ctx.obj = {} + ctx.obj['config_db'] = config_db + +@tx_error_status.command('set') +@click.argument('threshold', type=int, required=False) +@click.argument('time_period', type=int, required=False) +@click.pass_context +def set_tx_error_status(ctx, threshold, time_period): + """Configure Tx error status threshold and/or time period""" + if threshold is None and time_period is None: + ctx.fail("Please provide either threshold or time period") + + config_db = ValidatedConfigDBConnector(ctx.obj['config_db']) + + if threshold is not None: + if threshold < 0: + ctx.fail("Invalid threshold {}. Only valid threshold is accepted".format(threshold)) + config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'threshold': threshold}) + + if time_period is not None: + if time_period < 0: + ctx.fail("Invalid time period {}. Only valid time period is accepted".format(time_period)) + config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'time_period': time_period}) + + +@tx_error_status.command('del') +@click.argument('threshold', type=bool, required=False) +@click.argument('time_period', type=bool, required=False) +@click.pass_context +def del_tx_error_status(ctx, vrf_name): + """Delete configured Tx error status threshold and/or time period""" + if threshold is None and time_period is None: + ctx.fail("Please provide either threshold or time period") + + config_db = ValidatedConfigDBConnector(ctx.obj['config_db']) + + if threshold is not None and threshold is True: + config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'threshold': None}) + + if time_period is not None and time_period is True: + config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'time_period': None}) @config.group(cls=clicommon.AbbreviationGroup, name='vrf') @click.pass_context diff --git a/show/main.py b/show/main.py index 527cd3048da..e0605a5656e 100755 --- a/show/main.py +++ b/show/main.py @@ -405,6 +405,22 @@ def event_counters(): else: click.echo('No data available in COUNTERS_EVENTS\n') +# +# 'tx_error_status' command ("show tx_tx_error_status") +# +@cli.command() +@clicommon.pass_db +@click.argument('port', required=True) +def tx_error_status(db, port): + """Show details of the Tx error port status""" + + full_table_id = "PORT_TABLE|" + port + port_state = db.get(db.db.STATE_DB, full_table_id, 'tx_error_port_state') + + if port_state is None: + click.echo('No data available in Port table state for port: {}\n'.format(port)) + + click.echo('State of Port {} is {}'.format(port, port_state)) # # 'arp' command ("show arp") From b81cfca04ff5a74e9178524c30babf853a8d8924 Mon Sep 17 00:00:00 2001 From: Amit Abel Date: Wed, 30 Jul 2025 13:35:53 +0300 Subject: [PATCH 2/2] more fixes for LAB5 --- config/main.py | 51 +++++++++++++++++++++++--------------------------- show/main.py | 8 ++++---- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/config/main.py b/config/main.py index ef71eaba860..74855c920e3 100644 --- a/config/main.py +++ b/config/main.py @@ -7159,51 +7159,46 @@ def remove_vrrp_v6(ctx, interface_name, vrrp_id): # 'tx_error_status' command ("config tx_tx_error_status") # @config.group(cls=clicommon.AbbreviationGroup, name='tx_error_status') -@click.pass_context def tx_error_status(): - config_db = ConfigDBConnector() - config_db.connect() - ctx.obj = {} - ctx.obj['config_db'] = config_db + pass + @tx_error_status.command('set') -@click.argument('threshold', type=int, required=False) -@click.argument('time_period', type=int, required=False) +@click.option('-t', '--threshold', type=click.IntRange(min=1), + help='Configure threshold for Tx error state - for all ports') +@click.option('-p', '--period', type=click.IntRange(min=1), + help='Configure time period for Tx error state - for all ports') +@clicommon.pass_db @click.pass_context -def set_tx_error_status(ctx, threshold, time_period): +def set_tx_error_status(ctx, db ,threshold, period): """Configure Tx error status threshold and/or time period""" - if threshold is None and time_period is None: + if threshold is None and period is None: ctx.fail("Please provide either threshold or time period") - - config_db = ValidatedConfigDBConnector(ctx.obj['config_db']) - + if threshold is not None: - if threshold < 0: - ctx.fail("Invalid threshold {}. Only valid threshold is accepted".format(threshold)) - config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'threshold': threshold}) + db.cfgdb.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'threshold': threshold}) - if time_period is not None: - if time_period < 0: - ctx.fail("Invalid time period {}. Only valid time period is accepted".format(time_period)) - config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'time_period': time_period}) + if period is not None: + db.cfgdb.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'time_period': period}) @tx_error_status.command('del') -@click.argument('threshold', type=bool, required=False) -@click.argument('time_period', type=bool, required=False) +@click.option('-t', '--threshold', type=bool, + help='Is delete threshold for Tx error state - for all ports') +@click.option('-p', '--period', type=bool, + help='Is delete time period for Tx error state - for all ports') +@clicommon.pass_db @click.pass_context -def del_tx_error_status(ctx, vrf_name): +def del_tx_error_status(ctx, db, threshold, period): """Delete configured Tx error status threshold and/or time period""" - if threshold is None and time_period is None: + if threshold is None and period is None: ctx.fail("Please provide either threshold or time period") - config_db = ValidatedConfigDBConnector(ctx.obj['config_db']) - if threshold is not None and threshold is True: - config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'threshold': None}) + db.cfgdb.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'threshold': None}) - if time_period is not None and time_period is True: - config_db.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'time_period': None}) + if period is not None and period is True: + db.cfgdb.mod_entry('TX_ERROR_CHECK_TABLE', 'TX_ERROR_CHECK', {'time_period': None}) @config.group(cls=clicommon.AbbreviationGroup, name='vrf') @click.pass_context diff --git a/show/main.py b/show/main.py index e0605a5656e..f919af19d78 100755 --- a/show/main.py +++ b/show/main.py @@ -406,7 +406,7 @@ def event_counters(): click.echo('No data available in COUNTERS_EVENTS\n') # -# 'tx_error_status' command ("show tx_tx_error_status") +# 'tx_error_status' command ("show tx_error_status") # @cli.command() @clicommon.pass_db @@ -415,12 +415,12 @@ def tx_error_status(db, port): """Show details of the Tx error port status""" full_table_id = "PORT_TABLE|" + port - port_state = db.get(db.db.STATE_DB, full_table_id, 'tx_error_port_state') + port_state = db.db.get(db.db.STATE_DB, full_table_id, 'tx_error_port_state') if port_state is None: click.echo('No data available in Port table state for port: {}\n'.format(port)) - - click.echo('State of Port {} is {}'.format(port, port_state)) + else: + click.echo('State of Port {} is {}'.format(port, port_state)) # # 'arp' command ("show arp")