debian-forge/osbuild/util/host.py
Achilleas Koutsou 07a597481b util: move get_host_storage() to a separate module
Add a new util module called host which is used for functions that are
meant for interactions with the host.  These functions should not be
used in stages.

The containers.get_host_storage() function is renamed to
host.get_container_storage() for clarity, since it is no longer
namespaced under containers.
2024-08-21 19:26:31 +02:00

20 lines
637 B
Python

"""
Utility functions that only run on the host (osbuild internals or host modules like sources).
These should not be used by stages or code that runs in the build root.
"""
from osbuild.util import toml
def get_container_storage():
"""
Read the host storage configuration.
"""
config_paths = ("/etc/containers/storage.conf", "/usr/share/containers/storage.conf")
for conf_path in config_paths:
try:
return toml.load_from_file(conf_path)
except FileNotFoundError:
pass
raise FileNotFoundError(f"could not find container storage configuration in any of {config_paths}")