podman_info
podman_info
¶
Podman environment detection.
Parses podman info -f json output and containers.conf to detect
podman capabilities, version, and hooks directory configuration.
This module is stateless — callers cache the result.
PodmanInfo(version, rootless_network_cmd, pasta_executable, slirp4netns_executable)
dataclass
¶
Parsed podman environment information.
Constructed from podman info -f json output. Stateless — the
caller manages caching.
hooks_dir_persists
property
¶
Return True if --hooks-dir survives container restart.
Currently always False — podman drops per-container hooks-dir on stop/start even on 5.8.0 (issues #121, #122). The version gate will be lowered when podman fixes this upstream.
network_mode
property
¶
Determine the rootless network mode.
Uses rootlessNetworkCmd when available (podman 5+).
When absent (podman 4.x), defaults to slirp4netns if its
executable is available — podman 4.x defaults to slirp4netns.
parse_podman_info(json_str)
¶
Parse podman info -f json output into a :class:PodmanInfo.
Returns a zero-version fallback on invalid input.
Source code in src/terok_shield/common/podman_info.py
find_hooks_dirs()
¶
Find hooks directories podman would check.
Reads containers.conf (user config overrides system config).
Falls back to well-known system defaults if nothing is configured.
Returns directories in precedence order (last wins for podman).
Source code in src/terok_shield/common/podman_info.py
has_global_hooks(hooks_dirs=None)
¶
Check if terok-shield hooks are installed in any global hooks dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hooks_dirs
|
list[Path] | None
|
Directories to check (default: auto-detect via
:func: |
None
|
Source code in src/terok_shield/common/podman_info.py
parse_resolv_conf(text)
¶
Extract the first nameserver address from resolv.conf content.
Returns an empty string if no valid nameserver line is found.
Source code in src/terok_shield/common/podman_info.py
parse_proc_net_route(text)
¶
Extract the default gateway IP from /proc/{pid}/net/route content.
The gateway field is a 32-bit hex integer in host byte order. Returns an empty string if no default route is found.
Source code in src/terok_shield/common/podman_info.py
system_hooks_dir()
¶
Return the best system-level hooks directory.
Prefers existing directories; falls back to /etc/containers/oci/hooks.d.
Source code in src/terok_shield/common/podman_info.py
global_hooks_hint()
¶
Short hint telling the user to run terok-shield setup.
Source code in src/terok_shield/common/podman_info.py
ensure_containers_conf_hooks_dir(hooks_dir)
¶
Ensure ~/.config/containers/containers.conf includes hooks_dir.
Creates the file if absent. Inserts hooks_dir into the existing
[engine] section, or appends a new section if none exists.
Warns (does not fail) if hooks_dir is already set differently.
Uses line-based text manipulation to preserve comments and formatting.