Search in sources :

Example 1 with ScServerOperatingSystem

use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem in project coprhd-controller by CoprHD.

the class DellSCProvisioning method createOrFindScServer.

/**
 * Finds an existing server definition or creates a new one.
 *
 * @param ssn The Storage Center to check.
 * @param api The API connection.
 * @param initiators The list of initiators.
 * @param matchedHbas The ScServerHbas that matched the provided initiators.
 * @param createIfNotFound Whether to create the server if it's not found.
 * @return The server object or null.
 */
private ScServer createOrFindScServer(StorageCenterAPI api, String ssn, List<Initiator> initiators, List<ScServerHba> matchedHbas, boolean createIfNotFound) {
    ScServerOperatingSystem os = null;
    Map<String, ScServer> serverLookup = new HashMap<>();
    for (Initiator init : initiators) {
        if (os == null) {
            os = findOsType(api, ssn, init.getHostOsType());
        }
        if (os == null) {
            LOG.warn("Unable to find OS type for initiator {}, skipping...", init.getPort());
            continue;
        }
        String iqnOrWwn = init.getPort();
        if (init.getProtocol().equals(Protocol.FC)) {
            // Make sure it's in the format we expect
            iqnOrWwn = iqnOrWwn.replace(":", "").toUpperCase();
        }
        // Try our cache first
        ScServer individualServer = serverLookup.get(init.getHostName());
        if (individualServer == null) {
            individualServer = api.findServer(ssn, iqnOrWwn);
            if (individualServer != null) {
                serverLookup.put(init.getHostName(), individualServer);
            }
        }
        // See if we need to create it
        if (individualServer == null && createIfNotFound) {
            try {
                individualServer = api.createServer(ssn, init.getHostName(), init.getProtocol().equals(Protocol.iSCSI), os.instanceId);
            } catch (StorageCenterAPIException e) {
                // Well that's rather unfortunate
                LOG.warn(String.format("Error creating server: %s", e));
                continue;
            }
            // Need to add this initiator to existing server definition
            ScServerHba hba = api.addHbaToServer(individualServer.instanceId, iqnOrWwn, init.getProtocol().equals(Protocol.iSCSI));
            if (hba != null && !matchedHbas.contains(hba)) {
                matchedHbas.add(hba);
            }
        }
        if (individualServer != null) {
            serverLookup.put(init.getHostName(), individualServer);
        }
    }
    if (serverLookup.size() != 1) {
        LOG.warn("Looking for server returned {} servers.", serverLookup.size());
    }
    for (ScServer scServer : serverLookup.values()) {
        // Just return the first one
        return scServer;
    }
    return null;
}
Also used : ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) HashMap(java.util.HashMap) Initiator(com.emc.storageos.storagedriver.model.Initiator) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) ScServerOperatingSystem(com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem) ScServerHba(com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba)

Example 2 with ScServerOperatingSystem

use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem in project coprhd-controller by CoprHD.

the class StorageCenterAPI method getServerOperatingSystems.

/**
 * Gets the OS types.
 *
 * @param ssn The Storage Center system serial number.
 * @param product The product to filter on or null.
 * @return The OS types.
 */
public ScServerOperatingSystem[] getServerOperatingSystems(String ssn, String product) {
    PayloadFilter filter = new PayloadFilter();
    filter.append("scSerialNumber", ssn);
    if (product != null && !product.isEmpty()) {
        filter.append("product", product, ValueFilterType.INCLUDESSTRING);
    }
    RestResult rr = restClient.post("StorageCenter/ScServerOperatingSystem/GetList", filter.toJson());
    if (checkResults(rr)) {
        return gson.fromJson(rr.getResult(), ScServerOperatingSystem[].class);
    }
    return new ScServerOperatingSystem[0];
}
Also used : RestResult(com.emc.storageos.driver.dellsc.scapi.rest.RestResult) PayloadFilter(com.emc.storageos.driver.dellsc.scapi.rest.PayloadFilter) ScServerOperatingSystem(com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem)

Example 3 with ScServerOperatingSystem

use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem in project coprhd-controller by CoprHD.

the class DellSCProvisioning method findOsType.

/**
 * Find an appropriate server operating system type.
 *
 * @param hostOsType The provided OS type.
 * @return The SC OS type.
 */
private ScServerOperatingSystem findOsType(StorageCenterAPI api, String ssn, HostOsType hostOsType) {
    String product;
    String version;
    switch(hostOsType) {
        case Windows:
            product = "Windows";
            version = "2012 MPIO";
            break;
        case HPUX:
            product = "HP UX";
            version = "11i v3";
            break;
        case Linux:
            // Behavior is pretty much the same between them, so
            // we'll just default to Red Hat
            product = "Red Hat Linux";
            version = "6.x";
            break;
        case Esx:
            product = "VMWare";
            version = "5.1";
            break;
        case AIX:
        case AIXVIO:
            product = "AIX";
            version = "7.1 MPIO";
            break;
        case SUNVCS:
        case No_OS:
        case Other:
        default:
            product = "Other";
            version = "Multipath";
            break;
    }
    ScServerOperatingSystem[] osTypes = api.getServerOperatingSystems(ssn, product);
    // First try for an exact match
    for (ScServerOperatingSystem os : osTypes) {
        if (os.version.contains(version)) {
            return os;
        }
    }
    // Just get the first one
    for (ScServerOperatingSystem os : osTypes) {
        return os;
    }
    // Fall back to other if we can
    if (hostOsType != HostOsType.Other) {
        LOG.warn("Unable to find OS type, falling back to Other type.");
        return findOsType(api, ssn, HostOsType.Other);
    }
    return null;
}
Also used : ScServerOperatingSystem(com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem)

Aggregations

ScServerOperatingSystem (com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem)3 StorageCenterAPIException (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException)1 ScServer (com.emc.storageos.driver.dellsc.scapi.objects.ScServer)1 ScServerHba (com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba)1 PayloadFilter (com.emc.storageos.driver.dellsc.scapi.rest.PayloadFilter)1 RestResult (com.emc.storageos.driver.dellsc.scapi.rest.RestResult)1 Initiator (com.emc.storageos.storagedriver.model.Initiator)1 HashMap (java.util.HashMap)1