Search in sources :

Example 81 with Host

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;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) Host(com.emc.storageos.db.client.model.Host)

Example 82 with 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();
}
Also used : Initiator_Type(com.emc.storageos.vplex.api.VPlexInitiatorInfo.Initiator_Type) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 83 with Host

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());
    }
}
Also used : HashMap(java.util.HashMap) Host(com.emc.storageos.db.client.model.Host) OsInstallParam(com.emc.storageos.model.compute.OsInstallParam) ExecutionException(com.emc.sa.engine.ExecutionException)

Example 84 with Host

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;
}
Also used : AddHostToCluster(com.emc.sa.service.vipr.compute.tasks.AddHostToCluster) GetHost(com.emc.sa.service.vipr.tasks.GetHost) DiscoverHost(com.emc.sa.service.vipr.compute.tasks.DiscoverHost) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) Host(com.emc.storageos.db.client.model.Host) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException)

Example 85 with Host

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;
}
Also used : GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) Vcenter(com.emc.storageos.db.client.model.Vcenter) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) VMwareSupport(com.emc.sa.service.vmware.VMwareSupport) GetHost(com.emc.sa.service.vipr.tasks.GetHost) DiscoverHost(com.emc.sa.service.vipr.compute.tasks.DiscoverHost) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) Host(com.emc.storageos.db.client.model.Host) GetBlockResource(com.emc.sa.service.vipr.block.tasks.GetBlockResource) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) HostRestRep(com.emc.storageos.model.host.HostRestRep) HostSystem(com.vmware.vim25.mo.HostSystem) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostSystemConnectionState(com.vmware.vim25.HostSystemConnectionState) ExecutionException(com.emc.sa.engine.ExecutionException)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16