import pathlib import shutil import subprocess import tempfile def create_os_disk(paths): with tempfile.TemporaryDirectory(dir=paths.target_path.parent) as temporary_directory: temporary_path = pathlib.Path(temporary_directory) / 'disk.qcow2' subprocess.run( args=[ 'qemu-img', 'create', '-f', 'qcow2', '-b', paths.template_path, '-F', 'qcow2', temporary_path ], check=True, timeout=10 ) temporary_path.replace(paths.target_path) def create_nvram_disk(paths): with tempfile.TemporaryDirectory(dir=paths.nvram_target_path.parent) as temporary_directory: temporary_path = pathlib.Path(temporary_directory) / 'NVRAM.img' shutil.copyfile(paths.nvram_path, temporary_path) temporary_path.replace(paths.nvram_target_path)