util/containers: read host config

Add utility function to read the host's container storage config.
This commit is contained in:
Gianluca Zuccarelli 2024-02-09 10:33:52 +00:00 committed by Ondřej Budai
parent 462c498dcf
commit 26aac90eb4
3 changed files with 26 additions and 0 deletions

View file

@ -5,3 +5,6 @@ ignore_missing_imports = True
[mypy-mako.*]
ignore_missing_imports = True
[mypy-tomli.*]
ignore_missing_imports = True

View file

@ -39,6 +39,12 @@ Requires: util-linux
Requires: python3-%{pypi_name} = %{version}-%{release}
Requires: (%{name}-selinux if selinux-policy-%{selinuxtype})
# This is required for `osbuild`, for RHEL-10 and above
# the stdlib toml package can be used instead
%if 0%{?rhel} < 10
Requires: python3-tomli
%endif
# Turn off dependency generators for runners. The reason is that runners are
# tailored to the platform, e.g. on RHEL they are using platform-python. We
# don't want to pick up those dependencies on other platform.

View file

@ -128,3 +128,20 @@ def container_source(image):
image_source = f"{container_format}:{tmp_source}"
yield image_name, image_source
def get_host_storage(storage_conf=None):
"""
Read the host storage configuration.
"""
# pylint: disable=import-outside-toplevel
# importing this at the top level will break the buildroot
try:
import tomllib as toml
except ImportError:
import tomli as toml
if not storage_conf:
with open("/etc/containers/storage.conf", "rb") as conf_file:
storage_conf = toml.load(conf_file)
return storage_conf