From 2e2a2bc1491ed3aa027ee051b76d14b6c325d928 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 14:04:36 -0800 Subject: [PATCH 01/17] [auto-restart] Add a show command to display the status of auto-restart features for containers. Signed-off-by: Yong Zhao --- show/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/show/main.py b/show/main.py index 21b8352e4c..5fab66f5ec 100755 --- a/show/main.py +++ b/show/main.py @@ -2806,5 +2806,21 @@ def features(): body.append([key, status_data[key]['status']]) click.echo(tabulate(body, header)) +# show whether the auto-restart feature for each container +# is enabled or disabled. + +@cli.command('autorestart') +def features(): + """Show status of auto-restart features""" + config_db = ConfigDBConnector() + config_db.connect() + header = ['ContainerName', 'Status'] + body = [] + container_feature_table = config_db.get_table('CONTAINER_FEATURE') + for container_name in container_feature_table.keys(): + body.append([container_name, container_feature_table[container_name]['auto_restart']]) + click.echo(tabulate(body, header)) + + if __name__ == '__main__': cli() From 668426b86a3cd836234ec8a395c785f61b8eb500 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 15:12:06 -0800 Subject: [PATCH 02/17] [show subcommand] Add an option parameter --container-name. Signed-off-by: Yong Zhao --- show/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index 5fab66f5ec..9397e3f6d3 100755 --- a/show/main.py +++ b/show/main.py @@ -2810,15 +2810,20 @@ def features(): # is enabled or disabled. @cli.command('autorestart') -def features(): +@click.option('-c', '--container-name', required=False) +def autorestart(container-name): """Show status of auto-restart features""" config_db = ConfigDBConnector() config_db.connect() header = ['ContainerName', 'Status'] body = [] container_feature_table = config_db.get_table('CONTAINER_FEATURE') - for container_name in container_feature_table.keys(): - body.append([container_name, container_feature_table[container_name]['auto_restart']]) + if container-name: + if container_feature_table and container_feature_table.has_key(container-name): + body.append([container-name, container_feature_table[container-name]['auto_restart']]) + else: + for name in container_feature_table.keys(): + body.append([name, container_feature_table[name]['auto_restart']]) click.echo(tabulate(body, header)) From d6d66e59303ed1868e7aed5a291f22f5ff174e5c Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 15:14:05 -0800 Subject: [PATCH 03/17] [show subcommand] Change the comment. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 9397e3f6d3..9b4e9e989c 100755 --- a/show/main.py +++ b/show/main.py @@ -2806,7 +2806,7 @@ def features(): body.append([key, status_data[key]['status']]) click.echo(tabulate(body, header)) -# show whether the auto-restart feature for each container +# show whether the auto-restart feature for each container or a specific # is enabled or disabled. @cli.command('autorestart') From 520ba480d372306bc91520afd11dae4d611a5667 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 15:15:14 -0800 Subject: [PATCH 04/17] [show subcommand] Change the comment. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 9b4e9e989c..f6d71da8f8 100755 --- a/show/main.py +++ b/show/main.py @@ -2806,7 +2806,7 @@ def features(): body.append([key, status_data[key]['status']]) click.echo(tabulate(body, header)) -# show whether the auto-restart feature for each container or a specific +# show whether the auto-restart feature for containers or a specific container # is enabled or disabled. @cli.command('autorestart') From 3f5a5e4e1a996b5f99093bd0848cf02cf5d4dd63 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 16:11:39 -0800 Subject: [PATCH 05/17] [show subcommand] Place show autorestart in "container" and "feature" subgroups. Signed-off-by: Yong Zhao --- show/main.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/show/main.py b/show/main.py index f6d71da8f8..214c8ee05a 100755 --- a/show/main.py +++ b/show/main.py @@ -2806,13 +2806,25 @@ def features(): body.append([key, status_data[key]['status']]) click.echo(tabulate(body, header)) +# +# 'container' group +# +@cli.group(cls=AliasedGroup, default_if_no_args=False) +def container() + """Show container feature""" + pass + +@container.command('feature') +def feature() + pass + # show whether the auto-restart feature for containers or a specific container # is enabled or disabled. -@cli.command('autorestart') +@feature.command('autorestart') @click.option('-c', '--container-name', required=False) def autorestart(container-name): - """Show status of auto-restart features""" + """Show container feature autorestart""" config_db = ConfigDBConnector() config_db.connect() header = ['ContainerName', 'Status'] From f0990edf64a788eca6dc60fe63c9070960303a9a Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 16:23:44 -0800 Subject: [PATCH 06/17] [show subcommand] Change feature to a subgroup. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 214c8ee05a..cbab4cf07c 100755 --- a/show/main.py +++ b/show/main.py @@ -2814,7 +2814,7 @@ def container() """Show container feature""" pass -@container.command('feature') +@container.group('feature') def feature() pass From 08c650746a65f24507a36b236401255e8545d42b Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 16:29:20 -0800 Subject: [PATCH 07/17] [Show subcommand] Change the comment in the function container() and feature(). Signed-off-by: Yong Zhao --- show/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index cbab4cf07c..25312c2293 100755 --- a/show/main.py +++ b/show/main.py @@ -2811,11 +2811,12 @@ def features(): # @cli.group(cls=AliasedGroup, default_if_no_args=False) def container() - """Show container feature""" + """Show container""" pass @container.group('feature') def feature() + """Show container feature""" pass # show whether the auto-restart feature for containers or a specific container From a8ad256439ff143887976ccb1d63a01d113add1e Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 16:32:58 -0800 Subject: [PATCH 08/17] [show subcommand] Change the type of argument. Signed-off-by: Yong Zhao --- show/main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/show/main.py b/show/main.py index 25312c2293..732a72c4e3 100755 --- a/show/main.py +++ b/show/main.py @@ -2813,7 +2813,9 @@ def features(): def container() """Show container""" pass - +# +# 'feature' group +# @container.group('feature') def feature() """Show container feature""" @@ -2823,17 +2825,17 @@ def feature() # is enabled or disabled. @feature.command('autorestart') -@click.option('-c', '--container-name', required=False) -def autorestart(container-name): +@click.argument('container_name', required=False) +def autorestart(container_name): """Show container feature autorestart""" config_db = ConfigDBConnector() config_db.connect() header = ['ContainerName', 'Status'] body = [] container_feature_table = config_db.get_table('CONTAINER_FEATURE') - if container-name: + if container_name: if container_feature_table and container_feature_table.has_key(container-name): - body.append([container-name, container_feature_table[container-name]['auto_restart']]) + body.append([container_name, container_feature_table[container_name]['auto_restart']]) else: for name in container_feature_table.keys(): body.append([name, container_feature_table[name]['auto_restart']]) From a1d06f737e9d8ae24ccdc031014feaf6529fbe6e Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 16:37:05 -0800 Subject: [PATCH 09/17] [show subcommand] Change the parameter in feature subgroup. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 732a72c4e3..d9d921f9e4 100755 --- a/show/main.py +++ b/show/main.py @@ -2816,7 +2816,7 @@ def container() # # 'feature' group # -@container.group('feature') +@container.group(cls=AliasedGroup, default_if_no_args=False) def feature() """Show container feature""" pass From 76d4a878599f75fadb2a2fc712c5079c62a73301 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 17:09:48 -0800 Subject: [PATCH 10/17] [show subcommand] Reorganize the parameters for subgroups container and feature. Signed-off-by: Yong Zhao --- show/main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/show/main.py b/show/main.py index d9d921f9e4..801b0c3a82 100755 --- a/show/main.py +++ b/show/main.py @@ -2807,27 +2807,31 @@ def features(): click.echo(tabulate(body, header)) # -# 'container' group +# 'container' group (show container ...) # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(name='container', invoke_without_command=False) def container() """Show container""" pass # -# 'feature' group +# 'feature' group (show container feature ...) # -@container.group(cls=AliasedGroup, default_if_no_args=False) +@container.group(name='feature', invoke_without_command=False) def feature() """Show container feature""" pass -# show whether the auto-restart feature for containers or a specific container -# is enabled or disabled. +# +# 'autorestart' subcommand (show container feature autorestart) +# @feature.command('autorestart') @click.argument('container_name', required=False) def autorestart(container_name): - """Show container feature autorestart""" + """show whether the auto-restart feature for containers or a specific container + is enabled or disabled. + """ + config_db = ConfigDBConnector() config_db.connect() header = ['ContainerName', 'Status'] From b2cd68d41ab9e02db7529a00f2fb72bc7248eb9b Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 17:12:01 -0800 Subject: [PATCH 11/17] [show subcommand] Delete an extra blank line. Signed-off-by: Yong Zhao --- show/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/show/main.py b/show/main.py index 801b0c3a82..f85282cc58 100755 --- a/show/main.py +++ b/show/main.py @@ -2845,6 +2845,5 @@ def autorestart(container_name): body.append([name, container_feature_table[name]['auto_restart']]) click.echo(tabulate(body, header)) - if __name__ == '__main__': cli() From d10625c4f5d892cc0289b59a84d860528a26df08 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 18:09:06 -0800 Subject: [PATCH 12/17] [show subcommand] Use short_help to display the explanation of function. Signed-off-by: Yong Zhao --- show/main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/show/main.py b/show/main.py index f85282cc58..04c42c3334 100755 --- a/show/main.py +++ b/show/main.py @@ -2810,14 +2810,14 @@ def features(): # 'container' group (show container ...) # @cli.group(name='container', invoke_without_command=False) -def container() +def container(): """Show container""" pass # # 'feature' group (show container feature ...) # @container.group(name='feature', invoke_without_command=False) -def feature() +def feature(): """Show container feature""" pass @@ -2825,12 +2825,9 @@ def feature() # 'autorestart' subcommand (show container feature autorestart) # -@feature.command('autorestart') +@feature.command('autorestart', short_help="Show whether the auto-restart feature for contain(s) is enabled or disabled") @click.argument('container_name', required=False) def autorestart(container_name): - """show whether the auto-restart feature for containers or a specific container - is enabled or disabled. - """ config_db = ConfigDBConnector() config_db.connect() From 4fa0d4a7bef52f096810fa6f67a4f32f7063026a Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 18:14:09 -0800 Subject: [PATCH 13/17] [Show subcommand] Correct a typo for the short_help parameter. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 04c42c3334..e05389e9a7 100755 --- a/show/main.py +++ b/show/main.py @@ -2825,7 +2825,7 @@ def feature(): # 'autorestart' subcommand (show container feature autorestart) # -@feature.command('autorestart', short_help="Show whether the auto-restart feature for contain(s) is enabled or disabled") +@feature.command('autorestart', short_help="Show whether the auto-restart feature for container(s) is enabled or disabled") @click.argument('container_name', required=False) def autorestart(container_name): From 00ac86d0bcdaefc1da75805bcec74fee9f1c5e7c Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 18:15:32 -0800 Subject: [PATCH 14/17] [Show subcommand] Delete a blank line. Signed-off-by: Yong Zhao --- show/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/show/main.py b/show/main.py index e05389e9a7..23d86a1148 100755 --- a/show/main.py +++ b/show/main.py @@ -2828,7 +2828,6 @@ def feature(): @feature.command('autorestart', short_help="Show whether the auto-restart feature for container(s) is enabled or disabled") @click.argument('container_name', required=False) def autorestart(container_name): - config_db = ConfigDBConnector() config_db.connect() header = ['ContainerName', 'Status'] From 4f199c159f313e82b2d665bd1aaf29148e4dc225 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Mon, 3 Feb 2020 18:17:06 -0800 Subject: [PATCH 15/17] [show subcommand] Delete a blank line. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 23d86a1148..84aa47bebf 100755 --- a/show/main.py +++ b/show/main.py @@ -2813,6 +2813,7 @@ def features(): def container(): """Show container""" pass + # # 'feature' group (show container feature ...) # @@ -2824,7 +2825,6 @@ def feature(): # # 'autorestart' subcommand (show container feature autorestart) # - @feature.command('autorestart', short_help="Show whether the auto-restart feature for container(s) is enabled or disabled") @click.argument('container_name', required=False) def autorestart(container_name): From 42963dd1d3e3abe26901fe5882810c25a288122e Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Tue, 4 Feb 2020 10:27:43 -0800 Subject: [PATCH 16/17] [show subcommand] Chnage the column header of ContainerName to Container Name. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 84aa47bebf..b3ac53478d 100755 --- a/show/main.py +++ b/show/main.py @@ -2830,7 +2830,7 @@ def feature(): def autorestart(container_name): config_db = ConfigDBConnector() config_db.connect() - header = ['ContainerName', 'Status'] + header = ['Container Name', 'Status'] body = [] container_feature_table = config_db.get_table('CONTAINER_FEATURE') if container_name: From 7e6b08e1adf9124d880a97c92596c803b0c1e7eb Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Tue, 4 Feb 2020 10:44:44 -0800 Subject: [PATCH 17/17] [Show subcommand] Correct the container-name to container_name. Signed-off-by: Yong Zhao --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index b3ac53478d..cb116d20de 100755 --- a/show/main.py +++ b/show/main.py @@ -2834,7 +2834,7 @@ def autorestart(container_name): body = [] container_feature_table = config_db.get_table('CONTAINER_FEATURE') if container_name: - if container_feature_table and container_feature_table.has_key(container-name): + if container_feature_table and container_feature_table.has_key(container_name): body.append([container_name, container_feature_table[container_name]['auto_restart']]) else: for name in container_feature_table.keys():