Skip to content

Commit 81e614c

Browse files
Pearl1594dhslove
authored andcommitted
Support migration of VM imported from a remote host (apache#9259)
1 parent 4bea15a commit 81e614c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.HashMap;
2525
import java.util.List;
2626
import java.util.Map;
27+
import java.util.Objects;
2728
import java.util.Random;
2829
import java.util.Set;
2930
import java.util.UUID;
@@ -141,6 +142,9 @@
141142
import java.util.stream.Collectors;
142143
import org.apache.commons.collections.CollectionUtils;
143144

145+
import static org.apache.cloudstack.vm.UnmanagedVMsManagerImpl.KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME;
146+
import static org.apache.cloudstack.vm.UnmanagedVMsManagerImpl.VM_IMPORT_DEFAULT_TEMPLATE_NAME;
147+
144148
public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
145149
protected Logger logger = LogManager.getLogger(getClass());
146150
private static final Random RANDOM = new Random(System.nanoTime());
@@ -1933,7 +1937,10 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
19331937
continue;
19341938
}
19351939

1936-
if (srcVolumeInfo.getTemplateId() != null) {
1940+
VMTemplateVO vmTemplate = _vmTemplateDao.findById(vmInstance.getTemplateId());
1941+
if (srcVolumeInfo.getTemplateId() != null &&
1942+
Objects.nonNull(vmTemplate) &&
1943+
!Arrays.asList(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME, VM_IMPORT_DEFAULT_TEMPLATE_NAME).contains(vmTemplate.getName())) {
19371944
logger.debug(String.format("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s].", srcVolumeInfo.getTemplateId(), srcVolumeInfo.getId(), sourceStoragePool.getId(), destStoragePool.getId()));
19381945
copyTemplateToTargetFilesystemStorageIfNeeded(srcVolumeInfo, sourceStoragePool, destDataStore, destStoragePool, destHost);
19391946
} else {
@@ -2152,7 +2159,7 @@ String getVolumeBackingFile(VolumeInfo srcVolumeInfo) {
21522159
if (srcVolumeInfo.getHypervisorType() == HypervisorType.KVM &&
21532160
srcVolumeInfo.getTemplateId() != null && srcVolumeInfo.getPoolId() != null) {
21542161
VMTemplateVO template = _vmTemplateDao.findById(srcVolumeInfo.getTemplateId());
2155-
if (template.getFormat() != null && template.getFormat() != Storage.ImageFormat.ISO) {
2162+
if (Objects.nonNull(template) && template.getFormat() != null && template.getFormat() != Storage.ImageFormat.ISO) {
21562163
VMTemplateStoragePoolVO ref = templatePoolDao.findByPoolTemplate(srcVolumeInfo.getPoolId(), srcVolumeInfo.getTemplateId(), null);
21572164
return ref != null ? ref.getInstallPath() : null;
21582165
}

0 commit comments

Comments
 (0)