Search in sources :

Example 1 with ScServer

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

the class DellSCProvisioning method getInitiatorInfo.

/**
 * Gets Initiator details from servers and ports.
 *
 * @param api The Storage Center API connection.
 * @param server The ScServer.
 * @param hba The server HBA.
 * @return The initiator.
 */
private Initiator getInitiatorInfo(StorageCenterAPI api, ScServer server, ScServerHba hba) {
    Initiator result = new Initiator();
    ScServer cluster = null;
    if (server.type.contains("Physical")) {
        ScPhysicalServer physicalServer = api.getPhysicalServerDefinition(server.instanceId);
        if (physicalServer != null && physicalServer.parent != null && physicalServer.parent.instanceId != null) {
            cluster = api.getServerDefinition(physicalServer.parent.instanceId);
        }
    }
    result.setHostName(server.name);
    result.setInitiatorType(Type.Host);
    if (cluster != null) {
        result.setClusterName(cluster.name);
        result.setInitiatorType(Type.Cluster);
    }
    result.setNativeId(hba.instanceId);
    result.setPort(hba.instanceId);
    Protocol protocol = Protocol.iSCSI;
    if ("FibreChannel".equals(hba.portType)) {
        protocol = Protocol.FC;
    }
    result.setProtocol(protocol);
    return result;
}
Also used : ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) Initiator(com.emc.storageos.storagedriver.model.Initiator) ScPhysicalServer(com.emc.storageos.driver.dellsc.scapi.objects.ScPhysicalServer) Protocol(com.emc.storageos.storagedriver.model.Initiator.Protocol)

Example 2 with ScServer

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

the class DellSCProvisioning method populateVolumeExportInfo.

/**
 * Fills in export information for a specific volume mapping.
 *
 * @param volumeId The volume instance ID.
 * @param map The mapping.
 * @param result The export info map.
 * @param serverCache The server cache.
 * @param serverPortCache The server HBA cache.
 * @param portCache The controller port cache.
 * @throws StorageCenterAPIException
 */
private void populateVolumeExportInfo(StorageCenterAPI api, String volumeId, ScMapping map, Map<String, HostExportInfo> result, Map<String, ScServer> serverCache, Map<String, Initiator> serverPortCache, Map<String, StoragePort> portCache) throws StorageCenterAPIException {
    ScServer server;
    Initiator initiator;
    StoragePort port;
    // Get our server info
    if (serverCache.containsKey(map.server.instanceId)) {
        server = serverCache.get(map.server.instanceId);
    } else {
        server = api.getServerDefinition(map.server.instanceId);
        serverCache.put(server.instanceId, server);
    }
    // Find the server HBA
    if (serverPortCache.containsKey(map.serverHba.instanceId)) {
        initiator = serverPortCache.get(map.serverHba.instanceId);
    } else {
        ScServerHba hba = api.getServerHba(map.serverHba.instanceId);
        initiator = getInitiatorInfo(api, server, hba);
        serverPortCache.put(hba.instanceId, initiator);
    }
    // Get the controller port info
    if (portCache.containsKey(map.controllerPort.instanceId)) {
        port = portCache.get(map.controllerPort.instanceId);
    } else {
        ScControllerPort scPort = api.getControllerPort(map.controllerPort.instanceId);
        port = util.getStoragePortForControllerPort(api, scPort);
        portCache.put(scPort.instanceId, port);
    }
    String hostName = initiator.getHostName();
    if (initiator.getInitiatorType() == Type.Cluster) {
        hostName = initiator.getClusterName();
    }
    HostExportInfo exportInfo;
    if (result.containsKey(hostName)) {
        exportInfo = result.get(hostName);
    } else {
        exportInfo = new HostExportInfo(hostName, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
    }
    // Now populate all the info
    if (!exportInfo.getStorageObjectNativeIds().contains(volumeId)) {
        exportInfo.getStorageObjectNativeIds().add(volumeId);
    }
    if (!exportInfo.getTargets().contains(port)) {
        exportInfo.getTargets().add(port);
    }
    if (!exportInfo.getInitiators().contains(initiator)) {
        exportInfo.getInitiators().add(initiator);
    }
    result.put(hostName, exportInfo);
}
Also used : ScControllerPort(com.emc.storageos.driver.dellsc.scapi.objects.ScControllerPort) ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) Initiator(com.emc.storageos.storagedriver.model.Initiator) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) ArrayList(java.util.ArrayList) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) ScServerHba(com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba)

Example 3 with ScServer

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

the class DellSCProvisioning method getVolumeExportInfo.

/**
 * Gets the mapping information for a volume to initiators.
 *
 * @param volumeId The volume instance ID.
 * @param systemId The storage system ID.
 * @return The mapping details. Map of HostName:HostExportInfo
 */
public Map<String, HostExportInfo> getVolumeExportInfo(String volumeId, String systemId) {
    Map<String, HostExportInfo> result = new HashMap<>();
    Map<String, ScServer> serverCache = new HashMap<>();
    Map<String, Initiator> serverPortCache = new HashMap<>();
    Map<String, StoragePort> portCache = new HashMap<>();
    try {
        StorageCenterAPI api = connectionManager.getConnection(systemId);
        ScVolume scVol = api.getVolume(volumeId);
        if (scVol == null) {
            throw new DellSCDriverException(String.format("Volume %s could not be found.", volumeId));
        }
        ScMapping[] maps = api.getVolumeMaps(scVol.instanceId);
        for (ScMapping map : maps) {
            populateVolumeExportInfo(api, volumeId, map, result, serverCache, serverPortCache, portCache);
        }
    } catch (StorageCenterAPIException | DellSCDriverException dex) {
        String message = String.format("Error getting export info for volume %s: %s", volumeId, dex);
        LOG.warn(message);
    }
    return result;
}
Also used : StorageCenterAPI(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI) ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) HashMap(java.util.HashMap) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) ScVolume(com.emc.storageos.driver.dellsc.scapi.objects.ScVolume) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException) Initiator(com.emc.storageos.storagedriver.model.Initiator) ScMapping(com.emc.storageos.driver.dellsc.scapi.objects.ScMapping)

