[Vmware to KVM Migration] Fix issue with vCenter Standalone hosts for VM listing (#11091)

This commit is contained in:
Nicolas Vazquez 2025-07-09 04:41:34 -03:00 committed by GitHub
parent e47b78b2bb
commit c782835f01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -251,8 +251,9 @@ public class BaseMO {
hostClusterPair = hostClusterNamesMap.get(hostMorValue);
} else {
HostMO hostMO = new HostMO(_context, hostMor);
ClusterMO clusterMO = new ClusterMO(_context, hostMO.getHyperHostCluster());
hostClusterPair = new Pair<>(hostMO.getHostName(), clusterMO.getName());
String hostName = hostMO.getHostName();
String clusterName = getClusterNameFromHostIncludingStandaloneHosts(hostMO, hostName);
hostClusterPair = new Pair<>(hostName, clusterName);
hostClusterNamesMap.put(hostMorValue, hostClusterPair);
}
vm.setHostName(hostClusterPair.first());
@ -260,4 +261,20 @@ public class BaseMO {
}
}
/**
* Return the cluster name of the host on the vCenter
* @return null in case the host is standalone (doesn't belong to a cluster), cluster name otherwise
*/
private String getClusterNameFromHostIncludingStandaloneHosts(HostMO hostMO, String hostName) {
try {
ClusterMO clusterMO = new ClusterMO(_context, hostMO.getHyperHostCluster());
return clusterMO.getName();
} catch (Exception e) {
String msg = String.format("Cannot find a cluster for host %s, assuming standalone host, " +
"setting its cluster name as empty", hostName);
s_logger.info(msg);
return null;
}
}
}