From ec85bfaa44a3a88bf133e8a0e3ad8f8b5d86b6bb Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Tue, 17 Dec 2019 12:44:07 -0500 Subject: [PATCH] [podman] Update plugin to utilize policy container runtime Updates the plugin to use the new `ContainerRuntime` abstraction provided by the loaded `Policy` rather than shelling out again to get the same data loaded during `Policy` initialization. Resolves: #1873 Signed-off-by: Jake Hunsaker --- sos/plugins/podman.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/sos/plugins/podman.py b/sos/plugins/podman.py index c00a63ee61..10e39b0c77 100644 --- a/sos/plugins/podman.py +++ b/sos/plugins/podman.py @@ -74,24 +74,19 @@ def setup(self): "podman network inspect %s" % net for net in nets ], subdir='networks') - ps_cmd = 'podman ps -q' - if self.get_option('all'): - ps_cmd = "%s -a" % ps_cmd - - fmt = '{{lower .Repository}}:{{lower .Tag}} {{lower .ID}}' - img_cmd = "podman images --format='%s'" % fmt - vol_cmd = 'podman volume ls -q' - - containers = self._get_podman_list(ps_cmd) - images = self._get_podman_list(img_cmd) - volumes = self._get_podman_list(vol_cmd) + containers = [ + c[0] for c in self.get_containers(runtime='podman', + get_all=self.get_option('all')) + ] + images = self.get_container_images(runtime='podman') + volumes = self.get_container_volumes(runtime='podman') for container in containers: self.add_cmd_output("podman inspect %s" % container, subdir='containers') for img in images: - name, img_id = img.strip().split() + name, img_id = img insp = name if 'none' not in name else img_id self.add_cmd_output("podman inspect %s" % insp, subdir='images') @@ -104,14 +99,6 @@ def setup(self): self.add_cmd_output("podman logs -t %s" % con, subdir='containers') - def _get_podman_list(self, cmd): - ret = [] - result = self.exec_cmd(cmd) - if result['status'] == 0: - for ent in result['output'].splitlines(): - ret.append(ent) - return ret - def postproc(self): # Attempts to match key=value pairs inside container inspect output # for potentially sensitive items like env vars that contain passwords.