Search in sources :

Example 1 with ISCSIPath

use of com.emc.storageos.hp3par.command.ISCSIPath in project coprhd-controller by CoprHD.

the class HP3PARApi method updateHost.

public void updateHost(String name, ArrayList<String> portIdsNew) throws Exception {
    _log.info("3PARDriver:updateHost enter");
    ClientResponse clientResp = null;
    String portIdstr = "[";
    String body = null;
    final String path = MessageFormat.format(URI_HOST_DETAILS, name);
    ArrayList<String> portIdsNewFiltered = new ArrayList<>();
    ArrayList<String> existingFc = new ArrayList<>();
    try {
        // get existing host wwn/iqn;
        HostMember hostMemb = getHostDetails(name);
        if (portIdsNew.get(0).startsWith("iqn") == false) {
            for (FcPath fcPath : hostMemb.getFCPaths()) {
                existingFc.add(SanUtils.cleanWWN(fcPath.getWwn()));
            }
            // remove existing wwn/iqns in the list to be added
            for (String portId : portIdsNew) {
                if (existingFc.contains(SanUtils.cleanWWN(portId)) == false) {
                    portIdsNewFiltered.add(SanUtils.cleanWWN(portId));
                }
            }
        } else {
            for (ISCSIPath scPath : hostMemb.getiSCSIPaths()) {
                existingFc.add(scPath.getName());
            }
            // remove existing wwn/iqns in the list to be added
            for (String portId : portIdsNew) {
                if (existingFc.contains(portId) == false) {
                    portIdsNewFiltered.add(portId);
                }
            }
        }
        for (String Id : portIdsNewFiltered) {
            if (portIdstr.length() > 1) {
                portIdstr = portIdstr.concat(",");
            }
            portIdstr = portIdstr.concat("\"" + Id + "\"");
        }
        portIdstr = portIdstr.concat("]");
        if (portIdsNewFiltered.get(0).startsWith("iqn") == false) {
            body = "{\"FCWWNs\":" + portIdstr + ", \"pathOperation\":1}";
        } else {
            body = "{\"iSCSINames\":" + portIdstr + ", \"pathOperation\":1\"}";
        }
        _log.info("3PARDriver: updateHost path is {}, body is {}", path, body);
        clientResp = put(path, body);
        if (clientResp == null) {
            _log.error("3PARDriver:There is no response from 3PAR");
            throw new HP3PARException("There is no response from 3PAR");
        } else if (clientResp.getStatus() != 200) {
            String errResp = getResponseDetails(clientResp);
            throw new HP3PARException(errResp);
        } else {
            String responseString = getHeaderFieldValue(clientResp, "Location");
            _log.info("3PARDriver:updateHost 3PAR response is Location: {}", responseString);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (clientResp != null) {
            clientResp.close();
        }
        _log.info("3PARDriver:updateHost leave");
    }
// end try/catch/finally
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HostMember(com.emc.storageos.hp3par.command.HostMember) ISCSIPath(com.emc.storageos.hp3par.command.ISCSIPath) ArrayList(java.util.ArrayList) FcPath(com.emc.storageos.hp3par.command.FcPath)

Example 2 with ISCSIPath

use of com.emc.storageos.hp3par.command.ISCSIPath in project coprhd-controller by CoprHD.

the class HP3PARExpUnexpHelper method search3parHostName.

private HP3PARHostNameResult search3parHostName(List<Initiator> initiators, HostCommandResult hostRes) {
    String hp3parHost = null;
    HP3PARHostNameResult hp3parHostResult = new HP3PARHostNameResult();
    // for each host in the result
    for (HostMember hostMemb : hostRes.getMembers()) {
        // for each host initiator sent
        for (Initiator init : initiators) {
            // Is initiator FC
            if (Protocols.FC.toString().compareToIgnoreCase(init.getProtocol().toString()) == 0) {
                // verify in all FC ports with host
                for (FcPath fcPath : hostMemb.getFCPaths()) {
                    if (SanUtils.formatWWN(fcPath.getWwn()).compareToIgnoreCase(init.getPort()) == 0) {
                        hp3parHost = hostMemb.getName();
                        // Reference for residual initiator is present and there is no host name associated with this.
                        if (hp3parHost == null) {
                            continue;
                        }
                        hp3parHostResult.setHostName(hp3parHost);
                        // Confirm all initiators are present with this host
                        if (hostHasAllFcInitiators(initiators, hostMemb.getFCPaths())) {
                            _log.info("3PARDriver: get3parHostname FC initiator {} host {}", init.getPort(), hp3parHost);
                            hp3parHostResult.setAllInitiators(true);
                        } else {
                            // same FC can not be part of any other host; exit
                            hp3parHostResult.setAllInitiators(false);
                        }
                        return hp3parHostResult;
                    }
                }
            } else if (Protocols.iSCSI.toString().compareToIgnoreCase(init.getProtocol().toString()) == 0) {
                // verify in all iSCSI ports with host
                for (ISCSIPath scsiPath : hostMemb.getiSCSIPaths()) {
                    if (scsiPath.getName().compareToIgnoreCase(init.getPort()) == 0) {
                        hp3parHost = hostMemb.getName();
                        hp3parHostResult.setHostName(hp3parHost);
                        // Confirm all initiators are present with this host
                        if (hostHasAlliSCSIInitiators(initiators, hostMemb.getiSCSIPaths())) {
                            _log.info("3PARDriver: get3parHostname iSCSI initiator {} host {}", init.getPort(), hp3parHost);
                            hp3parHostResult.setAllInitiators(true);
                        } else {
                            // same iSCSI can not be part of any other host
                            hp3parHostResult.setAllInitiators(false);
                        }
                        return hp3parHostResult;
                    }
                }
            }
        // if FC or iSCSI
        }
    // each initiator
    }
    return null;
}
Also used : Initiator(com.emc.storageos.storagedriver.model.Initiator) HostMember(com.emc.storageos.hp3par.command.HostMember) ISCSIPath(com.emc.storageos.hp3par.command.ISCSIPath) FcPath(com.emc.storageos.hp3par.command.FcPath)

Aggregations

FcPath (com.emc.storageos.hp3par.command.FcPath)2 HostMember (com.emc.storageos.hp3par.command.HostMember)2 ISCSIPath (com.emc.storageos.hp3par.command.ISCSIPath)2 Initiator (com.emc.storageos.storagedriver.model.Initiator)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 ArrayList (java.util.ArrayList)1