use of com.vmware.vim25.HostHardwareInfo in project coprhd-controller by CoprHD.
the class EsxHostDiscoveryAdapter method discoverHost.
/**
* Discover Esx host
*
* @param host
* {@link Host} instance to be discovered
* @param changes
* {@link HostStateChange} instance containing host changes
* during discovery.
*/
@Override
protected void discoverHost(Host host, HostStateChange changes) {
VCenterAPI api = createVCenterAPI(host);
try {
List<HostSystem> hostSystems = api.listAllHostSystems();
if (null != hostSystems && !hostSystems.isEmpty()) {
// getting the 0th element only coz we are querying an ESX for
// hostsystems and this will always return one or none.
HostSystem hostSystem = hostSystems.get(0);
Host targetHost = null;
HostHardwareInfo hw = hostSystem.getHardware();
String uuid = null;
if (hw != null && hw.systemInfo != null && StringUtils.isNotBlank(hw.systemInfo.uuid)) {
// try finding host by UUID
uuid = hw.systemInfo.uuid;
if (KNOWN_DUPLICATE_UUID.equalsIgnoreCase(uuid)) {
info("Host " + hostSystem.getName() + " contains a known non-unique UUID");
}
// search host by uuid in VIPR if host already discovered
targetHost = findHostByUuid(uuid);
checkDuplicateHost(host, targetHost);
}
if (targetHost == null) {
// if target host is null, this is a new discovery.
targetHost = host;
}
targetHost.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
targetHost.setDiscoverable(true);
if (targetHost.getId() == null) {
targetHost.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
}
targetHost.setOsVersion(hostSystem.getConfig().getProduct().getVersion());
if (hw != null && hw.biosInfo != null && StringUtils.isNotBlank(hw.biosInfo.biosVersion)) {
targetHost.setBios(hw.biosInfo.biosVersion);
}
if (null != uuid) {
targetHost.setUuid(uuid);
}
save(targetHost);
DiscoveryStatusUtils.markAsProcessing(getModelClient(), targetHost);
try {
discoverHost(hostSystem, targetHost, changes);
DiscoveryStatusUtils.markAsSucceeded(getModelClient(), targetHost);
} catch (RuntimeException e) {
warn(e, "Problem discovering host %s", targetHost.getLabel());
DiscoveryStatusUtils.markAsFailed(getModelClient(), targetHost, e.getMessage(), e);
}
}
} finally {
api.logout();
}
}
Aggregations