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 @@ -25,18 +25,29 @@
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);

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
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;
Expand Down Expand Up @@ -394,7 +395,7 @@ protected void checkIfVolumeHasBackingFile(VolumeOnStorageTO volume) {
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.");
}
}
Expand Down Expand Up @@ -513,4 +514,16 @@ private void unmanageVolumeFromDatabase(VolumeVO volume) {
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
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@

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;
Expand Down Expand Up @@ -2908,7 +2909,7 @@ private void checkVolume(Map<VolumeOnStorageTO.Detail, String> volumeDetails) {
}
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.");
}
}
Expand Down
Loading