Search in sources :

Example 1 with HostIpPortCreateParam

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

the class HostIpPortRequestsTest method createHostIpPortTest.

@Test
public void createHostIpPortTest() {
    HostIpPortRequests req = new HostIpPortRequests(_client);
    HostIpPortCreateParam parm = new HostIpPortCreateParam();
    parm.setAddress("10.247.87.208");
    VNXeBase host = new VNXeBase();
    host.setId("Host_1");
    parm.setHost(host);
    VNXeCommandResult result = req.createHostIpPort(parm);
    String id = result.getId();
    System.out.println(id);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeCommandResult(com.emc.storageos.vnxe.models.VNXeCommandResult) HostIpPortCreateParam(com.emc.storageos.vnxe.models.HostIpPortCreateParam) Test(org.junit.Test)

Example 2 with HostIpPortCreateParam

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

HostIpPortCreateParam (com.emc.storageos.vnxe.models.HostIpPortCreateParam)2 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)2 VNXeCommandResult (com.emc.storageos.vnxe.models.VNXeCommandResult)2 HostCreateParam (com.emc.storageos.vnxe.models.HostCreateParam)1 VNXeHostIpPort (com.emc.storageos.vnxe.models.VNXeHostIpPort)1 HostIpPortRequests (com.emc.storageos.vnxe.requests.HostIpPortRequests)1 HostListRequest (com.emc.storageos.vnxe.requests.HostListRequest)1 UnknownHostException (java.net.UnknownHostException)1 Test (org.junit.Test)1