From 3fb603bc95d4f470773680089886b04d51013139 Mon Sep 17 00:00:00 2001 From: "Yuanbin.Chen" Date: Wed, 18 Jul 2018 15:45:50 +0800 Subject: [PATCH] Change container execute top return Change ps id option parameter, top default list all process, if ps id exist top list single process. Change-Id: I4bba71c695b88561f5c0245ea3c1a90f30574d2c Signed-off-by: Yuanbin.Chen --- zunclient/osc/v1/containers.py | 19 ++++++++++++------- zunclient/v1/containers_shell.py | 16 +++++++++++----- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index 26f93316..b3a46b86 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -867,17 +867,22 @@ class TopContainer(command.Command): metavar='', help='ID or name of the container to display processes.') parser.add_argument( - 'ps_args', - metavar='', - nargs=argparse.REMAINDER, - help='The args of the ps command.') + '--pid', + metavar='', + action='append', default=[], + help='The args of the ps id.') return parser def take_action(self, parsed_args): client = _get_client(self, parsed_args) - container = parsed_args.container - ps = ' '.join(parsed_args.ps_args) - output = client.containers.top(container, ps) + if parsed_args.pid: + # List container single ps id top result + output = client.containers.top(parsed_args.container, + ' '.join(parsed_args.pid)) + else: + # List container all processes top result + output = client.containers.top(parsed_args.container) + for titles in output['Titles']: print("%-20s") % titles, if output['Processes']: diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index aeb0b0d2..539441c6 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -737,13 +737,19 @@ def do_attach(cs, args): @utils.arg('container', metavar='', help='ID or name of the container to display processes.') -@utils.arg('ps_args', - metavar='', - nargs=argparse.REMAINDER, - help='The args of the ps command.') +@utils.arg('--pid', + metavar='', + action='append', default=[], + help='The args of the ps id.') def do_top(cs, args): """Display the running processes inside the container.""" - output = cs.containers.top(args.container, ' '.join(args.ps_args)) + + if args.pid: + # List container single ps id top result + output = cs.containers.top(args.container, ' '.join(args.pid)) + else: + # List container all processes top result + output = cs.containers.top(args.container) for titles in output['Titles']: print("%-20s") % titles, for process in output['Processes']: