Search in sources :

Example 41 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase 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 42 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class VNXeApiClient method addLunsToConsistencyGroup.

/**
 * Add luns to consistency group
 *
 * @param cgId
 *            consistency group Id
 * @param luns
 *            luns to be added into the consistency group
 */
public VNXeCommandResult addLunsToConsistencyGroup(String cgId, List<String> luns) {
    LunGroupModifyParam param = new LunGroupModifyParam();
    List<LunAddParam> lunAdds = new ArrayList<LunAddParam>();
    for (String lunId : luns) {
        VNXeBase lun = new VNXeBase(lunId);
        LunAddParam lunAdd = new LunAddParam();
        lunAdd.setLun(lun);
        lunAdds.add(lunAdd);
    }
    param.setLunAdd(lunAdds);
    ConsistencyGroupRequests req = new ConsistencyGroupRequests(_khClient);
    return req.modifyConsistencyGroupSync(cgId, param);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunAddParam(com.emc.storageos.vnxe.models.LunAddParam) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ArrayList(java.util.ArrayList) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)

Example 43 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class VNXeApiClient method exportFileSystem.

/**
 * NFS export
 *
 * @param fsId
 *            file system KH id
 * @param endpoints
 *            list of host ipaddresses export to
 * @param access
 *            access right
 * @return VNXeCommandJob
 * @throws VNXeException
 */
public VNXeCommandJob exportFileSystem(String fsId, List<String> roEndpoints, List<String> rwEndpoints, List<String> rootEndpoints, AccessEnum access, String path, String shareName, String shareId, String comments) throws VNXeException {
    _logger.info("Exporting file system:" + fsId);
    FileSystemRequest fsRequest = new FileSystemRequest(_khClient, fsId);
    VNXeFileSystem fs = fsRequest.get();
    if (fs == null) {
        _logger.info("Could not find file system in the vxne");
        throw VNXeException.exceptions.vnxeCommandFailed("Could not find file system in the vnxe for: " + fsId);
    }
    String resourceId = fs.getStorageResource().getId();
    ModifyFileSystemParam modifyFSParm = new ModifyFileSystemParam();
    List<VNXeBase> roHosts = getHosts(roEndpoints);
    List<VNXeBase> rwHosts = getHosts(rwEndpoints);
    List<VNXeBase> rootHosts = getHosts(rootEndpoints);
    VNXeNfsShare nfsShareFound = null;
    if (shareName != null) {
        nfsShareFound = findNfsShare(fsId, shareName);
    } else {
        nfsShareFound = getNfsShareById(shareId);
    }
    String nfsShareId = null;
    List<VNXeBase> hosts = new ArrayList<VNXeBase>();
    if (nfsShareFound != null) {
        nfsShareId = nfsShareFound.getId();
    }
    NfsShareParam shareParm = new NfsShareParam();
    shareParm.setReadOnlyHosts(roHosts);
    shareParm.setReadWriteHosts(rwHosts);
    shareParm.setRootAccessHosts(rootHosts);
    if (comments != null) {
        shareParm.setDescription(comments);
    }
    if (access == null) {
        if (nfsShareFound != null) {
            hosts.addAll(nfsShareFound.getNoAccessHosts());
            hosts.addAll(nfsShareFound.getRootAccessHosts());
            hosts.addAll(nfsShareFound.getReadWriteHosts());
            hosts.addAll(nfsShareFound.getReadOnlyHosts());
        }
        NFSShareDefaultAccessEnum nfsShareDefaultAccess = NFSShareDefaultAccessEnum.NONE;
        if (nfsShareFound != null) {
            nfsShareDefaultAccess = nfsShareFound.getDefaultAccess();
        }
        if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.ROOT)) {
            if (!hosts.isEmpty()) {
                shareParm.setRootAccessHosts(hosts);
            } else {
                shareParm.setRootAccessHosts(null);
            }
            shareParm.setNoAccessHosts(null);
            shareParm.setReadWriteHosts(null);
            shareParm.setReadOnlyHosts(null);
        } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READONLY)) {
            if (!hosts.isEmpty()) {
                shareParm.setReadOnlyHosts(hosts);
            } else {
                shareParm.setReadOnlyHosts(null);
            }
            shareParm.setNoAccessHosts(null);
            shareParm.setReadWriteHosts(null);
            shareParm.setRootAccessHosts(null);
        } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READWRITE)) {
            if (!hosts.isEmpty()) {
                shareParm.setReadWriteHosts(hosts);
            } else {
                shareParm.setReadWriteHosts(null);
            }
            shareParm.setNoAccessHosts(null);
            shareParm.setReadOnlyHosts(null);
            shareParm.setRootAccessHosts(null);
        } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.NONE)) {
            if (!hosts.isEmpty()) {
                shareParm.setNoAccessHosts(hosts);
            } else {
                shareParm.setNoAccessHosts(null);
            }
            shareParm.setReadWriteHosts(null);
            shareParm.setReadOnlyHosts(null);
            shareParm.setRootAccessHosts(null);
        }
    }
    if (nfsShareId == null) {
        // not found, new export
        if (!isUnityClient()) {
            shareParm.setDefaultAccess(NFSShareDefaultAccessEnum.NONE);
        }
        NfsShareCreateParam nfsShareCreateParm = new NfsShareCreateParam();
        nfsShareCreateParm.setName(shareName);
        nfsShareCreateParm.setPath(path);
        nfsShareCreateParm.setNfsShareParameters(shareParm);
        List<NfsShareCreateParam> nfsList = new ArrayList<NfsShareCreateParam>();
        nfsList.add(nfsShareCreateParm);
        modifyFSParm.setNfsShareCreate(nfsList);
    } else {
        // update export
        NfsShareModifyParam nfsShareModifyParam = new NfsShareModifyParam();
        VNXeBase nfsShare = new VNXeBase();
        nfsShare.setId(nfsShareId);
        nfsShareModifyParam.setNfsShare(nfsShare);
        nfsShareModifyParam.setNfsShareParameters(shareParm);
        List<NfsShareModifyParam> nfsModifyList = new ArrayList<NfsShareModifyParam>();
        nfsModifyList.add(nfsShareModifyParam);
        modifyFSParm.setNfsShareModify(nfsModifyList);
    }
    FileSystemActionRequest req = new FileSystemActionRequest(_khClient);
    return req.modifyFileSystemAsync(modifyFSParm, resourceId);
}
Also used : VNXeFileSystem(com.emc.storageos.vnxe.models.VNXeFileSystem) NFSShareDefaultAccessEnum(com.emc.storageos.vnxe.models.NfsShareParam.NFSShareDefaultAccessEnum) ArrayList(java.util.ArrayList) NfsShareCreateParam(com.emc.storageos.vnxe.models.NfsShareCreateParam) NfsShareModifyParam(com.emc.storageos.vnxe.models.NfsShareModifyParam) FileSystemRequest(com.emc.storageos.vnxe.requests.FileSystemRequest) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) NfsShareParam(com.emc.storageos.vnxe.models.NfsShareParam) ModifyFileSystemParam(com.emc.storageos.vnxe.models.ModifyFileSystemParam) FileSystemActionRequest(com.emc.storageos.vnxe.requests.FileSystemActionRequest)

