skattoju4 commented on a change in pull request #4875:
URL: https://github.com/apache/cloudstack/pull/4875#discussion_r620554844



##########
File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
##########
@@ -1596,6 +1596,19 @@ private Volume orchestrateAttachVolumeToVM(Long vmId, 
Long volumeId, Long device
         StoragePoolVO destPrimaryStorage = null;
         if (exstingVolumeOfVm != null && 
!exstingVolumeOfVm.getState().equals(Volume.State.Allocated)) {
             destPrimaryStorage = 
_storagePoolDao.findById(exstingVolumeOfVm.getPoolId());
+            if(destPrimaryStorage.getPodId() == null) {
+                destPrimaryStorage.setPodId(vm.getPodIdToDeployIn());
+
+            }
+            if(destPrimaryStorage.getClusterId() == null) {
+                HostVO hostVO = null;
+                if (vm.getHostId() != null) {
+                    hostVO = _hostDao.findById(vm.getHostId());
+                } else {
+                    hostVO = _hostDao.findById(vm.getLastHostId());
+                }
+                destPrimaryStorage.setClusterId(hostVO.getClusterId());

Review comment:
       This was added because we were encountering a null pointer exception in 
some scenarios I don't recall exactly. I added the bit to get the last host id 
of the vm as attaching a disk to a stopped vm would fail. Have not encountered 
any side effects with regards to zone wide storage so far..




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to