Skip to content

Commit e93ae1a

Browse files
sudo87rajujith
andauthored
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>
1 parent 09ee092 commit e93ae1a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

api/src/main/java/org/apache/cloudstack/storage/volume/VolumeImportUnmanageService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,29 @@
2525
import org.apache.cloudstack.api.response.ListResponse;
2626
import org.apache.cloudstack.api.response.VolumeForImportResponse;
2727
import org.apache.cloudstack.api.response.VolumeResponse;
28+
import org.apache.cloudstack.framework.config.ConfigKey;
29+
import org.apache.cloudstack.framework.config.Configurable;
2830

2931
import java.util.Arrays;
3032
import java.util.List;
3133

32-
public interface VolumeImportUnmanageService extends PluggableService {
34+
public interface VolumeImportUnmanageService extends PluggableService, Configurable {
3335

3436
List<Hypervisor.HypervisorType> SUPPORTED_HYPERVISORS =
3537
Arrays.asList(Hypervisor.HypervisorType.KVM, Hypervisor.HypervisorType.VMware);
3638

3739
List<Storage.StoragePoolType> SUPPORTED_STORAGE_POOL_TYPES_FOR_KVM = Arrays.asList(Storage.StoragePoolType.NetworkFilesystem,
3840
Storage.StoragePoolType.Filesystem, Storage.StoragePoolType.RBD);
3941

42+
ConfigKey<Boolean> AllowImportVolumeWithBackingFile = new ConfigKey<>(Boolean.class,
43+
"allow.import.volume.with.backing.file",
44+
"Advanced",
45+
"false",
46+
"If enabled, allows QCOW2 volumes with backing files to be imported or unmanaged",
47+
true,
48+
ConfigKey.Scope.Global,
49+
null);
50+
4051
ListResponse<VolumeForImportResponse> listVolumesForImport(ListVolumesForImportCmd cmd);
4152

4253
VolumeResponse importVolume(ImportVolumeCmd cmd);

server/src/main/java/org/apache/cloudstack/storage/volume/VolumeImportUnmanageManagerImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import org.apache.cloudstack.api.response.VolumeResponse;
6969
import org.apache.cloudstack.context.CallContext;
7070
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
71+
import org.apache.cloudstack.framework.config.ConfigKey;
7172
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
7273
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
7374
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@@ -394,7 +395,7 @@ protected void checkIfVolumeHasBackingFile(VolumeOnStorageTO volume) {
394395
Map<VolumeOnStorageTO.Detail, String> volumeDetails = volume.getDetails();
395396
if (volumeDetails != null && volumeDetails.containsKey(VolumeOnStorageTO.Detail.BACKING_FILE)) {
396397
String backingFile = volumeDetails.get(VolumeOnStorageTO.Detail.BACKING_FILE);
397-
if (StringUtils.isNotBlank(backingFile)) {
398+
if (StringUtils.isNotBlank(backingFile) && !AllowImportVolumeWithBackingFile.value()) {
398399
logFailureAndThrowException("Volume with backing file cannot be imported or unmanaged.");
399400
}
400401
}
@@ -513,4 +514,16 @@ private void unmanageVolumeFromDatabase(VolumeVO volume) {
513514
volume.setRemoved(new Date());
514515
volumeDao.update(volume.getId(), volume);
515516
}
517+
518+
@Override
519+
public String getConfigComponentName() {
520+
return VolumeImportUnmanageManagerImpl.class.getSimpleName();
521+
}
522+
523+
@Override
524+
public ConfigKey<?>[] getConfigKeys() {
525+
return new ConfigKey<?>[]{
526+
AllowImportVolumeWithBackingFile
527+
};
528+
}
516529
}

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195

196196
import static org.apache.cloudstack.api.ApiConstants.MAX_IOPS;
197197
import static org.apache.cloudstack.api.ApiConstants.MIN_IOPS;
198+
import static org.apache.cloudstack.storage.volume.VolumeImportUnmanageService.AllowImportVolumeWithBackingFile;
198199
import static org.apache.cloudstack.vm.ImportVmTask.Step.CloningInstance;
199200
import static org.apache.cloudstack.vm.ImportVmTask.Step.Completed;
200201
import static org.apache.cloudstack.vm.ImportVmTask.Step.ConvertingInstance;
@@ -2908,7 +2909,7 @@ private void checkVolume(Map<VolumeOnStorageTO.Detail, String> volumeDetails) {
29082909
}
29092910
if (volumeDetails.containsKey(VolumeOnStorageTO.Detail.BACKING_FILE)) {
29102911
String backingFile = volumeDetails.get(VolumeOnStorageTO.Detail.BACKING_FILE);
2911-
if (StringUtils.isNotBlank(backingFile)) {
2912+
if (StringUtils.isNotBlank(backingFile) && !AllowImportVolumeWithBackingFile.value()) {
29122913
logFailureAndThrowException("Volume with backing file cannot be imported or unmanaged.");
29132914
}
29142915
}

0 commit comments

Comments
 (0)