diff options
| author | Simon Rettberg | 2025-03-27 14:51:03 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-03-27 14:51:03 +0100 |
| commit | 48ca1fc335fbe5bd886b2f86f63ddef546f17029 (patch) | |
| tree | 1af9908e27fbc8bf0547b492f3a061695f735026 | |
| parent | [qemu] Honor SLX_PASSTHROUGH_USB_ID for USB autoconnect on startup (diff) | |
| download | mltk-48ca1fc335fbe5bd886b2f86f63ddef546f17029.tar.gz mltk-48ca1fc335fbe5bd886b2f86f63ddef546f17029.tar.xz mltk-48ca1fc335fbe5bd886b2f86f63ddef546f17029.zip | |
[qemu] Honor existing libvirt uuid, make system-uuid if applicable
| -rw-r--r-- | core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericUuid.java | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericUuid.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericUuid.java index 43fb6412..94536b16 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericUuid.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericUuid.java @@ -1,7 +1,11 @@ package org.openslx.runvirt.plugin.qemu.configuration; +import java.util.Iterator; +import java.util.UUID; + import org.openslx.libvirt.domain.Domain; import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.util.Util; import org.openslx.virtualization.configuration.transformation.TransformationException; import org.openslx.virtualization.configuration.transformation.TransformationGeneric; @@ -37,8 +41,6 @@ public class TransformationGenericUuid extends TransformationGeneric<Domain, Com { if ( config == null || args == null ) { throw new TransformationException( "Virtualization configuration or input arguments are missing!" ); - } else if ( args.getVmUuid() == null || args.getVmUuid().isEmpty() ) { - throw new TransformationException( "UUID is not specified!" ); } } @@ -48,6 +50,34 @@ public class TransformationGenericUuid extends TransformationGeneric<Domain, Com // validate configuration and input arguments this.validateInputs( config, args ); - config.setUuid( args.getVmUuid() ); + // Get UUID which the user (most likely) uploaded the VM with + String originalUuid = config.getUuid(); + + // Check if there is a custom system UUID set and if not, make the original + // libvirt uuid the system UUID, as this is what libvirt does by default + // This is qemu specific but won't do anything for other hypervisors + String systemUuid = null; + for ( Iterator<String> it = config.getQemuCmdlnArguments().iterator(); it.hasNext(); ) { + String arg = it.next(); + if ( "-uuid".equals( arg ) ) { + if ( it.hasNext() ) { + systemUuid = it.next(); + } else { + it.remove(); + } + } + } + if ( Util.isEmptyString( systemUuid ) ) { + // No system-uuid on command line, use old libvirt uuid + config.addQemuCmdlnArgument( "-uuid" ); + config.addQemuCmdlnArgument( originalUuid ); + } + + // Finally, apply new uuid, either from our cmdline, or random + if ( !Util.isEmptyString( args.getVmUuid() ) ) { + config.setUuid( args.getVmUuid() ); + } else { + config.setUuid( UUID.randomUUID().toString() ); + } } } |
