fester/backend/storage/router.py

40 lines
980 B
Python

from storage.config import load_storage_config
from storage.tmpfs import get_tmpfs_workspace
from storage.btrfs_cas import cas_path, is_btrfs
from storage.qcow2_freeze import freeze_to_qcow2
def prepare_workspace(project_name):
cfg = load_storage_config()
workspace = {
"tmpfs": None,
"cas": None,
"freeze": None,
"mode": cfg
}
# ----------------------------
# ALWAYS: tmpfs
# ----------------------------
workspace["tmpfs"] = get_tmpfs_workspace(cfg, project_name)
# ----------------------------
# OPTIONAL: Btrfs CAS
# ----------------------------
if cfg.get("btrfs"):
workspace["cas"] = cas_path(cfg, project_name)
return workspace
def maybe_freeze_workspace(workdir, project_name):
cfg = load_storage_config()
if not cfg.get("qcow2_freeze"):
return None
output = f"/var/lib/fester/snapshots/{project_name}.qcow2"
return freeze_to_qcow2(workdir, output)