Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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) {
Expand Down Expand Up @@ -503,6 +504,10 @@ public void setMetadata(VirtualMachineMetadataTO metadata) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class UnmanageInstanceCommand extends Command {
boolean executeInSequence = false;
VirtualMachineTO vm;
boolean isConfigDriveAttached;
boolean isLibvirtMetadataCleanUpEnabled;

@Override
public boolean executeInSequence() {
Expand Down Expand Up @@ -58,4 +59,10 @@ public boolean isConfigDriveAttached() {
public void setConfigDriveAttached(boolean configDriveAttached) {
isConfigDriveAttached = configDriveAttached;
}

public boolean isLibvirtMetadataCleanupEnabled() {return isLibvirtMetadataCleanUpEnabled;}

public void setLibvirtMetadataCleanup(boolean libvirtMetadataCleanUp) {
isLibvirtMetadataCleanUpEnabled = libvirtMetadataCleanUp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,8 @@ Long persistDomainForKVM(VMInstanceVO vm, Long paramHostId) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3014,7 +3014,8 @@ private void configureVM(VirtualMachineTO vmTO, LibvirtVMDef vm, Map<String, Str
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3037,7 +3037,8 @@ public ConfigKey<?>[] getConfigKeys() {
ThreadsOnMSToImportVMwareVMFiles,
ThreadsOnKVMHostToImportVMwareVMFiles,
ConvertVmwareInstanceToKvmExtraParamsAllowed,
ConvertVmwareInstanceToKvmExtraParamsAllowedList
ConvertVmwareInstanceToKvmExtraParamsAllowedList,
VmUnmanageLibvirtMetadataCleanup
};
}
}
Loading