throw discEx;
}
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
}
VmwareContext context = null;
try {
context = VmwareContextFactory.create(url.getHost(), username,
password);
if (privateTrafficLabel != null)
context.registerStockObject("privateTrafficLabel",
privateTrafficLabel);
if (nexusDVS) {
if (vsmCredentials != null) {
s_logger.info("Stocking credentials of Nexus VSM");
context.registerStockObject("vsmcredentials",
vsmCredentials);
}
}
List<ManagedObjectReference> morHosts = _vmwareMgr
.addHostToPodCluster(context, dcId, podId, clusterId,
URLDecoder.decode(url.getPath()));
if (morHosts == null)
s_logger.info("Found 0 hosts.");
if (privateTrafficLabel != null)
context.uregisterStockObject("privateTrafficLabel");
if (morHosts == null) {
s_logger.error("Unable to find host or cluster based on url: "
+ URLDecoder.decode(url.getPath()));
return null;
}
ManagedObjectReference morCluster = null;
clusterDetails = _clusterDetailsDao.findDetails(clusterId);
if (clusterDetails.get("url") != null) {
URI uriFromCluster = new URI(
UriUtils.encodeURIComponent(clusterDetails.get("url")));
morCluster = context.getHostMorByPath(URLDecoder
.decode(uriFromCluster.getPath()));
if (morCluster == null
|| !morCluster.getType().equalsIgnoreCase(
"ClusterComputeResource")) {
s_logger.warn("Cluster url does not point to a valid vSphere cluster, url: "
+ clusterDetails.get("url"));
return null;
} else {
ClusterMO clusterMo = new ClusterMO(context, morCluster);
ClusterDasConfigInfo dasConfig = clusterMo.getDasConfig();
if (dasConfig != null && dasConfig.isEnabled() != null
&& dasConfig.isEnabled().booleanValue()) {
clusterDetails.put("NativeHA", "true");
_clusterDetailsDao.persist(clusterId, clusterDetails);
}
}
}
if (!validateDiscoveredHosts(context, morCluster, morHosts)) {
if (morCluster == null)
s_logger.warn("The discovered host is not standalone host, can not be added to a standalone cluster");
else
s_logger.warn("The discovered host does not belong to the cluster");
return null;
}
Map<VmwareResource, Map<String, String>> resources = new HashMap<VmwareResource, Map<String, String>>();
for (ManagedObjectReference morHost : morHosts) {
Map<String, String> details = new HashMap<String, String>();
Map<String, Object> params = new HashMap<String, Object>();
HostMO hostMo = new HostMO(context, morHost);
details.put("url", hostMo.getHostName());
details.put("username", username);
details.put("password", password);
String guid = morHost.getType() + ":" + morHost.getValue()
+ "@" + url.getHost();
details.put("guid", guid);
params.put("url", hostMo.getHostName());
params.put("username", username);
params.put("password", password);
params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guid);
if (privateTrafficLabel != null) {
params.put("private.network.vswitch.name",
privateTrafficLabel);
}
params.put("guestTrafficInfo", guestTrafficLabelObj);
params.put("publicTrafficInfo", publicTrafficLabelObj);
VmwareResource resource = new VmwareResource();
try {
resource.configure("VMware", params);
} catch (ConfigurationException e) {
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId,
podId, "Unable to add " + url.getHost(),
"Error is " + e.getMessage());
s_logger.warn("Unable to instantiate " + url.getHost(), e);
}
resource.start();
resources.put(resource, details);
}
// place a place holder guid derived from cluster ID
cluster.setGuid(UUID.nameUUIDFromBytes(
String.valueOf(clusterId).getBytes()).toString());
_clusterDao.update(clusterId, cluster);
// Flag cluster discovery success
failureInClusterDiscovery = false;
return resources;
} catch (DiscoveredWithErrorException e) {
throw e;
} catch (Exception e) {
s_logger.warn("Unable to connect to Vmware vSphere server. service address: "
+ url.getHost());
return null;
} finally {
if (context != null)
context.close();
if (failureInClusterDiscovery && vsmInfo.first()) {
try {
s_logger.debug("Deleting Nexus 1000v VSM " + vsmIp + " because cluster discovery and addition to zone has failed.");
_nexusElement.deleteCiscoNexusVSM(vsmInfo.second().longValue());
} catch(Exception e) {