Skip to content

Commit

Permalink
[podman] Update plugin to utilize policy container runtime
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
TurboTurtle committed Dec 17, 2019
1 parent 78fb45a commit 9379f79
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions sos/plugins/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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.
Expand Down

0 comments on commit 9379f79

Please sign in to comment.