From eb7447eb40617db2af76c91df938da43ce44ac79 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Wed, 25 Jun 2025 23:56:36 -0300 Subject: [PATCH 1/2] [Vmware to KVM Migration] Fix issue with vCenter Standalone hosts for VM listing --- .../cloud/hypervisor/vmware/mo/BaseMO.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java index 0d380bd7ff7d..2d4e30fd6092 100644 --- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java +++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java @@ -251,8 +251,9 @@ private void setUnmanagedInstanceTOHostAndCluster(UnmanagedInstanceTO vm, Manage 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,19 @@ private void setUnmanagedInstanceTOHostAndCluster(UnmanagedInstanceTO vm, Manage } } + /** + * 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("Standalone host %s found, setting empty cluster field", hostName); + s_logger.debug(msg); + return null; + } + } + } From 3af17025739bcbcfdbf677dd297de841c4044a03 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Mon, 7 Jul 2025 07:58:47 -0300 Subject: [PATCH 2/2] Fix logged message --- .../src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java index 2d4e30fd6092..3f27f6c80feb 100644 --- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java +++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java @@ -270,8 +270,9 @@ private String getClusterNameFromHostIncludingStandaloneHosts(HostMO hostMO, Str ClusterMO clusterMO = new ClusterMO(_context, hostMO.getHyperHostCluster()); return clusterMO.getName(); } catch (Exception e) { - String msg = String.format("Standalone host %s found, setting empty cluster field", hostName); - s_logger.debug(msg); + 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; } }