Search in sources :

Example 51 with VNXeBase

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

the class VNXUnityArrayAffinityDiscoverer method findHostURI.

/**
 * Find host URI from host initiators on array
 *
 * @param initiators
 * @param apiClient
 * @param dbClient
 * @return host URI or null
 */
private URI findHostURI(List<VNXeBase> initiators, VNXeApiClient apiClient, DbClient dbClient) {
    if (initiators != null && !initiators.isEmpty()) {
        for (VNXeBase init : initiators) {
            VNXeHostInitiator vnxeInitiator = apiClient.getHostInitiator(init.getId());
            String portwwn = vnxeInitiator.getPortWWN();
            if (HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI.equals(vnxeInitiator.getType())) {
                portwwn = vnxeInitiator.getInitiatorId();
            }
            if (portwwn == null || portwwn.isEmpty()) {
                continue;
            }
            Initiator initiator = NetworkUtil.getInitiator(portwwn, dbClient);
            if (initiator != null && !initiator.getInactive()) {
                URI hostURI = initiator.getHost();
                if (!NullColumnValueGetter.isNullURI(hostURI)) {
                    return hostURI;
                }
            }
        }
    }
    return null;
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI)

Example 52 with VNXeBase

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

the class VNXeApiClient method unexportSnap.

/**
 * Unexport a snapshot
 *
 * @param hostId - The host id
 * @param snapId - The snap id
 */
public void unexportSnap(String hostId, String snapId) {
    _logger.info("Unexporting snap: {}", snapId);
    String parentLunId = null;
    String groupId = null;
    boolean detach = false;
    if (!_khClient.isUnity()) {
        VNXeLunSnap lunSnap = getLunSnapshot(snapId);
        if (lunSnap == null) {
            _logger.info("Could not find lun snap in the vxne: {}", snapId);
            throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun snap: " + snapId);
        }
        if (lunSnap.getIsAttached()) {
            _logger.info("Detaching the snap: {}", snapId);
            detachLunSnap(snapId);
            detach = true;
        }
        parentLunId = lunSnap.getLun().getId();
    } else {
        Snap snap = getSnapshot(snapId);
        if (snap == null) {
            _logger.info("Could not find snap in the vxn unity: {}", snapId);
            throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun snap: " + snapId);
        }
        VNXeBase snapGroup = snap.getSnapGroup();
        parentLunId = snap.getLun().getId();
        if (snapGroup == null && (snap.isAttached())) {
            _logger.info("Detaching the snap: {}", snapId);
            detachSnap(snapId);
            detach = true;
        } else if (snapGroup != null && snap.isAttached()) {
            _logger.info("Detaching the snap: {}", snapId);
            groupId = snapGroup.getId();
            detachSnap(groupId);
            detach = true;
        }
    }
    VNXeLun parentLun = getLun(parentLunId);
    List<BlockHostAccess> hostAccesses = parentLun.getHostAccess();
    if (hostAccesses == null || hostAccesses.isEmpty()) {
        _logger.info("No block host access found for the snap: {}", snapId);
        return;
    }
    List<BlockHostAccess> changedHostAccessList = new ArrayList<BlockHostAccess>();
    /*
         * we have to detach the snap in order to unexport any host. we need to reattach the snap
         * after the unexport if the snap is still exported to any other hosts.
         */
    boolean needReattach = false;
    for (BlockHostAccess hostAccess : hostAccesses) {
        int accessMask = hostAccess.getAccessMask();
        if (hostId.equals(hostAccess.getHost().getId())) {
            if (accessMask == HostLUNAccessEnum.BOTH.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.PRODUCTION.getValue());
            } else if (accessMask == HostLUNAccessEnum.SNAPSHOT.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.NOACCESS.getValue());
            }
        } else if (detach && !needReattach && (accessMask == HostLUNAccessEnum.BOTH.getValue() || accessMask == HostLUNAccessEnum.SNAPSHOT.getValue())) {
            needReattach = true;
        }
        changedHostAccessList.add(hostAccess);
    }
    if (changedHostAccessList.isEmpty()) {
        // the removing hosts are not exported
        _logger.info("The unexport hosts were not exported.");
        return;
    }
    if (!needReattach && detach && groupId != null) {
        // Check if there are other exported snaps in the snap group
        String cgId = parentLun.getStorageResource().getId();
        if (cgId != null && !cgId.isEmpty()) {
            BlockLunRequests lunReq = new BlockLunRequests(_khClient);
            List<VNXeLun> luns = lunReq.getLunsInLunGroup(cgId);
            for (VNXeLun cgLun : luns) {
                if (cgLun.getId().equals(parentLun.getId())) {
                    continue;
                }
                List<BlockHostAccess> hostAccess = cgLun.getHostAccess();
                if (hostAccess == null) {
                    continue;
                }
                for (BlockHostAccess hostA : hostAccess) {
                    int mask = hostA.getAccessMask();
                    if (mask == HostLUNAccessEnum.BOTH.getValue() || mask == HostLUNAccessEnum.SNAPSHOT.getValue()) {
                        needReattach = true;
                        break;
                    }
                }
                if (needReattach) {
                    break;
                }
            }
        } else {
            _logger.warn(String.format("The storage resource id is empty for the lun ", parentLun.getName()));
        }
    }
    LunParam lunParam = new LunParam();
    lunParam.setHostAccess(changedHostAccessList);
    LunModifyParam modifyParam = new LunModifyParam();
    modifyParam.setLunParameters(lunParam);
    int type = parentLun.getType();
    if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
        // if standalone lun
        BlockLunRequests lunReq = new BlockLunRequests(_khClient);
        lunReq.modifyLunSync(modifyParam, parentLun.getStorageResource().getId());
    } else {
        // lun in a lun group
        modifyParam.setLun(new VNXeBase(parentLun.getId()));
        List<LunModifyParam> list = new ArrayList<LunModifyParam>();
        list.add(modifyParam);
        LunGroupModifyParam groupParam = new LunGroupModifyParam();
        groupParam.setLunModify(list);
        if (!_khClient.isUnity()) {
            LunGroupRequests lunGroupReq = new LunGroupRequests(_khClient);
            lunGroupReq.modifyLunGroupSync(parentLun.getStorageResource().getId(), groupParam);
        } else {
            ConsistencyGroupRequests cgReq = new ConsistencyGroupRequests(_khClient);
            cgReq.modifyConsistencyGroupSync(parentLun.getStorageResource().getId(), groupParam);
        }
    }
    if (needReattach) {
        if (!_khClient.isUnity()) {
            attachLunSnap(snapId);
        } else {
            if (groupId == null) {
                attachSnap(snapId);
            } else {
                attachSnap(groupId);
            }
        }
    }
    _logger.info("Done unexporting lun: {}", snapId);
}
Also used : ArrayList(java.util.ArrayList) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeFileSystemSnap(com.emc.storageos.vnxe.models.VNXeFileSystemSnap) VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) Snap(com.emc.storageos.vnxe.models.Snap) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunParam(com.emc.storageos.vnxe.models.LunParam) BlockLunRequests(com.emc.storageos.vnxe.requests.BlockLunRequests) LunGroupRequests(com.emc.storageos.vnxe.requests.LunGroupRequests) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) HostLunModifyParam(com.emc.storageos.vnxe.models.HostLunModifyParam) LunModifyParam(com.emc.storageos.vnxe.models.LunModifyParam)

