File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments