Skip to content

Commit

Permalink
Added CLI commands to configure Banner and display current configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Fastiuk <yfastiuk@nvidia.com>
  • Loading branch information
fastiuk committed May 19, 2024
1 parent 556026c commit 1ae2d63
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
54 changes: 54 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7750,5 +7750,59 @@ def notice(db, category_list, max_events, namespace):
handle_asic_sdk_health_suppress(db, 'notice', category_list, max_events, namespace)


#
# 'banner' group ('config banner ...')
#
@config.group()
def banner():
"""Configuring system banner messages"""
pass


@banner.command()
@click.argument('state', metavar='<enabled|disabled>', required=True, type=click.Choice(['enabled', 'disabled']))
def state(state):
"""Set banner feature state"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry(swsscommon.CFG_BANNER_MESSAGE_TABLE_NAME, 'global',
{'state': state})



@banner.command()
@click.argument('message', metavar='<message>', required=True)
def login(message):
"""Set login message"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry(swsscommon.CFG_BANNER_MESSAGE_TABLE_NAME, 'global',
{'login': message})


@banner.command()
@click.argument('message', metavar='<message>', required=True)
def logout(message):
"""Set logout message"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry(swsscommon.CFG_BANNER_MESSAGE_TABLE_NAME, 'global',
{'logout': message})


@banner.command()
@click.argument('message', metavar='<message>', required=True)
def motd(message):
"""Set message of the day"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry(swsscommon.CFG_BANNER_MESSAGE_TABLE_NAME, 'global',
{'motd': message})


if __name__ == '__main__':
config()
20 changes: 20 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,26 @@ def received(db, namespace):
ctx.fail("ASIC/SDK health event is not supported on the platform")


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

banner_table = db.cfgdb.get_entry('BANNER_MESSAGE', 'global')

hdrs = ['state', 'login', 'motd', 'logout']
data = []

for key in hdrs:
data.append(banner_table.get(key, '').replace('\\n', '\n'))

messages = [data]
click.echo(tabulate(messages, 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 1ae2d63

Please sign in to comment.