Skip to content

Commit eb7447e

Browse files
committed
[Vmware to KVM Migration] Fix issue with vCenter Standalone hosts for VM listing
1 parent cbd2b5a commit eb7447e

File tree

1 file changed

+18
-2
lines changed
  • vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo

1 file changed

+18
-2
lines changed

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,29 @@ private void setUnmanagedInstanceTOHostAndCluster(UnmanagedInstanceTO vm, Manage
251251
hostClusterPair = hostClusterNamesMap.get(hostMorValue);
252252
} else {
253253
HostMO hostMO = new HostMO(_context, hostMor);
254-
ClusterMO clusterMO = new ClusterMO(_context, hostMO.getHyperHostCluster());
255-
hostClusterPair = new Pair<>(hostMO.getHostName(), clusterMO.getName());
254+
String hostName = hostMO.getHostName();
255+
String clusterName = getClusterNameFromHostIncludingStandaloneHosts(hostMO, hostName);
256+
hostClusterPair = new Pair<>(hostName, clusterName);
256257
hostClusterNamesMap.put(hostMorValue, hostClusterPair);
257258
}
258259
vm.setHostName(hostClusterPair.first());
259260
vm.setClusterName(hostClusterPair.second());
260261
}
261262
}
262263

264+
/**
265+
* Return the cluster name of the host on the vCenter
266+
* @return null in case the host is standalone (doesn't belong to a cluster), cluster name otherwise
267+
*/
268+
private String getClusterNameFromHostIncludingStandaloneHosts(HostMO hostMO, String hostName) {
269+
try {
270+
ClusterMO clusterMO = new ClusterMO(_context, hostMO.getHyperHostCluster());
271+
return clusterMO.getName();
272+
} catch (Exception e) {
273+
String msg = String.format("Standalone host %s found, setting empty cluster field", hostName);
274+
s_logger.debug(msg);
275+
return null;
276+
}
277+
}
278+
263279
}

0 commit comments

Comments
 (0)