@Deprecated
private ManagedObjectReference addHostToVCenterCluster(VmwareContext serviceContext, ManagedObjectReference morCluster,
String host, String userName, String password) throws Exception {
ServiceUtil serviceUtil = serviceContext.getServiceUtil();
ManagedObjectReference morHost = serviceUtil.getDecendentMoRef(morCluster, "HostSystem", host);
if(morHost == null) {
HostConnectSpec hostSpec = new HostConnectSpec();
hostSpec.setUserName(userName);
hostSpec.setPassword(password);
hostSpec.setHostName(host);
hostSpec.setForce(true); // forcely take over the host
ManagedObjectReference morTask = serviceContext.getService().addHost_Task(morCluster, hostSpec, true, null, null);
String taskResult = serviceUtil.waitForTask(morTask);
if(!taskResult.equals("sucess")) {
s_logger.error("Unable to add host " + host + " to vSphere cluster due to " + TaskMO.getTaskFailureInfo(serviceContext, morTask));
throw new CloudRuntimeException("Unable to add host " + host + " to vSphere cluster due to " + taskResult);
}
serviceContext.waitForTaskProgressDone(morTask);
// init morHost after it has been created
morHost = serviceUtil.getDecendentMoRef(morCluster, "HostSystem", host);
if(morHost == null) {
throw new CloudRuntimeException("Successfully added host into vSphere but unable to find it later on?!. Please make sure you are either using IP address or full qualified domain name for host");
}
}