Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into dpu_tty
Browse files Browse the repository at this point in the history
  • Loading branch information
wenchungw committed Sep 19, 2024
2 parents bfec7a9 + 867fc54 commit d2398bc
Show file tree
Hide file tree
Showing 48 changed files with 3,564 additions and 288 deletions.
158 changes: 146 additions & 12 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,38 @@ def watermark():
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
@watermark.command('headroom')
def clear_wm_pg_headroom():
def clear_wm_pg_headroom(namespace):
"""Clear user headroom WM for pg"""
command = ['watermarkstat', '-c', '-t', 'pg_headroom']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@watermark.command('shared')
def clear_wm_pg_shared():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_pg_shared(namespace):
"""Clear user shared WM for pg"""
command = ['watermarkstat', '-c', '-t', 'pg_shared']
if namespace:
command += ['-n', str(namespace)]
run_command(command)

@priority_group.group()
Expand All @@ -261,16 +283,38 @@ def persistent_watermark():
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@persistent_watermark.command('headroom')
def clear_pwm_pg_headroom():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_pg_headroom(namespace):
"""Clear persistent headroom WM for pg"""
command = ['watermarkstat', '-c', '-p', '-t', 'pg_headroom']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@persistent_watermark.command('shared')
def clear_pwm_pg_shared():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_pg_shared(namespace):
"""Clear persistent shared WM for pg"""
command = ['watermarkstat', '-c', '-p', '-t', 'pg_shared']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


Expand All @@ -285,69 +329,159 @@ def watermark():
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@watermark.command('unicast')
def clear_wm_q_uni():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_q_uni(namespace):
"""Clear user WM for unicast queues"""
command = ['watermarkstat', '-c', '-t', 'q_shared_uni']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@watermark.command('multicast')
def clear_wm_q_multi():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_q_multi(namespace):
"""Clear user WM for multicast queues"""
command = ['watermarkstat', '-c', '-t', 'q_shared_multi']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@watermark.command('all')
def clear_wm_q_all():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_q_all(namespace):
"""Clear user WM for all queues"""
command = ['watermarkstat', '-c', '-t', 'q_shared_all']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@queue.group(name='persistent-watermark')
def persistent_watermark():
"""Clear queue persistent WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@persistent_watermark.command('unicast')
def clear_pwm_q_uni():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_q_uni(namespace):
"""Clear persistent WM for persistent queues"""
command = ['watermarkstat', '-c', '-p', '-t', 'q_shared_uni']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@persistent_watermark.command('multicast')
def clear_pwm_q_multi():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_q_multi(namespace):
"""Clear persistent WM for multicast queues"""
command = ['watermarkstat', '-c', '-p', '-t', 'q_shared_multi']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@persistent_watermark.command('all')
def clear_pwm_q_all():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_q_all(namespace):
"""Clear persistent WM for all queues"""
command = ['watermarkstat', '-c', '-p', '-t', 'q_shared_all']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@cli.group(name='headroom-pool')
def headroom_pool():
"""Clear headroom pool WM"""
pass


@headroom_pool.command('watermark')
def watermark():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def watermark(namespace):
"""Clear headroom pool user WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")

command = ['watermarkstat', '-c', '-t', 'headroom_pool']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@headroom_pool.command('persistent-watermark')
def persistent_watermark():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def persistent_watermark(namespace):
"""Clear headroom pool persistent WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")

command = ['watermarkstat', '-c', '-p', '-t', 'headroom_pool']
if namespace:
command += ['-n', str(namespace)]
run_command(command)

#
Expand Down
66 changes: 66 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7987,5 +7987,71 @@ def notice(db, category_list, max_events, namespace):
handle_asic_sdk_health_suppress(db, 'notice', category_list, max_events, namespace)


#
# 'serial_console' group ('config serial_console')
#
@config.group(cls=clicommon.AbbreviationGroup, name='serial_console')
def serial_console():
"""Configuring system serial-console behavior"""
pass


@serial_console.command('sysrq-capabilities')
@click.argument('sysrq_capabilities', metavar='<enabled|disabled>', required=True,
type=click.Choice(['enabled', 'disabled']))
def sysrq_capabilities(sysrq_capabilities):
"""Set serial console sysrq-capabilities state"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry("SERIAL_CONSOLE", 'POLICIES',
{'sysrq_capabilities': sysrq_capabilities})


@serial_console.command('inactivity-timeout')
@click.argument('inactivity_timeout', metavar='<timeout>', required=True,
type=click.IntRange(0, 35000))
def inactivity_timeout_serial(inactivity_timeout):
"""Set serial console inactivity timeout"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry("SERIAL_CONSOLE", 'POLICIES',
{'inactivity_timeout': inactivity_timeout})


#
# 'ssh' group ('config ssh')
#
@config.group(cls=clicommon.AbbreviationGroup, name='ssh')
def ssh():
"""Configuring system ssh behavior"""
pass


@ssh.command('inactivity-timeout')
@click.argument('inactivity_timeout', metavar='<timeout>', required=True,
type=click.IntRange(0, 35000))
def inactivity_timeout_ssh(inactivity_timeout):
"""Set ssh inactivity timeout"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry("SSH_SERVER", 'POLICIES',
{'inactivity_timeout': inactivity_timeout})


@ssh.command('max-sessions')
@click.argument('max-sessions', metavar='<max-sessions>', required=True,
type=click.IntRange(0, 100))
def max_sessions(max_sessions):
"""Set max number of concurrent logins"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry("SSH_SERVER", 'POLICIES',
{'max_sessions': max_sessions})


if __name__ == '__main__':
config()
Loading

0 comments on commit d2398bc

Please sign in to comment.