sonic-buildimage/dockers/docker-macsec/cli/clear/plugins/clear_macsec_counter.py
Mai Bui 1477f779de
modify commands using utilities_common.cli.run_command and advance sonic-utilities submodule on master (#15193)
Dependency:
sonic-net/sonic-utilities#2718

Why I did it
This PR sonic-net/sonic-utilities#2718 reduce shell=True usage in utilities_common.cli.run_command() function.

Work item tracking
Microsoft ADO (number only): 15022050
How I did it
Replace strings commands using utilities_common.cli.run_command() function to list of strings

due to circular dependency, advance sonic-utilities submodule
72ca4848 (HEAD -> master, upstream/master, upstream/HEAD) Add CLI configuration options for teamd retry count feature (sonic-net/sonic-utilities#2642)
359dfc0c [Clock] Implement clock CLI (sonic-net/sonic-utilities#2793)
b316fc27 Add transceiver status CLI to show output from TRANSCEIVER_STATUS table (sonic-net/sonic-utilities#2772)
dc59dbd2 Replace pickle by json (sonic-net/sonic-utilities#2849)
a66f41c4 [show] replace shell=True, replace xml by lxml, replace exit by sys.exit (sonic-net/sonic-utilities#2666)
57500572 [utilities_common] replace shell=True (sonic-net/sonic-utilities#2718)
6e0ee3e7 [CRM][DASH] Extend CRM utility to support DASH resources. (sonic-net/sonic-utilities#2800)
b2c29b0b [config] Generate sysinfo in single asic (sonic-net/sonic-utilities#2856)
2023-06-05 17:08:13 +08:00

37 lines
1.2 KiB
Python

import os
import click
import show.plugins.macsec as show_macsec
import utilities_common.cli as clicommon
from sonic_py_common import multi_asic
@click.group(cls=clicommon.AliasedGroup)
def macsec():
pass
@macsec.command('macsec')
@click.option('--clean-cache', type=bool, required=False, default=False, help="If the option of clean cache is true, next show commands will show the raw counters which based on the service booted instead of the last clear command.")
def macsec_clear_counters(clean_cache):
"""
Clear MACsec counts.
This clear command will generated a cache for next show commands which will base on this cache as the zero baseline to show the increment of counters.
"""
if clean_cache:
for namespace in multi_asic.get_namespace_list():
if os.path.isfile(show_macsec.CACHE_FILE.format(namespace)):
os.remove(show_macsec.CACHE_FILE.format(namespace))
print("Cleaned cache")
return
clicommon.run_command(['show', 'macsec', '--dump-file'])
print("Clear MACsec counters")
def register(cli):
cli.add_command(macsec_clear_counters)
if __name__ == '__main__':
macsec_clear_counters(None)