diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-11-20 14:04:00 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-11-23 10:43:23 -0500 |
commit | cb8ad7b2923376c3640bfa1f6aaa0b30e6d5f96d (patch) | |
tree | a27f11884839cf801343393faf923ccf8832f422 | |
parent | d2639f7c217f9cc727161ed3608fe044fdde05ab (diff) | |
download | sos-cb8ad7b2923376c3640bfa1f6aaa0b30e6d5f96d.tar.gz |
[Plugin] Add method to get all containers matching a regex
Adds a new method, `Plugin.get_all_containers_by_regex()`, that will
return all known containers on the system with a name matching a
provided regex string. Optionally, this method may also return
terminated containers in addition to those that are active and running.
Closes: #2176
Resolves: #2319
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/report/plugins/__init__.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py index 6eeef5c1..39086584 100644 --- a/sos/report/plugins/__init__.py +++ b/sos/report/plugins/__init__.py @@ -2130,6 +2130,24 @@ class Plugin(object): return con is not None return False + def get_all_containers_by_regex(self, regex, get_all=False): + """Get a list of all container names and ID matching a regex + + :param regex: The regular expression to match + :type regex: ``str`` + + :param get_all: Return all containers found, even terminated ones + :type get_all: ``bool`` + + :returns: All container IDs and names matching ``regex`` + :rtype: ``list`` of ``tuples`` as (id, name) + """ + _runtime = self._get_container_runtime() + if _runtime is not None: + _containers = _runtime.get_containers(get_all=get_all) + return [c for c in _containers if re.match(regex, c[1])] + return [] + def get_container_by_name(self, name): """Get the container ID for a specific container |