DaanHoogland commented on code in PR #10748:
URL: https://github.com/apache/cloudstack/pull/10748#discussion_r2066176798


##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java:
##########
@@ -2350,13 +2350,59 @@ protected StartAnswer execute(StartCommand cmd) {
                     continue;
                 }
 
+                VirtualMachineDiskInfo matchingExistingDisk = 
getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
+                VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
+                DataStoreTO primaryStore = volumeTO.getDataStore();
+                Map<String, String> details = vol.getDetails();
+                boolean managed = false;
+                String iScsiName = null;
+
+                if (details != null) {
+                    managed = 
Boolean.parseBoolean(details.get(DiskTO.MANAGED));
+                    iScsiName = details.get(DiskTO.IQN);
+                }
+
+                String primaryStoreUuid = primaryStore.getUuid();
+                // if the storage is managed, iScsiName should not be null
+                String datastoreName = managed ? 
VmwareResource.getDatastoreName(iScsiName) : primaryStoreUuid;
+                Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = 
dataStoresDetails.get(datastoreName);
+
+                assert (volumeDsDetails != null);
+                if (volumeDsDetails == null) {
+                    throw new Exception("Primary datastore " + 
primaryStore.getUuid() + " is not mounted on host.");
+                }
+
+                if (vol.getDetails().get(DiskTO.PROTOCOL_TYPE) != null && 
vol.getDetails().get(DiskTO.PROTOCOL_TYPE).equalsIgnoreCase("DatastoreCluster"))
 {
+                    if (diskInfoBuilder != null && matchingExistingDisk != 
null) {
+                        String[] diskChain = 
matchingExistingDisk.getDiskChain();
+                        if (diskChain != null && diskChain.length > 0) {
+                            DatastoreFile file = new 
DatastoreFile(diskChain[0]);
+                            if 
(!file.getFileBaseName().equalsIgnoreCase(volumeTO.getPath())) {
+                                if (logger.isInfoEnabled())
+                                    logger.info("Detected disk-chain top file 
change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + 
file.getFileBaseName());
+                                volumeTO.setPath(file.getFileBaseName());
+                                vol.setPath(file.getFileBaseName());
+                            }
+                        }
+                        DatastoreMO diskDatastoreMofromVM = 
getDataStoreWhereDiskExists(hyperHost, context, diskInfoBuilder, vol, 
diskDatastores);
+                        if (diskDatastoreMofromVM != null) {
+                            String actualPoolUuid = 
diskDatastoreMofromVM.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID);
+                            if (actualPoolUuid != null && 
!actualPoolUuid.equalsIgnoreCase(primaryStore.getUuid())) {
+                                volumeDsDetails = new 
Pair<>(diskDatastoreMofromVM.getMor(), diskDatastoreMofromVM);
+                                if (logger.isInfoEnabled())
+                                    logger.info("Detected datastore uuid 
change on volume: " + volumeTO.getId() + " " + primaryStore.getUuid() + " -> " 
+ actualPoolUuid);
+                                
((PrimaryDataStoreTO)primaryStore).setUuid(actualPoolUuid);
+                            }
+                        }
+                    }
+                }

Review Comment:
   @sureshanaparti , can you extract these lines in extra methods?



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to