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 <cybing4@gmail.com>
This commit is contained in:
Yuanbin.Chen 2018-07-18 15:45:50 +08:00
parent 46ee18e0cf
commit 3fb603bc95
2 changed files with 23 additions and 12 deletions

View File

@ -867,17 +867,22 @@ class TopContainer(command.Command):
metavar='<container>',
help='ID or name of the container to display processes.')
parser.add_argument(
'ps_args',
metavar='<ps_args>',
nargs=argparse.REMAINDER,
help='The args of the ps command.')
'--pid',
metavar='<pid>',
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']:

View File

@ -737,13 +737,19 @@ def do_attach(cs, args):
@utils.arg('container',
metavar='<container>',
help='ID or name of the container to display processes.')
@utils.arg('ps_args',
metavar='<ps_args>',
nargs=argparse.REMAINDER,
help='The args of the ps command.')
@utils.arg('--pid',
metavar='<pid>',
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']: