|
24 | 24 | import java.util.HashMap; |
25 | 25 | import java.util.List; |
26 | 26 | import java.util.Map; |
| 27 | +import java.util.Objects; |
27 | 28 | import java.util.Random; |
28 | 29 | import java.util.Set; |
29 | 30 | import java.util.UUID; |
|
141 | 142 | import java.util.stream.Collectors; |
142 | 143 | import org.apache.commons.collections.CollectionUtils; |
143 | 144 |
|
| 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 | + |
144 | 148 | public class StorageSystemDataMotionStrategy implements DataMotionStrategy { |
145 | 149 | protected Logger logger = LogManager.getLogger(getClass()); |
146 | 150 | private static final Random RANDOM = new Random(System.nanoTime()); |
@@ -1933,7 +1937,10 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach |
1933 | 1937 | continue; |
1934 | 1938 | } |
1935 | 1939 |
|
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())) { |
1937 | 1944 | 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())); |
1938 | 1945 | copyTemplateToTargetFilesystemStorageIfNeeded(srcVolumeInfo, sourceStoragePool, destDataStore, destStoragePool, destHost); |
1939 | 1946 | } else { |
@@ -2152,7 +2159,7 @@ String getVolumeBackingFile(VolumeInfo srcVolumeInfo) { |
2152 | 2159 | if (srcVolumeInfo.getHypervisorType() == HypervisorType.KVM && |
2153 | 2160 | srcVolumeInfo.getTemplateId() != null && srcVolumeInfo.getPoolId() != null) { |
2154 | 2161 | 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) { |
2156 | 2163 | VMTemplateStoragePoolVO ref = templatePoolDao.findByPoolTemplate(srcVolumeInfo.getPoolId(), srcVolumeInfo.getTemplateId(), null); |
2157 | 2164 | return ref != null ? ref.getInstallPath() : null; |
2158 | 2165 | } |
|
0 commit comments