Search in sources :

Example 1 with VNXeHostIpPort

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

the class HostIpPortRequestsTest method getIpPortTest.

// @Test
public void getIpPortTest() {
    HostIpPortRequests req = new HostIpPortRequests(_client);
    VNXeHostIpPort ipPort = req.getIpPortByIpAddress("1.1.1.1");
    if (ipPort == null) {
        System.out.println("could not found the ip");
    }
}
Also used : VNXeHostIpPort(com.emc.storageos.vnxe.models.VNXeHostIpPort)

Example 2 with VNXeHostIpPort

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

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

the class HostIpPortRequests method getIpPortByIpAddress.

/**
 * Get HostIpPort by ipaddress
 *
 * @param address
 * @return
 */
public VNXeHostIpPort getIpPortByIpAddress(String address) {
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(VNXeConstants.FILTER, VNXeConstants.IPADDRESS_FILTER + "\"" + address + "\"");
    setQueryParameters(queryParams);
    VNXeHostIpPort result = null;
    List<VNXeHostIpPort> ipPortList = getDataForObjects(VNXeHostIpPort.class);
    // it should just return 1
    if (ipPortList != null && !ipPortList.isEmpty()) {
        result = ipPortList.get(0);
    } else {
        _logger.info("No hostIpPort found using the address: " + address);
    }
    return result;
}
Also used : MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) VNXeHostIpPort(com.emc.storageos.vnxe.models.VNXeHostIpPort)

Aggregations

VNXeHostIpPort (com.emc.storageos.vnxe.models.VNXeHostIpPort)3 HostCreateParam (com.emc.storageos.vnxe.models.HostCreateParam)1 HostIpPortCreateParam (com.emc.storageos.vnxe.models.HostIpPortCreateParam)1 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)1 VNXeCommandResult (com.emc.storageos.vnxe.models.VNXeCommandResult)1 HostIpPortRequests (com.emc.storageos.vnxe.requests.HostIpPortRequests)1 HostListRequest (com.emc.storageos.vnxe.requests.HostListRequest)1 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)1 UnknownHostException (java.net.UnknownHostException)1