diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2021-12-03 13:37:09 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2021-12-06 09:52:29 -0500 |
commit | 9d4b5af39d76ac99afa40d004fe9888633218356 (patch) | |
tree | 23527ebc09e70f60a72baa04dfa4212251fb3f40 | |
parent | decb5d26c165e664fa879a669f2d80165181f0e1 (diff) | |
download | sos-9d4b5af39d76ac99afa40d004fe9888633218356.tar.gz |
[Plugin] Add container parameter for add_cmd_output()
Adds a new `container` parameter for `Plugin.add_cmd_output()`, which if
set will format all commands passed to that call for execution in the
specified container.
`Plugin.fmt_container_cmd()` is called for this purpose, and has been
modified so that if the given container does not exist, an empty string
is returned instead, thus preventing execution on the host.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/report/plugins/__init__.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py index e180ae17..3ff7c191 100644 --- a/sos/report/plugins/__init__.py +++ b/sos/report/plugins/__init__.py @@ -1707,7 +1707,7 @@ class Plugin(): chroot=True, runat=None, env=None, binary=False, sizelimit=None, pred=None, subdir=None, changes=False, foreground=False, tags=[], - priority=10, cmd_as_tag=False): + priority=10, cmd_as_tag=False, container=None): """Run a program or a list of programs and collect the output Output will be limited to `sizelimit`, collecting the last X amount @@ -1772,6 +1772,10 @@ class Plugin(): :param cmd_as_tag: Should the command string be automatically formatted to a tag? :type cmd_as_tag: ``bool`` + + :param container: Run the specified `cmds` inside a container with this + ID or name + :type container: ``str`` """ if isinstance(cmds, str): cmds = [cmds] @@ -1782,6 +1786,14 @@ class Plugin(): if pred is None: pred = self.get_predicate(cmd=True) for cmd in cmds: + if container: + ocmd = cmd + cmd = self.fmt_container_cmd(container, cmd) + if not cmd: + self._log_debug("Skipping command '%s' as the requested " + "container '%s' does not exist." + % (ocmd, container)) + continue self._add_cmd_output(cmd=cmd, suggest_filename=suggest_filename, root_symlink=root_symlink, timeout=timeout, stderr=stderr, chroot=chroot, runat=runat, @@ -2420,7 +2432,7 @@ class Plugin(): if self.container_exists(container): _runtime = self._get_container_runtime() return _runtime.fmt_container_cmd(container, cmd, quotecmd) - return cmd + return '' def is_module_loaded(self, module_name): """Determine whether specified module is loaded or not |