Search in sources :

Example 1 with HostCreateParam

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

the class VNXeApiClient method deleteInitiators.

/**
 * Delete initiators by moving initiators to a dummy host, then delete the dummy host
 *
 * This should be used if there is mapped resource on the host that the initiators are registered to.
 * It can also be used in case of no mapped resource.
 *
 * @param initiatorIds initiator Ids (IQN or WWN)
 * @return VNXeCommandResult
 */
public VNXeCommandResult deleteInitiators(List<String> initiatorIds) throws VNXeException {
    _logger.info("deleting initiators: " + Joiner.on(',').join(initiatorIds));
    // create a dummy host
    HostListRequest hostListReq = new HostListRequest(_khClient);
    HostCreateParam hostCreateParm = new HostCreateParam();
    hostCreateParm.setName(VIPR_TMP_HOST_PREFIX + initiatorIds.get(0));
    hostCreateParm.setType(HostTypeEnum.HOSTMANUAL.getValue());
    VNXeCommandResult result = hostListReq.createHost(hostCreateParm);
    String dummyHostId = result.getId();
    // get initiators
    for (String initiatorId : initiatorIds) {
        VNXeHostInitiator initiator = getInitiatorByWWN(initiatorId);
        if (initiator == null) {
            _logger.info("Could not find initiator: {}", initiatorId);
        } else {
            // move the initiator to the dummy host
            setInitiatorHost(initiator.getId(), dummyHostId);
        }
    }
    // delete the dummy host
    return deleteHost(dummyHostId);
}
Also used : HostListRequest(com.emc.storageos.vnxe.requests.HostListRequest) HostCreateParam(com.emc.storageos.vnxe.models.HostCreateParam) VNXeCommandResult(com.emc.storageos.vnxe.models.VNXeCommandResult) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator)

Example 2 with HostCreateParam

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

use of com.emc.storageos.vnxe.models.HostCreateParam 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)

Example 4 with HostCreateParam

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

the class HostListRequestTest method createHostTest.

@Test
public void createHostTest() {
    HostListRequest req = new HostListRequest(_client);
    HostCreateParam parm = new HostCreateParam();
    parm.setName("test-host-1");
    parm.setType(HostTypeEnum.HOSTMANUAL.getValue());
    VNXeCommandResult result = req.createHost(parm);
    String id = result.getId();
    System.out.println(id);
}
Also used : HostCreateParam(com.emc.storageos.vnxe.models.HostCreateParam) VNXeCommandResult(com.emc.storageos.vnxe.models.VNXeCommandResult) Test(org.junit.Test)

Aggregations

HostCreateParam (com.emc.storageos.vnxe.models.HostCreateParam)4 VNXeCommandResult (com.emc.storageos.vnxe.models.VNXeCommandResult)4 HostListRequest (com.emc.storageos.vnxe.requests.HostListRequest)3 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)2 VNXeHostInitiator (com.emc.storageos.vnxe.models.VNXeHostInitiator)2 HostInitiatorCreateParam (com.emc.storageos.vnxe.models.HostInitiatorCreateParam)1 HostIpPortCreateParam (com.emc.storageos.vnxe.models.HostIpPortCreateParam)1 VNXeHostIpPort (com.emc.storageos.vnxe.models.VNXeHostIpPort)1 DeleteHostInitiatorRequest (com.emc.storageos.vnxe.requests.DeleteHostInitiatorRequest)1 HostInitiatorRequest (com.emc.storageos.vnxe.requests.HostInitiatorRequest)1 HostIpPortRequests (com.emc.storageos.vnxe.requests.HostIpPortRequests)1 UnknownHostException (java.net.UnknownHostException)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1