Example 44 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class VNXeApiClient method createNfsShareForSnap.

/**
 * Create Nfs share for snapshot
 *
 * @param snapId
 *            snapshot id
 * @param endpoints
 *            hosts
 * @param access
 *            READ, WRITE, ROOT
 * @param path
 * @param exportKey
 * @return VNXeCommandJob
 * @throws VNXeException
 */
public VNXeCommandJob createNfsShareForSnap(String snapId, List<String> roEndpoints, List<String> rwEndpoints, List<String> rootEndpoints, AccessEnum access, String path, String shareName, String comments) throws VNXeException {
    _logger.info("creating nfs share for the snap: " + snapId);
    NfsShareRequests request = new NfsShareRequests(_khClient);
    String softwareVersion = getBasicSystemInfo().getSoftwareVersion();
    FileSystemSnapRequests req = new FileSystemSnapRequests(_khClient, softwareVersion);
    VNXeFileSystemSnap snapshot = req.getFileSystemSnap(snapId, softwareVersion);
    if (snapshot == null) {
        _logger.info("Could not find snapshot in the vxne");
        throw VNXeException.exceptions.vnxeCommandFailed("Could not find snapshot in the vnxe for: " + snapId);
    }
    NfsShareCreateForSnapParam nfsCreateParam = new NfsShareCreateForSnapParam();
    VNXeBase snap = new VNXeBase(snapId);
    if (!VNXeUtils.isHigherVersion(softwareVersion, VNXeConstants.VNXE_BASE_SOFT_VER)) {
        nfsCreateParam.setFilesystemSnap(snap);
    } else {
        nfsCreateParam.setSnap(snap);
    }
    List<VNXeBase> roHosts = getHosts(roEndpoints);
    List<VNXeBase> rwHosts = getHosts(rwEndpoints);
    List<VNXeBase> rootHosts = getHosts(rootEndpoints);
    VNXeCommandJob job = null;
    VNXeNfsShare nfsShareFound = request.findSnapNfsShare(snapId, shareName, softwareVersion);
    if (nfsShareFound == null) {
        // new export
        nfsCreateParam.setReadOnlyHosts(roHosts);
        nfsCreateParam.setReadWriteHosts(rwHosts);
        nfsCreateParam.setRootAccessHosts(rootHosts);
        nfsCreateParam.setName(shareName);
        nfsCreateParam.setPath(path);
        if (comments != null) {
            nfsCreateParam.setDescription(comments);
        }
        request.unsetQueryParameters();
        job = request.createShareForSnapshot(nfsCreateParam);
    } else {
        String nfsShareId = nfsShareFound.getId();
        NFSShareDefaultAccessEnum nfsShareDefaultAccess = nfsShareFound.getDefaultAccess();
        NfsShareModifyForShareParam nfsModifyParam = new NfsShareModifyForShareParam();
        List<VNXeBase> hosts = new ArrayList<VNXeBase>();
        nfsModifyParam.setReadOnlyHosts(roHosts);
        nfsModifyParam.setReadWriteHosts(rwHosts);
        nfsModifyParam.setRootAccessHosts(rootHosts);
        if (comments != null) {
            nfsModifyParam.setDescription(comments);
        }
        if (access == null) {
            if (nfsShareFound != null) {
                hosts.addAll(nfsShareFound.getNoAccessHosts());
                hosts.addAll(nfsShareFound.getRootAccessHosts());
                hosts.addAll(nfsShareFound.getReadWriteHosts());
                hosts.addAll(nfsShareFound.getReadOnlyHosts());
            }
            if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.ROOT)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setRootAccessHosts(hosts);
                } else {
                    nfsModifyParam.setRootAccessHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READONLY)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setReadOnlyHosts(hosts);
                } else {
                    nfsModifyParam.setReadOnlyHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READWRITE)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setReadWriteHosts(hosts);
                } else {
                    nfsModifyParam.setReadWriteHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.NONE)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setNoAccessHosts(hosts);
                } else {
                    nfsModifyParam.setNoAccessHosts(null);
                }
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            }
        }
        request.unsetQueryParameters();
        job = request.modifyShareForSnapshot(nfsShareId, nfsModifyParam);
    }
    return job;
}
Also used : VNXeFileSystemSnap(com.emc.storageos.vnxe.models.VNXeFileSystemSnap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileSystemSnapRequests(com.emc.storageos.vnxe.requests.FileSystemSnapRequests) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) NfsShareRequests(com.emc.storageos.vnxe.requests.NfsShareRequests) NFSShareDefaultAccessEnum(com.emc.storageos.vnxe.models.NfsShareParam.NFSShareDefaultAccessEnum) NfsShareModifyForShareParam(com.emc.storageos.vnxe.models.NfsShareModifyForShareParam) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) ArrayList(java.util.ArrayList) NfsShareCreateForSnapParam(com.emc.storageos.vnxe.models.NfsShareCreateForSnapParam)

