aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2019-12-03 13:23:45 -0500
committerJake Hunsaker <jhunsake@redhat.com>2020-04-07 16:43:35 -0400
commitb5b82007576f15f6c07f5bf2b8e10587b2fa1d20 (patch)
tree22ddfc16d879f626ebd3cde801f01668f2c3857c
parent3dd3b813d5c81090ba5d0822e9a48161b052fb21 (diff)
downloadsos-b5b82007576f15f6c07f5bf2b8e10587b2fa1d20.tar.gz
[docker] 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. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/plugins/docker.py27
1 files changed, 7 insertions, 20 deletions
diff --git a/sos/plugins/docker.py b/sos/plugins/docker.py
index 7424fbba..74843ab2 100644
--- a/sos/plugins/docker.py
+++ b/sos/plugins/docker.py
@@ -73,17 +73,12 @@ class Docker(Plugin):
for net in n:
self.add_cmd_output("docker network inspect %s" % net)
- ps_cmd = 'docker ps -q'
- if self.get_option('all'):
- ps_cmd = "%s -a" % ps_cmd
-
- fmt = '{{lower .Repository}}:{{lower .Tag}} {{lower .ID}}'
- img_cmd = "docker images --format='%s'" % fmt
- vol_cmd = 'docker volume ls -q'
-
- containers = self._get_docker_list(ps_cmd)
- images = self._get_docker_list(img_cmd)
- volumes = self._get_docker_list(vol_cmd)
+ containers = [
+ c[0] for c in self.get_containers(runtime='docker',
+ get_all=self.get_option('all'))
+ ]
+ images = self.get_container_images(runtime='docker')
+ volumes = self.get_container_volumes(runtime='docker')
for container in containers:
self.add_cmd_output("docker inspect %s" % container,
@@ -93,7 +88,7 @@ class Docker(Plugin):
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("docker inspect %s" % insp, subdir='images')
@@ -101,14 +96,6 @@ class Docker(Plugin):
self.add_cmd_output("docker volume inspect %s" % vol,
subdir='volumes')
- def _get_docker_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.