Example 53 with VNXeBase

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

the class VNXeApiClient method createFileSystem.

/**
 * create file system
 *
 * @param fsName
 *            file system name.
 * @param size
 *            size in byte.
 * @param poolId
 *            pool id.
 * @param nasServerId
 *            nasServer id.
 * @param isThin
 *            is thin enabled.
 * @param supportedProtocols
 * @return VNXeCommandJob
 * @throws VNXeException
 */
public VNXeCommandJob createFileSystem(String fsName, long size, String poolId, String nasServerId, boolean isThin, VNXeFSSupportedProtocolEnum supportedProtocols) throws VNXeException {
    _logger.info("Creating file system:" + fsName);
    CreateFileSystemParam parm = new CreateFileSystemParam();
    parm.setName(fsName);
    FileSystemParam fsParm = new FileSystemParam();
    fsParm.setIsThinEnabled(isThin);
    VNXeBase nasServer = new VNXeBase();
    nasServer.setId(nasServerId);
    fsParm.setNasServer(nasServer);
    VNXeBase pool = new VNXeBase();
    pool.setId(poolId);
    fsParm.setPool(pool);
    fsParm.setSize(size);
    fsParm.setSupportedProtocols(supportedProtocols.getValue());
    parm.setFsParameters(fsParm);
    FileSystemActionRequest req = new FileSystemActionRequest(_khClient);
    _logger.info("submitted the create file system job for " + fsName);
    return req.createFileSystemAsync(parm);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) FileSystemParam(com.emc.storageos.vnxe.models.FileSystemParam) ModifyFileSystemParam(com.emc.storageos.vnxe.models.ModifyFileSystemParam) CreateFileSystemParam(com.emc.storageos.vnxe.models.CreateFileSystemParam) CreateFileSystemParam(com.emc.storageos.vnxe.models.CreateFileSystemParam) FileSystemActionRequest(com.emc.storageos.vnxe.requests.FileSystemActionRequest)

Example 54 with VNXeBase

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

the class VNXeApiClient method deleteLunsFromLunGroup.

/**
 * Delete luns from lun group
 *
 * @param lunGroupId
 * @param luns
 * @return
 */