Example 45 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class VNXeApiClient method removeLunsFromConsistencyGroup.

/**
 * Remove luns from the consistency group
 *
 * @param cgId
 *            lun group id
 * @param luns
 *            list of lun IDs
 * @return
 */
public VNXeCommandResult removeLunsFromConsistencyGroup(String cgId, List<String> luns) {
    LunGroupModifyParam param = new LunGroupModifyParam();
    List<LunAddParam> lunRemoves = new ArrayList<LunAddParam>();
    for (String lunId : luns) {
        VNXeBase lun = new VNXeBase(lunId);
        LunAddParam lunAdd = new LunAddParam();
        lunAdd.setLun(lun);
        lunRemoves.add(lunAdd);
    }
    param.setLunRemove(lunRemoves);
    ConsistencyGroupRequests req = new ConsistencyGroupRequests(_khClient);
    return req.modifyConsistencyGroupSync(cgId, param);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunAddParam(com.emc.storageos.vnxe.models.LunAddParam) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ArrayList(java.util.ArrayList) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)

Aggregations

VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)71 ArrayList (java.util.ArrayList)39 URI (java.net.URI)17 HashMap (java.util.HashMap)14 LunGroupModifyParam (com.emc.storageos.vnxe.models.LunGroupModifyParam)13 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)12 VNXeHostInitiator (com.emc.storageos.vnxe.models.VNXeHostInitiator)11 HashSet (java.util.HashSet)11 List (java.util.List)11 StoragePort (com.emc.storageos.db.client.model.StoragePort)9 VNXeException (com.emc.storageos.vnxe.VNXeException)9 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)9 ConsistencyGroupRequests (com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)9 LunGroupRequests (com.emc.storageos.vnxe.requests.LunGroupRequests)9 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)8 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)8 LunParam (com.emc.storageos.vnxe.models.LunParam)8 ModifyFileSystemParam (com.emc.storageos.vnxe.models.ModifyFileSystemParam)8 Initiator (com.emc.storageos.db.client.model.Initiator)7 VNXeHost (com.emc.storageos.vnxe.models.VNXeHost)7