@@ -251,13 +251,30 @@ private void setUnmanagedInstanceTOHostAndCluster(UnmanagedInstanceTO vm, Manage
251
251
hostClusterPair = hostClusterNamesMap .get (hostMorValue );
252
252
} else {
253
253
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 );
256
257
hostClusterNamesMap .put (hostMorValue , hostClusterPair );
257
258
}
258
259
vm .setHostName (hostClusterPair .first ());
259
260
vm .setClusterName (hostClusterPair .second ());
260
261
}
261
262
}
262
263
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 ("Cannot find a cluster for host %s, assuming standalone host, " +
274
+ "setting its cluster name as empty" , hostName );
275
+ s_logger .info (msg );
276
+ return null ;
277
+ }
278
+ }
279
+
263
280
}
0 commit comments