Search in sources :

Example 1 with HostInitiatorRequest

use of com.emc.storageos.vnxe.requests.HostInitiatorRequest in project coprhd-controller by CoprHD.

the class VNXeApiClient method setInitiatorHost.

/**
 * Modify initiator's parent host
 *
 * @param initiatorId initiator Id
 * @param hostId host Id
 */
public void setInitiatorHost(String initiatorId, String hostId) {
    HostInitiatorModifyParam initModifyParam = new HostInitiatorModifyParam();
    VNXeBase host = new VNXeBase(hostId);
    initModifyParam.setHost(host);
    HostInitiatorRequest req = new HostInitiatorRequest(_khClient);
    req.modifyHostInitiator(initModifyParam, initiatorId);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) HostInitiatorModifyParam(com.emc.storageos.vnxe.models.HostInitiatorModifyParam) DeleteHostInitiatorRequest(com.emc.storageos.vnxe.requests.DeleteHostInitiatorRequest) HostInitiatorRequest(com.emc.storageos.vnxe.requests.HostInitiatorRequest)

Example 2 with HostInitiatorRequest

use of com.emc.storageos.vnxe.requests.HostInitiatorRequest in project coprhd-controller by CoprHD.

the class VNXeApiClient method prepareHostsForExport.

/**
 * given host name and initiators, find/create hosts/initiators in the
 *
 * @param hostInitiators
 * @return
 */
public VNXeBase prepareHostsForExport(Collection<VNXeHostInitiator> hostInitiators) throws VNXeException {
    String hostId = null;
    Set<VNXeHostInitiator> notExistingInits = new HashSet<VNXeHostInitiator>();
    Set<VNXeHostInitiator> existingNoHostInits = new HashSet<VNXeHostInitiator>();
    String hostOsType = null;
    String hostName = null;
    for (VNXeHostInitiator init : hostInitiators) {
        VNXeHostInitiator existingInit = getInitiatorByWWN(init.getInitiatorId());
        if (existingInit != null && existingInit.getParentHost() != null) {
            if (hostId == null) {
                hostId = existingInit.getParentHost().getId();
            } else if (!hostId.equals(existingInit.getParentHost().getId())) {
                _logger.error("Initiators belong to different hosts");
                throw VNXeException.exceptions.vnxeCommandFailed("Initiators belong to different hosts");
            }
        } else if (existingInit != null) {
            existingNoHostInits.add(existingInit);
        } else {
            notExistingInits.add(init);
        }
        if (hostOsType == null) {
            hostOsType = init.getHostOsType();
        }
        if (hostName == null) {
            hostName = init.getName();
        }
    }
    if (hostId == null) {
        // create host and hostInitiator
        HostListRequest hostReq = new HostListRequest(_khClient);
        HostCreateParam hostCreateParm = new HostCreateParam();
        hostCreateParm.setName(hostName);
        hostCreateParm.setType(HostTypeEnum.HOSTMANUAL.getValue());
        if (isUnityClient() && hostOsType != null) {
            hostCreateParm.setOsType(hostOsType);
        }
        VNXeCommandResult result = hostReq.createHost(hostCreateParm);
        hostId = result.getId();
    }
    for (VNXeHostInitiator newInit : notExistingInits) {
        HostInitiatorCreateParam initCreateParam = new HostInitiatorCreateParam();
        VNXeBase host = new VNXeBase(hostId);
        initCreateParam.setHost(host);
        if (newInit.getType() == HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI) {
            initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI.getValue());
            initCreateParam.setInitiatorWWNorIqn(newInit.getChapUserName());
            initCreateParam.setChapUser(newInit.getChapUserName());
        } else {
            initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_FC.getValue());
            initCreateParam.setInitiatorWWNorIqn(newInit.getInitiatorId());
        }
        HostInitiatorRequest req = new HostInitiatorRequest(_khClient);
        try {
            req.createHostInitiator(initCreateParam);
        } catch (VNXeException e) {
            // For ESX hosts, even if we could not get the initiators when we query them, when we try to create the host
            // initiator with the created host, it would throw error, saying the initiator exists. ignore the error.
            String message = e.getMessage();
            if (message != null && message.contains(VNXeConstants.INITIATOR_EXISITNG)) {
                _logger.info("The initiator exists. Ignore the error.");
            } else {
                throw e;
            }
        }
    }
    for (VNXeHostInitiator exitInit : existingNoHostInits) {
        setInitiatorHost(exitInit.getId(), hostId);
    }
    return new VNXeBase(hostId);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) HostListRequest(com.emc.storageos.vnxe.requests.HostListRequest) HostCreateParam(com.emc.storageos.vnxe.models.HostCreateParam) VNXeCommandResult(com.emc.storageos.vnxe.models.VNXeCommandResult) HostInitiatorCreateParam(com.emc.storageos.vnxe.models.HostInitiatorCreateParam) DeleteHostInitiatorRequest(com.emc.storageos.vnxe.requests.DeleteHostInitiatorRequest) HostInitiatorRequest(com.emc.storageos.vnxe.requests.HostInitiatorRequest) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) HashSet(java.util.HashSet)

Example 3 with HostInitiatorRequest

use of com.emc.storageos.vnxe.requests.HostInitiatorRequest in project coprhd-controller by CoprHD.

the class VNXeApiClient method createInitiator.

/**
 * Create host initiator in the array
 *
 * @param inits
 * @param hostId
 */
public void createInitiator(VNXeHostInitiator newInit, String hostId) {
    HostInitiatorCreateParam initCreateParam = new HostInitiatorCreateParam();
    VNXeBase host = new VNXeBase(hostId);
    initCreateParam.setHost(host);
    if (newInit.getType() == HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI) {
        initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI.getValue());
        initCreateParam.setInitiatorWWNorIqn(newInit.getChapUserName());
        initCreateParam.setChapUser(newInit.getChapUserName());
    } else {
        initCreateParam.setInitiatorType(HostInitiatorTypeEnum.INITIATOR_TYPE_FC.getValue());
        initCreateParam.setInitiatorWWNorIqn(newInit.getInitiatorId());
    }
    HostInitiatorRequest req = new HostInitiatorRequest(_khClient);
    req.createHostInitiator(initCreateParam);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) HostInitiatorCreateParam(com.emc.storageos.vnxe.models.HostInitiatorCreateParam) DeleteHostInitiatorRequest(com.emc.storageos.vnxe.requests.DeleteHostInitiatorRequest) HostInitiatorRequest(com.emc.storageos.vnxe.requests.HostInitiatorRequest)

Aggregations

VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)3 DeleteHostInitiatorRequest (com.emc.storageos.vnxe.requests.DeleteHostInitiatorRequest)3 HostInitiatorRequest (com.emc.storageos.vnxe.requests.HostInitiatorRequest)3 HostInitiatorCreateParam (com.emc.storageos.vnxe.models.HostInitiatorCreateParam)2 HostCreateParam (com.emc.storageos.vnxe.models.HostCreateParam)1 HostInitiatorModifyParam (com.emc.storageos.vnxe.models.HostInitiatorModifyParam)1 VNXeCommandResult (com.emc.storageos.vnxe.models.VNXeCommandResult)1 VNXeHostInitiator (com.emc.storageos.vnxe.models.VNXeHostInitiator)1 HostListRequest (com.emc.storageos.vnxe.requests.HostListRequest)1 HashSet (java.util.HashSet)1