From 77c72b415feccd828fd7bc13caebf9841afc40c2 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 3 Sep 2018 17:11:06 +0100 Subject: [PATCH] [docker] combine docker 'inspect' and 'logs' loops We're iterating over all the containers: might as well only do it one time. Related: #1406, #1407 Signed-off-by: Bryn M. Reeves --- sos/plugins/docker.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sos/plugins/docker.py b/sos/plugins/docker.py index a44264a4..5b2acff5 100644 --- a/sos/plugins/docker.py +++ b/sos/plugins/docker.py @@ -80,9 +80,7 @@ class Docker(Plugin): if insp: for container in insp: self.add_cmd_output("docker inspect %s" % container) - - if self.get_option('logs'): - for container in insp: + if self.get_option('logs'): self.add_cmd_output("docker logs -t %s" % container) -- 2.17.2 From e3cfb1428592390166237e715471bb62d9bd9db6 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 29 Aug 2018 06:50:10 -0400 Subject: [PATCH] [podman] Add support for gathering information on podman containers Resolves: #1407. Signed-off-by: Daniel J Walsh Signed-off-by: Bryn M. Reeves --- sos/plugins/podman.py | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sos/plugins/podman.py diff --git a/sos/plugins/podman.py b/sos/plugins/podman.py new file mode 100644 index 00000000..c43246fc --- /dev/null +++ b/sos/plugins/podman.py @@ -0,0 +1,79 @@ +# Copyright (C) 2018 Red Hat, Inc. Daniel Walsh + +# This file is part of the sos project: https://github.com/sosreport/sos +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# version 2 of the GNU General Public License. +# +# See the LICENSE file in the source distribution for further information. + +from sos.plugins import Plugin, RedHatPlugin, UbuntuPlugin + + +class Podman(Plugin): + + """Podman containers + """ + + plugin_name = 'podman' + profiles = ('container',) + packages = ('podman') + + option_list = [ + ("all", "enable capture for all containers, even containers " + "that have terminated", 'fast', False), + ("logs", "capture logs for running containers", + 'fast', False), + ("size", "capture image sizes for podman ps", 'slow', False) + ] + + def setup(self): + self.add_copy_spec([ + "/etc/containers/registries.conf", + "/etc/containers/storage.conf", + "/etc/containers/mounts.conf", + "/etc/containers/policy.json", + ]) + + subcmds = [ + 'info', + 'images', + 'pod ps', + 'pod ps -a', + 'ps', + 'ps -a', + 'stats --no-stream', + 'version', + ] + + self.add_cmd_output(["podman %s" % s for s in subcmds]) + + # separately grab ps -s as this can take a *very* long time + if self.get_option('size'): + self.add_cmd_output('podman ps -as') + + self.add_journal(units="podman") + self.add_cmd_output("ls -alhR /etc/cni") + + ps_cmd = 'podman ps -q' + if self.get_option('all'): + ps_cmd = "%s -a" % ps_cmd + + img_cmd = 'podman images -q' + insp = set() + + for icmd in [ps_cmd, img_cmd]: + result = self.get_command_output(icmd) + if result['status'] == 0: + for con in result['output'].splitlines(): + insp.add(con) + + if insp: + for container in insp: + self.add_cmd_output("podman inspect %s" % container) + if self.get_option('logs'): + self.add_cmd_output("podman logs -t %s" % container) + + +# vim: set et ts=4 sw=4 : -- 2.17.2 From 1401c7153dda9bd0558035ba0692cf05a93ca419 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Tue, 6 Nov 2018 08:13:52 +0100 Subject: [PATCH] [podman] allow the plugin for RedHatPlugin and UbuntuPlugin Until Podman inherits RedHatPlugin and/or UbuntuPlugin, the plugin can not be executed on underlying distros. Further, remove one redundant test as "for container in insp" will work properly also for empty "insp". Resolves: #1473 Signed-off-by: Pavel Moravec --- sos/plugins/podman.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sos/plugins/podman.py b/sos/plugins/podman.py index c43246fc..72e22558 100644 --- a/sos/plugins/podman.py +++ b/sos/plugins/podman.py @@ -11,7 +11,7 @@ from sos.plugins import Plugin, RedHatPlugin, UbuntuPlugin -class Podman(Plugin): +class Podman(Plugin, RedHatPlugin, UbuntuPlugin): """Podman containers """ @@ -69,11 +69,10 @@ class Podman(Plugin): for con in result['output'].splitlines(): insp.add(con) - if insp: - for container in insp: - self.add_cmd_output("podman inspect %s" % container) - if self.get_option('logs'): - self.add_cmd_output("podman logs -t %s" % container) + for container in insp: + self.add_cmd_output("podman inspect %s" % container) + if self.get_option('logs'): + self.add_cmd_output("podman logs -t %s" % container) # vim: set et ts=4 sw=4 : -- 2.17.2