mirror of https://github.com/apache/cloudstack.git
New config key "allow.import.volume.with.backing.file" to skip volume backing (#12809)
* Added support for skipping volume backing when importing unmanaged volumes and VMs. This allows users to import volumes and VMs without creating a backing volume, which can be useful in certain scenarios where the backing volume is not needed or desired. * cleanup conflicting key * move configkey into VolumeImportUnmanageService --------- Co-authored-by: rajujith <rajujith@gmail.com>
This commit is contained in:
parent
09ee0927e9
commit
e93ae1a4f4
|
|
@ -25,11 +25,13 @@ import org.apache.cloudstack.api.command.admin.volume.ImportVolumeCmd;
|
|||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeForImportResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.Configurable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public interface VolumeImportUnmanageService extends PluggableService {
|
||||
public interface VolumeImportUnmanageService extends PluggableService, Configurable {
|
||||
|
||||
List<Hypervisor.HypervisorType> SUPPORTED_HYPERVISORS =
|
||||
Arrays.asList(Hypervisor.HypervisorType.KVM, Hypervisor.HypervisorType.VMware);
|
||||
|
|
@ -37,6 +39,15 @@ public interface VolumeImportUnmanageService extends PluggableService {
|
|||
List<Storage.StoragePoolType> SUPPORTED_STORAGE_POOL_TYPES_FOR_KVM = Arrays.asList(Storage.StoragePoolType.NetworkFilesystem,
|
||||
Storage.StoragePoolType.Filesystem, Storage.StoragePoolType.RBD);
|
||||
|
||||
ConfigKey<Boolean> AllowImportVolumeWithBackingFile = new ConfigKey<>(Boolean.class,
|
||||
"allow.import.volume.with.backing.file",
|
||||
"Advanced",
|
||||
"false",
|
||||
"If enabled, allows QCOW2 volumes with backing files to be imported or unmanaged",
|
||||
true,
|
||||
ConfigKey.Scope.Global,
|
||||
null);
|
||||
|
||||
ListResponse<VolumeForImportResponse> listVolumesForImport(ListVolumesForImportCmd cmd);
|
||||
|
||||
VolumeResponse importVolume(ImportVolumeCmd cmd);
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ import org.apache.cloudstack.api.response.VolumeForImportResponse;
|
|||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
|
|
@ -394,7 +395,7 @@ public class VolumeImportUnmanageManagerImpl implements VolumeImportUnmanageServ
|
|||
Map<VolumeOnStorageTO.Detail, String> volumeDetails = volume.getDetails();
|
||||
if (volumeDetails != null && volumeDetails.containsKey(VolumeOnStorageTO.Detail.BACKING_FILE)) {
|
||||
String backingFile = volumeDetails.get(VolumeOnStorageTO.Detail.BACKING_FILE);
|
||||
if (StringUtils.isNotBlank(backingFile)) {
|
||||
if (StringUtils.isNotBlank(backingFile) && !AllowImportVolumeWithBackingFile.value()) {
|
||||
logFailureAndThrowException("Volume with backing file cannot be imported or unmanaged.");
|
||||
}
|
||||
}
|
||||
|
|
@ -513,4 +514,16 @@ public class VolumeImportUnmanageManagerImpl implements VolumeImportUnmanageServ
|
|||
volume.setRemoved(new Date());
|
||||
volumeDao.update(volume.getId(), volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigComponentName() {
|
||||
return VolumeImportUnmanageManagerImpl.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigKey<?>[] getConfigKeys() {
|
||||
return new ConfigKey<?>[]{
|
||||
AllowImportVolumeWithBackingFile
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import static org.apache.cloudstack.api.ApiConstants.MAX_IOPS;
|
||||
import static org.apache.cloudstack.api.ApiConstants.MIN_IOPS;
|
||||
import static org.apache.cloudstack.storage.volume.VolumeImportUnmanageService.AllowImportVolumeWithBackingFile;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.CloningInstance;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.Completed;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.ConvertingInstance;
|
||||
|
|
@ -2908,7 +2909,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
|||
}
|
||||
if (volumeDetails.containsKey(VolumeOnStorageTO.Detail.BACKING_FILE)) {
|
||||
String backingFile = volumeDetails.get(VolumeOnStorageTO.Detail.BACKING_FILE);
|
||||
if (StringUtils.isNotBlank(backingFile)) {
|
||||
if (StringUtils.isNotBlank(backingFile) && !AllowImportVolumeWithBackingFile.value()) {
|
||||
logFailureAndThrowException("Volume with backing file cannot be imported or unmanaged.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue