use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class AssetLoader method saveHost.
public Host saveHost(String tenant, HostDef def) {
Host host = new Host();
host.setTenant(URI.create(tenant));
host.setLabel(def.name);
host.setHostName(def.hostname);
host.setPortNumber(def.port);
host.setType(def.os);
host.setUsername(def.username);
host.setPassword(def.password);
client.save(host);
if (def.wwns != null) {
int i = 0;
for (String wwn : def.wwns) {
Initiator initiator = new Initiator();
initiator.setHost(host.getId());
initiator.setLabel("P" + i);
if (StringUtils.startsWith(wwn, "iqn.")) {
initiator.setInitiatorNode("");
initiator.setInitiatorPort(wwn);
initiator.setProtocol(Protocol.iSCSI.name());
} else {
String node = SanUtils.getNodeName(wwn);
String port = SanUtils.getPortName(wwn);
initiator.setInitiatorNode(node);
initiator.setInitiatorPort(port);
initiator.setProtocol(Protocol.FC.name());
}
client.save(initiator);
}
}
return host;
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class VPlexDeviceController method getVPlexInitiatorType.
/**
* Gets the VPLEX initiator type for the passed initiator.
*
* @param initiator
* A reference to an initiator.
*
* @return The VPLEX initiator type.
*/
private String getVPlexInitiatorType(Initiator initiator) {
Initiator_Type initiatorType = Initiator_Type.DEFAULT;
URI initiatorHostURI = initiator.getHost();
if (!NullColumnValueGetter.isNullURI(initiatorHostURI)) {
Host initiatorHost = getDataObject(Host.class, initiatorHostURI, _dbClient);
if (initiatorHost != null) {
// registering an HPUX initiator in VPLEX.
if (Host.HostType.HPUX.name().equals(initiatorHost.getType())) {
initiatorType = Initiator_Type.HPUX;
} else if ((Host.HostType.AIX.name().equals(initiatorHost.getType())) || (Host.HostType.AIXVIO.name().equals(initiatorHost.getType()))) {
initiatorType = Initiator_Type.AIX;
} else if (Host.HostType.SUNVCS.name().equals(initiatorHost.getType())) {
initiatorType = Initiator_Type.SUN_VCS;
}
}
}
return initiatorType.getType();
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class AddHostToClusterService method installOSForHosts.
private void installOSForHosts(Map<String, String> hostToIps, Map<String, URI> hostNameToBootVolumeMap, List<Host> createdHosts) {
Map<Host, OsInstallParam> osInstallParamMap = new HashMap<Host, OsInstallParam>();
for (Host host : createdHosts) {
if ((host != null) && ((host.getType() == null) || host.getType().isEmpty() || host.getType().equals(Host.HostType.No_OS.name()))) {
OsInstallParam param = new OsInstallParam();
String hostIp = hostToIps.get(host.getHostName());
param.setComputeImage(computeImage);
param.setHostName(host.getHostName());
param.setDnsServers(dnsServers);
param.setGateway(gateway);
param.setNetmask(netmask);
param.setHostIp(hostIp);
param.setVolume(hostNameToBootVolumeMap.get(host.getHostName()));
param.setManagementNetwork(managementNetwork);
param.setNtpServer(ntpServer);
param.setRootPassword(rootPassword);
osInstallParamMap.put(host, param);
} else {
osInstallParamMap.put(host, null);
}
}
try {
// Attempt an OS Install only on the list of hosts that are a part of the order
// This does check if the hosts already have a OS before attempting the install
ComputeUtils.installOsOnHosts(osInstallParamMap);
} catch (Exception e) {
logError(e.getMessage());
}
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ComputeUtils method addHostsToCluster.
/**
* Adds the specified hosts to the given cluster. This operation will add the hosts to the cluster's Export Groups.
* @param List of Hosts to add
* @param Cluster to ad hosts to
* @return Cluster
*/
public static Cluster addHostsToCluster(List<Host> hosts, Cluster cluster) {
if ((hosts != null) && (cluster != null)) {
for (Host host : hosts) {
if (host != null) {
try {
ExecutionUtils.currentContext().logInfo("computeutils.clusterexport.addhost", host.getLabel(), cluster.getLabel());
execute(new AddHostToCluster(host.getId(), cluster.getId()));
} catch (Exception ex) {
ExecutionUtils.currentContext().logError(ex, "computeutils.clusterexport.addhost.failure", host.getLabel(), cluster.getLabel());
}
}
}
} else {
if (cluster != null) {
ExecutionUtils.currentContext().logWarn("computeutils.clusterexport.nohosts.toadd", cluster.getLabel());
} else {
ExecutionUtils.currentContext().logWarn("computeutils.clusterexport.nocluster");
}
}
return cluster;
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ComputeUtils method validateBootVolumes.
/**
* Validate that the boot volume for this host is still on the server.
* This prevents us from deleting a re-purposed volume that was originally
* a boot volume.
*
* @return true if the volumes are valid, or the volumes are not able to be validated, so we can go ahead anyway.
*/
public static boolean validateBootVolumes(Cluster cluster, List<HostRestRep> hostsToValidate) {
// the references are fixed.
if (cluster == null || cluster.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.cluster");
return false;
}
// so return that the boot volume is valid due to lack of technical ability to dig any deeper.
if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noVcenterDataCenter", cluster.forDisplay());
return true;
}
VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
// until that's fixed.
if (dataCenter == null || dataCenter.getInactive() || NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.datacenter", cluster.forDisplay());
return false;
}
Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
// until that's fixed.
if (vcenter == null || vcenter.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.vcenter", cluster.forDisplay());
return false;
}
VMwareSupport vmware = null;
try {
vmware = new VMwareSupport();
vmware.connect(vcenter.getId());
for (HostRestRep clusterHost : hostsToValidate) {
Host host = BlockStorageUtils.getHost(clusterHost.getId());
// Do not validate a host no longer in our database
if (host == null || host.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", "N/A", "host not found or inactive");
return false;
}
// in the vCenter cluster, and therefore we can not perform a deep validation.
if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.vcenternotinhost", host.getHostName());
continue;
}
// any update to the host using the hostService automatically adds this association.
if (!NullColumnValueGetter.isNullURI(host.getVcenterDataCenter()) && host.getType() != null && host.getType().equalsIgnoreCase((Host.HostType.No_OS).name())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noOShost", host.getHostName());
continue;
}
// flag it as an issue.
if (clusterHost.getBootVolume() == null || NullColumnValueGetter.isNullURI(clusterHost.getBootVolume().getId())) {
ExecutionUtils.currentContext().logWarn("computeutils.removebootvolumes.failure.host", host.getHostName(), "no boot volume associated with host");
continue;
}
BlockObjectRestRep bootVolume = execute(new GetBlockResource(clusterHost.getBootVolume().getId()));
// Do not validate an old/non-existent boot volume representation
if (bootVolume == null || bootVolume.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", host.getHostName(), "boot volume not found or inactive");
return false;
}
HostSystem hostSystem = null;
try {
hostSystem = vmware.getHostSystem(dataCenter.getLabel(), clusterHost.getName(), false);
// we can't perform the validation.
if (hostSystem == null) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
continue;
}
HostSystemConnectionState connectionState = VMwareUtils.getConnectionState(hostSystem);
if (connectionState == null || connectionState == HostSystemConnectionState.notResponding || connectionState == HostSystemConnectionState.disconnected) {
String exMsg = "Validation of boot volume usage on host %s failed. " + "Validation failed because host is in a disconnected state or not responding state, and therefore cannot be validated. " + "Cannot decommission in current state. Recommended to either re-connect the host or remove the host from vCenter, " + "run vCenter discovery and address actionable events before attempting decommission of hosts in this cluster.";
// will print a boot volume re-purposed error message which is kind of misleading or incorrect reason for the failure.
throw new IllegalStateException(String.format(exMsg, host.getHostName()));
}
} catch (ExecutionException e) {
if (e.getCause() instanceof IllegalStateException) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
continue;
}
// If it's anything other than the IllegalStateException, re-throw the base exception
throw e;
}
if (vmware.findScsiDisk(hostSystem, null, bootVolume, false, false) == null) {
// fail, host can't see its boot volume
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.bootvolume", bootVolume.getDeviceLabel(), bootVolume.getWwn());
return false;
} else {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validated", host.getHostName(), bootVolume.getDeviceLabel());
}
}
} finally {
if (vmware != null) {
vmware.disconnect();
}
}
return true;
}
Aggregations