docker_utils
Docker host helpers: client access, self-inspection, GPUs, and images.
Everything that talks to the Docker daemon outside of a launch goes through this module so the rest of the server never creates its own client.
attributelogger= logging.getLogger(__name__)funcget_docker_client() -> docker.DockerClientReturn the shared Docker client, creating it on first use.
Returns
docker.DockerClientA DockerClient connected from the environment.
funclocal_image(client, image) -> strReturn the reference this node runs an image by, pulling it through its mirror when it is not here.
paramclientdocker.DockerClientparamimagestrReturns
strfuncprune_dangling_images() -> NoneRemove dangling images left behind by pulls.
Returns
Nonefunc_own_container(client) -> Any | NoneReturn the server's own container, or None on a host or when Docker holds no container of this process.
The server's own container is the one whose host name is this process's:
the container Docker knows by that name or id, else the one named
sealskin exactly. A container that merely carries the name is another
server's, whose mounts and sessions are not this one's to use.
paramclientdocker.DockerClientReturns
typing.Any | Nonefuncown_container_name() -> strReturn the name of the server's own container, or "" on a host or when Docker does not answer.
A container's short id is its default host name and changes each time it is recreated, while its name stays, so the cluster identity of a node in Docker is taken from the name.
Returns
strfuncinspect_self_container() -> NoneDiscover mount mappings, ports, and network of the server's own container.
Populates state.path_prefix_map, state.discovered_api_port,
state.discovered_session_port, state.discovered_network, and
state.instance_name (the container's name, else the host name). The
container is the one _own_container finds.
Returns
Nonefunctranslate_path_to_host(internal_path) -> strMap a path inside the server container to the equivalent host path.
paraminternal_pathstrAbsolute path as seen by the server process.
Returns
strThe host path when a mount prefix matches, otherwise the input.
funcread_cpu_model() -> NoneRead the CPU model name from /proc/cpuinfo into state.cpu_model.
Returns
Nonefuncget_system_stats() -> dict[str, Any]Return CPU model and storage usage, cached for one minute.
Returns
dictDictionary with cpu_model, disk_total, and disk_used.
funcscan_render_nodes() -> list[dict[str, Any]]Return the render nodes under /sys/class/drm as GPU descriptors.
NVIDIA nodes are typed nvidia and numbered in order for the runtime's
device request; every other driver is dri3.
Returns
list[dict[str, typing.Any]]funcget_and_cache_image_metadata(image_name, force_refresh=False) -> NoneRecord the local digest of an image in state.image_metadata.
paramimage_namestrImage reference such as ghcr.io/org/app:latest.
paramforce_refreshbool= FalseRe-query Docker even when a digest is cached.
Returns
Nonefuncpull_and_cache_image(image_name) -> NonePull an image in the background and refresh its cached digest.
paramimage_namestrImage reference to pull.
Returns
None