Skip to content

Commit

Permalink
SONIC CLI for CLI-Sessions feature
Browse files Browse the repository at this point in the history
  • Loading branch information
i-davydenko committed May 21, 2024
1 parent 7298cd2 commit 103f903
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
64 changes: 64 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7750,5 +7750,69 @@ 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()
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()
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()
39 changes: 39 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,45 @@ def received(db, namespace):
ctx.fail("ASIC/SDK health event is not supported on the platform")


#
# 'serial_console' command group ("show serial_console ...")
#
@cli.group('serial_console', invoke_without_command=True)
@clicommon.pass_db
def serial_console(db):
"""Show serial_console configuration"""

serial_console_table = db.cfgdb.get_entry('SERIAL_CONSOLE', 'POLICIES')

hdrs = ['inactivity-timeout', 'sysrq-capabilities']
data = []

data.append(serial_console_table.get('inactivity_timeout', '900 <default>'))
data.append(serial_console_table.get('sysrq_capabilities', 'disabled <default>'))

configuration = [data]
click.echo(tabulate(configuration, headers=hdrs, tablefmt='simple', missingval=''))

#
# 'ssh' command group ("show ssh ...")
#
@cli.group('ssh', invoke_without_command=True)
@clicommon.pass_db
def ssh(db):
"""Show ssh configuration"""

serial_console_table = db.cfgdb.get_entry('SSH_SERVER', 'POLICIES')

hdrs = ['inactivity-timeout', 'max-sessions']
data = []

data.append(serial_console_table.get('inactivity_timeout', '900 <default>'))
data.append(serial_console_table.get('max_session', '0 <default>'))

configuration = [data]
click.echo(tabulate(configuration, headers=hdrs, tablefmt='simple', missingval=''))


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

0 comments on commit 103f903

Please sign in to comment.