public VNXeCommandJob deleteLunsFromLunGroup(String lunGroupId, List<String> luns) {
    LunGroupModifyParam param = new LunGroupModifyParam();
    List<LunAddParam> lunDelete = new ArrayList<LunAddParam>();
    for (String lunId : luns) {
        VNXeBase lun = new VNXeBase(lunId);
        LunAddParam lunAdd = new LunAddParam();
        lunAdd.setLun(lun);
        lunDelete.add(lunAdd);
    }
    param.setLunDelete(lunDelete);
    LunGroupRequests req = new LunGroupRequests(_khClient);
    return req.modifyLunGroupAsync(lunGroupId, param);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunAddParam(com.emc.storageos.vnxe.models.LunAddParam) LunGroupRequests(com.emc.storageos.vnxe.requests.LunGroupRequests) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ArrayList(java.util.ArrayList)

Example 55 with VNXeBase

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

the class VNXeApiClient method getHosts.

/**
 * get list host instances based on the endpoints
 *
 * @param endpoints
 *            ipAddress, hostname or subnet
 * @return List of host instances
 * @throws VNXeException
 */
private List<VNXeBase> getHosts(List<String> endpoints) throws VNXeException {
    List<VNXeBase> hosts = null;
    if (endpoints != null) {
        hosts = new ArrayList<VNXeBase>();
        for (String endpoint : endpoints) {
            String ipAddress = null;
            boolean isSubnet = false;
            String netMask = null;
            boolean isValid = true;
            try {
                if (VNXeUtils.isHostType(endpoint)) {
                    ipAddress = VNXeUtils.getHostIp(endpoint);
                } else if (VNXeUtils.isIPV4Type(endpoint) || VNXeUtils.isIPV6Type(endpoint)) {
                    ipAddress = endpoint;
                } else {
                    // check if subnet
                    String[] ends = endpoint.split("/");
                    if (ends != null && ends.length == 2) {
                        ipAddress = ends[0];
                        endpoint = ipAddress;
                        String mask = ends[1];
                        try {
                            // CIDR format?
                            int cidr = Integer.parseInt(mask);
                            netMask = VNXeUtils.convertCIDRToNetmask(cidr);
                            isSubnet = true;
                        } catch (NumberFormatException e) {
                            if (VNXeUtils.isIPV4Type(mask) || VNXeUtils.isIPV6Type(mask)) {
                                netMask = mask;
                                isSubnet = true;
                            } else {
                                isValid = false;
                            }
                        }
                    } else {
                        isValid = false;
                    }
                }
            } catch (UnknownHostException e) {
                _logger.error("Could not resolve the host: " + endpoint);
                throw VNXeException.exceptions.vnxeCommandFailed("Could not resolve the host: " + endpoint);
            }
            if (!isValid) {
                _logger.error("Unsupported endpoint type: " + endpoint);
                throw VNXeException.exceptions.vnxeCommandFailed("Unsupported endpoint type: " + endpoint);
            }
            HostIpPortRequests ipReq = new HostIpPortRequests(_khClient);
            VNXeHostIpPort ipPort = ipReq.getIpPortByIpAddress(ipAddress);
            VNXeBase host = null;
            if (ipPort != null) {
                // HostIPPort found
                host = ipPort.getHost();
                hosts.add(host);
            } else {
                // create host and ipPort
                HostListRequest hostReq = new HostListRequest(_khClient);
                HostCreateParam hostCreateParm = new HostCreateParam();
                hostCreateParm.setName(endpoint);
                if (isSubnet) {
                    hostCreateParm.setType(HostTypeEnum.SUBNET.getValue());
                } else {
                    hostCreateParm.setType(HostTypeEnum.HOSTMANUAL.getValue());
                }
                VNXeCommandResult result = hostReq.createHost(hostCreateParm);
                String hostId = result.getId();
                if (hostId != null) {
                    HostIpPortRequests ipReq2 = new HostIpPortRequests(_khClient);
                    HostIpPortCreateParam ipCreateParm = new HostIpPortCreateParam();
                    host = new VNXeBase(hostId);
                    ipCreateParm.setHost(host);
                    ipCreateParm.setAddress(ipAddress);
                    if (isSubnet) {
                        ipCreateParm.setSubnetMask(netMask);
                    }
                    ipReq2.createHostIpPort(ipCreateParm);
                    hosts.add(host);
                }
            }
        }
    }
    return hosts;
}
Also used : UnknownHostException(java.net.UnknownHostException) HostListRequest(com.emc.storageos.vnxe.requests.HostListRequest) HostIpPortCreateParam(com.emc.storageos.vnxe.models.HostIpPortCreateParam) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) HostIpPortRequests(com.emc.storageos.vnxe.requests.HostIpPortRequests) HostCreateParam(com.emc.storageos.vnxe.models.HostCreateParam) VNXeCommandResult(com.emc.storageos.vnxe.models.VNXeCommandResult) VNXeHostIpPort(com.emc.storageos.vnxe.models.VNXeHostIpPort)

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