From 1e4346aba2c34f8f68e710f494901372e2fd57d2 Mon Sep 17 00:00:00 2001 From: Sviatoslav Boichuk Date: Fri, 4 Aug 2023 16:01:03 +0300 Subject: [PATCH] Added CLI commands to configure Banner and display current configuration --- config/main.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ show/main.py | 20 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/config/main.py b/config/main.py index 630facb4536..69b70bda338 100644 --- a/config/main.py +++ b/config/main.py @@ -7381,5 +7381,59 @@ def date(date, time): clicommon.run_command(['timedatectl', 'set-time', date_time]) +# +# 'banner' group ('config banner ...') +# +@config.group() +def banner(): + """Configuring system banner messages""" + pass + + +@banner.command() +@click.argument('state', metavar='', 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, 'MESSAGE', + {'state': state}) + + + +@banner.command() +@click.argument('message', metavar='', required=True) +def login(message): + """Set login message""" + + config_db = ConfigDBConnector() + config_db.connect() + config_db.mod_entry(swsscommon.CFG_BANNER_MESSAGE_TABLE_NAME, 'MESSAGE', + {'login': message}) + + +@banner.command() +@click.argument('message', metavar='', required=True) +def logout(message): + """Set logout message""" + + config_db = ConfigDBConnector() + config_db.connect() + config_db.mod_entry(swsscommon.CFG_BANNER_MESSAGE_TABLE_NAME, 'MESSAGE', + {'logout': message}) + + +@banner.command() +@click.argument('message', metavar='', 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, 'MESSAGE', + {'motd': message}) + + if __name__ == '__main__': config() diff --git a/show/main.py b/show/main.py index 725556e6e86..57c842ef43f 100755 --- a/show/main.py +++ b/show/main.py @@ -2139,6 +2139,26 @@ def suppress_pending_fib(db): click.echo(state) +# +# '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', 'MESSAGE') + + 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)