Skip to content

Commit bb10686

Browse files
authored
[show] Add subcommand to display the status of auto-restart feature for each container (#798)
Since we introduced the auto-restart feature for each container, we need add a show subcommand to display the current status of auto-restart feature for all containers or a specific container. - How I did it We define a function named autorestart to show the status of this features. This function will accept an option parameter which is the container name. If this parameter is not specified, this function will by default show the status of all containers. Otherwise it will show the status of specific container. Signed-off-by: Yong Zhao <[email protected]>
1 parent 1fc2c3d commit bb10686

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

show/main.py

+35
Original file line numberDiff line numberDiff line change
@@ -2806,5 +2806,40 @@ def features():
28062806
body.append([key, status_data[key]['status']])
28072807
click.echo(tabulate(body, header))
28082808

2809+
#
2810+
# 'container' group (show container ...)
2811+
#
2812+
@cli.group(name='container', invoke_without_command=False)
2813+
def container():
2814+
"""Show container"""
2815+
pass
2816+
2817+
#
2818+
# 'feature' group (show container feature ...)
2819+
#
2820+
@container.group(name='feature', invoke_without_command=False)
2821+
def feature():
2822+
"""Show container feature"""
2823+
pass
2824+
2825+
#
2826+
# 'autorestart' subcommand (show container feature autorestart)
2827+
#
2828+
@feature.command('autorestart', short_help="Show whether the auto-restart feature for container(s) is enabled or disabled")
2829+
@click.argument('container_name', required=False)
2830+
def autorestart(container_name):
2831+
config_db = ConfigDBConnector()
2832+
config_db.connect()
2833+
header = ['Container Name', 'Status']
2834+
body = []
2835+
container_feature_table = config_db.get_table('CONTAINER_FEATURE')
2836+
if container_name:
2837+
if container_feature_table and container_feature_table.has_key(container_name):
2838+
body.append([container_name, container_feature_table[container_name]['auto_restart']])
2839+
else:
2840+
for name in container_feature_table.keys():
2841+
body.append([name, container_feature_table[name]['auto_restart']])
2842+
click.echo(tabulate(body, header))
2843+
28092844
if __name__ == '__main__':
28102845
cli()

0 commit comments

Comments
 (0)