From 9559cd052841714d52695b8ec7fd3f24bdb40460 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Mon, 30 Jun 2025 08:17:31 +0200 Subject: [PATCH] stages/ovf: write virtualbox Expand the written XML to include information as used by VirtualBox. This should not affect any other use cases of the OVF document that is generated and is purely extra information consumed by VirtualBox. Signed-off-by: Simon de Vlieger --- stages/org.osbuild.ovf | 55 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/stages/org.osbuild.ovf b/stages/org.osbuild.ovf index 06256bbd..25942533 100755 --- a/stages/org.osbuild.ovf +++ b/stages/org.osbuild.ovf @@ -1,20 +1,22 @@ #!/usr/bin/python3 import json import os +import random import subprocess import sys +import uuid import osbuild.api from osbuild.util import checksum OVF_TEMPLATE = """ - + Virtual disk information - + The list of logical networks @@ -84,11 +86,56 @@ OVF_TEMPLATE = """ + + Complete VirtualBox machine configuration in VirtualBox format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ +def vbox_mac_address(): + # https://github.com/mirror/vbox/blob/b9657cd5351cf17432b664009cc25bb480dc64c1/src/VBox/Main/src-server/HostImpl.cpp#L3267 + # VirtualBox-6.1.12 src/VBox/NetworkServices/Dhcpd/Config.cpp line 276 + mac_address = "080027" + for _ in range(0, 3): + mac_address += "".join(random.sample("0123456789abcdef", 2)) + return mac_address + + def virtual_size(vmdk): cmd = ["qemu-img", "info", "--output=json", vmdk] res = subprocess.run( @@ -107,6 +154,10 @@ def write_template(vmdk): ovf_data = OVF_TEMPLATE.format( vmdk_size=os.stat(vmdk).st_size, vmdk_capacity=virtual_size(vmdk), + vbox_machine_uuid=str(uuid.uuid4()), + vbox_disk_uuid=str(uuid.uuid4()), + vbox_os_type="ArchLinux_64", + vbox_mac_address=vbox_mac_address(), image_name=basename, )