This commit is contained in:
Dattu 2026-07-04 14:36:10 +00:00 committed by GitHub
commit e24cfcf2f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 2 deletions

View File

@ -91,6 +91,7 @@ public class VirtualMachineTO {
private String metadataManufacturer;
private String metadataProductName;
private VirtualMachineMetadataTO metadata;
private boolean excludeMetadata;
public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader,
String os, boolean enableHA, boolean limitCpuUse, String vncPassword) {
@ -509,6 +510,10 @@ public class VirtualMachineTO {
this.metadata = metadata;
}
public boolean isExcludeMetadata() { return excludeMetadata; }
public void setExcludeMetadata(boolean excludeMetadata) { this.excludeMetadata = excludeMetadata;}
@Override
public String toString() {
return String.format("VM {id: \"%s\", name: \"%s\", uuid: \"%s\", type: \"%s\"}", id, name, uuid, type);

View File

@ -71,6 +71,14 @@ public interface UnmanagedVMsManager extends VmImportService, UnmanageVMService,
true,
ConfigKey.Scope.Global,
null);
ConfigKey<Boolean> VmUnmanageLibvirtMetadataCleanup = new ConfigKey<>(Boolean.class,
"vm.unmanage.libvirt.metadata.cleanup",
"Advanced",
"true",
"Specifies whether metadata should be cleaned up when a VM is unmanaged, applicable to the KVM hypervisor.",
true,
ConfigKey.Scope.Global,
null);
static boolean isSupported(Hypervisor.HypervisorType hypervisorType) {
return hypervisorType == VMware || hypervisorType == KVM;

View File

@ -28,6 +28,7 @@ public class UnmanageInstanceCommand extends Command {
boolean executeInSequence = false;
VirtualMachineTO vm;
boolean isConfigDriveAttached;
boolean isLibvirtMetadataCleanUpEnabled;
@Override
public boolean executeInSequence() {
@ -58,4 +59,10 @@ public class UnmanageInstanceCommand extends Command {
public void setConfigDriveAttached(boolean configDriveAttached) {
isConfigDriveAttached = configDriveAttached;
}
public boolean isLibvirtMetadataCleanupEnabled() {return isLibvirtMetadataCleanUpEnabled;}
public void setLibvirtMetadataCleanup(boolean libvirtMetadataCleanUp) {
isLibvirtMetadataCleanUpEnabled = libvirtMetadataCleanUp;
}
}

View File

@ -2147,6 +2147,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
unmanageInstanceCommand = new UnmanageInstanceCommand(vmName);
unmanageInstanceCommand.setConfigDriveAttached(vmInstanceDetailsDao.findDetail(vm.getId(), VmDetailConstants.CONFIG_DRIVE_LOCATION) != null);
}
boolean isEnabled = UnmanagedVMsManager.VmUnmanageLibvirtMetadataCleanup.value();
unmanageInstanceCommand.setLibvirtMetadataCleanup(isEnabled);
logger.debug("Selected host ID: {} to persist domain XML for Instance: {}.", agentHostId, vmName);
try {

View File

@ -3160,7 +3160,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
vm.addComp(createDevicesDef(vmTO, guest, vcpus, isUefiEnabled));
MetadataDef metaDef;
if ((metaDef = createMetadataDef(vmTO)) != null) {
boolean excludeMetadata = vmTO.isExcludeMetadata();
if (!excludeMetadata && (metaDef = createMetadataDef(vmTO)) != null) {
vm.addComp(metaDef);
}

View File

@ -67,6 +67,9 @@ public final class LibvirtUnmanageInstanceCommandWrapper extends CommandWrapper<
public Answer execute(final UnmanageInstanceCommand command, final LibvirtComputingResource libvirtComputingResource) {
String instanceName = command.getInstanceName();
VirtualMachineTO vmSpec = command.getVm();
if (command.isLibvirtMetadataCleanupEnabled()) {
vmSpec.setExcludeMetadata(true);
}
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
logger.debug("Attempting to unmanage KVM instance: {}", instanceName);
Domain dom = null;

View File

@ -3177,7 +3177,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
ThreadsOnMSToImportVMwareVMFiles,
ThreadsOnKVMHostToImportVMwareVMFiles,
ConvertVmwareInstanceToKvmExtraParamsAllowed,
ConvertVmwareInstanceToKvmExtraParamsAllowedList
ConvertVmwareInstanceToKvmExtraParamsAllowedList,
VmUnmanageLibvirtMetadataCleanup
};
}
}