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:
parent
46ee18e0cf
commit
3fb603bc95
@ -867,17 +867,22 @@ class TopContainer(command.Command):
|
|||||||
metavar='<container>',
|
metavar='<container>',
|
||||||
help='ID or name of the container to display processes.')
|
help='ID or name of the container to display processes.')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'ps_args',
|
'--pid',
|
||||||
metavar='<ps_args>',
|
metavar='<pid>',
|
||||||
nargs=argparse.REMAINDER,
|
action='append', default=[],
|
||||||
help='The args of the ps command.')
|
help='The args of the ps id.')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
client = _get_client(self, parsed_args)
|
client = _get_client(self, parsed_args)
|
||||||
container = parsed_args.container
|
if parsed_args.pid:
|
||||||
ps = ' '.join(parsed_args.ps_args)
|
# List container single ps id top result
|
||||||
output = client.containers.top(container, ps)
|
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']:
|
for titles in output['Titles']:
|
||||||
print("%-20s") % titles,
|
print("%-20s") % titles,
|
||||||
if output['Processes']:
|
if output['Processes']:
|
||||||
|
@ -737,13 +737,19 @@ def do_attach(cs, args):
|
|||||||
@utils.arg('container',
|
@utils.arg('container',
|
||||||
metavar='<container>',
|
metavar='<container>',
|
||||||
help='ID or name of the container to display processes.')
|
help='ID or name of the container to display processes.')
|
||||||
@utils.arg('ps_args',
|
@utils.arg('--pid',
|
||||||
metavar='<ps_args>',
|
metavar='<pid>',
|
||||||
nargs=argparse.REMAINDER,
|
action='append', default=[],
|
||||||
help='The args of the ps command.')
|
help='The args of the ps id.')
|
||||||
def do_top(cs, args):
|
def do_top(cs, args):
|
||||||
"""Display the running processes inside the container."""
|
"""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']:
|
for titles in output['Titles']:
|
||||||
print("%-20s") % titles,
|
print("%-20s") % titles,
|
||||||
for process in output['Processes']:
|
for process in output['Processes']:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user