Example 4 with ScServer

use of com.emc.storageos.driver.dellsc.scapi.objects.ScServer 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 5 with ScServer

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

the class DellSCProvisioning method unexportVolumesFromInitiators.

/**
 * Remove volume exports to initiators.
 *
 * @param initiators The initiators to remove from.
 * @param volumes The volumes to remove.
 * @return The unexport task.
 */
public DriverTask unexportVolumesFromInitiators(List<Initiator> initiators, List<StorageVolume> volumes) {
    LOG.info("Unexporting volumes from initiators");
    DriverTask task = new DellSCDriverTask("unexportVolumes");
    ScServer server = null;
    StringBuilder errBuffer = new StringBuilder();
    int volumesUnmapped = 0;
    for (StorageVolume volume : volumes) {
        String ssn = volume.getStorageSystemId();
        boolean isSnapshot = StringUtils.countMatches(volume.getNativeId(), ".") == 2;
        try {
            StorageCenterAPI api = connectionManager.getConnection(ssn);
            // Find our actual volume
            ScVolume scVol = null;
            if (isSnapshot) {
                scVol = api.findReplayView(volume.getNativeId());
                // For snapshot views we can just delete the view
                if (scVol != null) {
                    api.deleteVolume(scVol.instanceId);
                    volumesUnmapped++;
                    continue;
                }
            } else {
                scVol = api.getVolume(volume.getNativeId());
            }
            if (scVol == null) {
                throw new DellSCDriverException(String.format("Unable to find volume %s", volume.getNativeId()));
            }
            // Look up the server if needed
            if (server == null) {
                server = findScServer(api, ssn, initiators);
            }
            if (server == null) {
                // Unable to find the server, can't continue
                throw new DellSCDriverException(SERVER_CREATE_FAIL_MSG);
            }
            ScMappingProfile[] mappingProfiles = api.findMappingProfiles(server.instanceId, scVol.instanceId);
            for (ScMappingProfile mappingProfile : mappingProfiles) {
                api.deleteMappingProfile(mappingProfile.instanceId);
            }
            volumesUnmapped++;
            LOG.info("Volume '{}' unexported from server '{}'", scVol.name, server.name);
        } catch (StorageCenterAPIException | DellSCDriverException dex) {
            String error = String.format("Error unmapping volume %s: %s", volume.getDisplayName(), dex);
            LOG.error(error);
            errBuffer.append(String.format("%s%n", error));
            if (SERVER_CREATE_FAIL_MSG.equals(dex.getMessage())) {
                // Game over
                break;
            }
        }
    }
    task.setMessage(errBuffer.toString());
    if (volumesUnmapped == volumes.size()) {
        task.setStatus(TaskStatus.READY);
    } else if (volumesUnmapped == 0) {
        task.setStatus(TaskStatus.FAILED);
    } else {
        task.setStatus(TaskStatus.PARTIALLY_FAILED);
    }
    return task;
}
Also used : StorageCenterAPI(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI) ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) DellSCDriverTask(com.emc.storageos.driver.dellsc.DellSCDriverTask) ScMappingProfile(com.emc.storageos.driver.dellsc.scapi.objects.ScMappingProfile) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) DriverTask(com.emc.storageos.storagedriver.DriverTask) DellSCDriverTask(com.emc.storageos.driver.dellsc.DellSCDriverTask) ScVolume(com.emc.storageos.driver.dellsc.scapi.objects.ScVolume) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException)

Aggregations

ScServer (com.emc.storageos.driver.dellsc.scapi.objects.ScServer)9 StorageCenterAPIException (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException)4 ScServerHba (com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba)4 ScVolume (com.emc.storageos.driver.dellsc.scapi.objects.ScVolume)4 Initiator (com.emc.storageos.storagedriver.model.Initiator)4 DellSCDriverException (com.emc.storageos.driver.dellsc.DellSCDriverException)3 StorageCenterAPI (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI)3 ScMappingProfile (com.emc.storageos.driver.dellsc.scapi.objects.ScMappingProfile)3 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)3 HashMap (java.util.HashMap)3 DellSCDriverTask (com.emc.storageos.driver.dellsc.DellSCDriverTask)2 ScControllerPort (com.emc.storageos.driver.dellsc.scapi.objects.ScControllerPort)2 ScMapping (com.emc.storageos.driver.dellsc.scapi.objects.ScMapping)2 RestResult (com.emc.storageos.driver.dellsc.scapi.rest.RestResult)2 HostExportInfo (com.emc.storageos.storagedriver.HostExportInfo)2 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)2 ArrayList (java.util.ArrayList)2 ScPhysicalServer (com.emc.storageos.driver.dellsc.scapi.objects.ScPhysicalServer)1 ScServerOperatingSystem (com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem)1 ScVolumeConfiguration (com.emc.storageos.driver.dellsc.scapi.objects.ScVolumeConfiguration)1