diff --git a/stages/org.osbuild.ovf b/stages/org.osbuild.ovf index 0b5d18e6..e0bcb830 100755 --- a/stages/org.osbuild.ovf +++ b/stages/org.osbuild.ovf @@ -127,12 +127,21 @@ OVF_TEMPLATE = """ """ -def vbox_mac_address(): +def vbox_mac_address(options): + # If we have an explicit mac address we use that. + mac_address = options.get("virtualbox", {}).get("mac_address") + + if mac_address: + return mac_address + + # Otherwise we generate one according to how VirtualBox usually does this: # 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 @@ -158,7 +167,7 @@ def write_template(vmdk, options): vbox_machine_uuid=str(uuid.uuid4()), vbox_disk_uuid=str(uuid.uuid4()), vbox_os_type=options.get("virtualbox", {}).get("os_type", "OtherLinux_64"), - vbox_mac_address=vbox_mac_address(), + vbox_mac_address=vbox_mac_address(options), image_name=basename, ) diff --git a/stages/org.osbuild.ovf.meta.json b/stages/org.osbuild.ovf.meta.json index 71be3916..6799a06f 100644 --- a/stages/org.osbuild.ovf.meta.json +++ b/stages/org.osbuild.ovf.meta.json @@ -38,6 +38,9 @@ "os_type": { "type": "string", "default": "OtherLinux_64" + }, + "mac_address": { + "type": "string" } } } diff --git a/stages/test/test_ovf.py b/stages/test/test_ovf.py index 8e372548..a36f37d2 100644 --- a/stages/test/test_ovf.py +++ b/stages/test/test_ovf.py @@ -43,6 +43,7 @@ def test_schema_validation_ovf(stage_schema, test_data, expected_err): # Replacements ({"vmware": {"os_type": "my-vmware-os-type"}}, ["my-vmware-os-type"],), ({"virtualbox": {"os_type": "my-vbox-os-type"}}, ["my-vbox-os-type"],), + ({"virtualbox": {"mac_address": "my-mac-address"}}, ["my-mac-address"],), ]) def test_ovf_default_template(tmp_path, stage_module, test_opts, expected_substrings): faked_vmdk_path = tmp_path / "some-image.vmdk"