podman_info
podman_info
¶
Podman environment detection.
Grouped into three submodules so each concern stands on its own:
info— version + capability parsing.hooks_dir— global hook directory discovery viacontainers.conf.network— slirp4netns CIDR/gateway andresolv.confparsing.
Public names are re-exported here for convenience; new code is welcome to import from the specific submodule when intent is clearer.
HOOK_JSON_FILENAME = 'terok-shield-createRuntime.json'
module-attribute
¶
HOOKS_DIR_PERSIST_VERSION = (99, 0, 0)
module-attribute
¶
__all__ = ['HOOKS_DIR_PERSIST_VERSION', 'HOOK_JSON_FILENAME', 'PodmanInfo', 'find_hooks_dirs', 'global_hooks_hint', 'has_global_hooks', 'parse_podman_info', 'parse_resolv_conf', 'parse_slirp4netns_cidr', 'slirp4netns_gateway']
module-attribute
¶
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.
version
instance-attribute
¶
rootless_network_cmd
instance-attribute
¶
pasta_executable
instance-attribute
¶
slirp4netns_executable
instance-attribute
¶
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.
find_hooks_dirs()
¶
Find hooks directories podman would check.
Reads containers.conf (user config overrides system config).
Returns the configured directories in precedence order (last wins
for podman). Empty when no hooks_dir entry is configured —
terok always patches containers.conf at setup time, so an
empty result implies setup has not run.
Source code in src/terok_shield/podman_info/hooks_dir.py
global_hooks_hint()
¶
Short hint telling the user to run terok-shield setup.
Source code in src/terok_shield/podman_info/hooks_dir.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
|
None
|
Source code in src/terok_shield/podman_info/hooks_dir.py
parse_podman_info(json_str)
¶
Parse podman info -f json output into a PodmanInfo.
Returns a zero-version fallback on invalid or partially-malformed input —
every nested section is coerced through an isinstance(..., dict)
guard so a scalar/list where a table is expected can never produce
an AttributeError.
Source code in src/terok_shield/podman_info/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/podman_info/network.py
parse_slirp4netns_cidr()
¶
Read the slirp4netns CIDR from containers.conf, or return the default.
User config (XDG) is checked first in rootless mode, then system paths.
When running as root, user config is skipped to prevent untrusted
XDG_CONFIG_HOME from influencing firewall rules.
Source code in src/terok_shield/podman_info/network.py
slirp4netns_gateway(cidr=None)
¶
Compute the slirp4netns gateway address (CIDR base + 2).
Reads containers.conf for a cidr= override when cidr is None.
Falls back to the default CIDR on malformed input.