Search in sources :

Example 1 with Pool

use of org.onap.so.openstack.beans.Pool in project so by onap.

the class MsoNetworkAdapterImpl method mergeSubnets.

private String mergeSubnets(String heatTemplate, List<Subnet> subnets) throws MsoException {
    String resourceTempl = "  subnet_%subnetId%:\n" + "    type: OS::Neutron::Subnet\n" + "    properties:\n" + "      name: %name%\n" + "      network_id: { get_resource: network }\n" + "      cidr: %cidr%\n";
    /*
         * make these optional + "      ip_version: %ipversion%\n" + "      enable_dhcp: %enabledhcp%\n" +
         * "      gateway_ip: %gatewayip%\n" + "      allocation_pools:\n" + "       - start: %poolstart%\n" +
         * "         end: %poolend%\n";
         *
         */
    String outputTempl = "  subnet_id_%subnetId%:\n" + "    description: Openstack subnet identifier\n" + "    value: {get_resource: subnet_%subnetId%}\n";
    String curR;
    String curO;
    StringBuilder resourcesBuf = new StringBuilder();
    StringBuilder outputsBuf = new StringBuilder();
    for (Subnet subnet : subnets) {
        // build template for each subnet
        curR = resourceTempl;
        if (subnet.getSubnetId() != null) {
            curR = curR.replace("%subnetId%", subnet.getSubnetId());
        } else {
            String error = "Missing Required AAI SubnetId for subnet in HEAT Template";
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
            throw new MsoAdapterException(error);
        }
        if (subnet.getSubnetName() != null) {
            curR = curR.replace("%name%", subnet.getSubnetName());
        } else {
            curR = curR.replace("%name%", subnet.getSubnetId());
        }
        if (subnet.getCidr() != null) {
            curR = curR.replace("%cidr%", subnet.getCidr());
        } else {
            String error = "Missing Required cidr for subnet in HEAT Template";
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
            throw new MsoAdapterException(error);
        }
        if (subnet.getIpVersion() != null) {
            curR = curR + "      ip_version: " + subnet.getIpVersion() + "\n";
        }
        if (subnet.getEnableDHCP() != null) {
            curR = curR + "      enable_dhcp: " + Boolean.toString(subnet.getEnableDHCP()) + "\n";
        }
        if (subnet.getGatewayIp() != null && !subnet.getGatewayIp().isEmpty()) {
            curR = curR + "      gateway_ip: " + subnet.getGatewayIp() + "\n";
        }
        if (subnet.getAllocationPools() != null) {
            StringBuilder tempBuf = new StringBuilder();
            tempBuf.append(curR);
            tempBuf.append("      allocation_pools:\n");
            for (Pool pool : subnet.getAllocationPools()) {
                if (!commonUtils.isNullOrEmpty(pool.getStart()) && !commonUtils.isNullOrEmpty(pool.getEnd())) {
                    tempBuf.append("       - start: ");
                    tempBuf.append(pool.getStart());
                    tempBuf.append("\n         end: ");
                    tempBuf.append(pool.getEnd());
                    tempBuf.append("\n");
                }
            }
            curR = tempBuf.toString();
        }
        resourcesBuf.append(curR);
        curO = outputTempl;
        curO = curO.replace("%subnetId%", subnet.getSubnetId());
        outputsBuf.append(curO);
    }
    // append resources and outputs in heatTemplate
    logger.debug("Tempate initial:{}", heatTemplate);
    int outputsIdx = heatTemplate.indexOf("outputs:");
    heatTemplate = insertStr(heatTemplate, outputsBuf.toString(), outputsIdx + 8);
    int resourcesIdx = heatTemplate.indexOf("resources:");
    heatTemplate = insertStr(heatTemplate, resourcesBuf.toString(), resourcesIdx + 10);
    logger.debug("Template updated with all subnets:{}", heatTemplate);
    return heatTemplate;
}
Also used : MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) Pool(org.onap.so.openstack.beans.Pool) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet)

Example 2 with Pool

use of org.onap.so.openstack.beans.Pool in project so by onap.

the class ContrailSubnetMappersTest method contrailSubnetPoolMapperTest.

@Test
public void contrailSubnetPoolMapperTest() {
    Pool pool = new Pool();
    pool.setStart("start");
    pool.setEnd("end");
    ContrailSubnetPoolMapper mapper = new ContrailSubnetPoolMapper(pool);
    ContrailSubnetPool csPool = mapper.map();
    assertEquals("start", csPool.getStart());
    assertEquals("end", csPool.getEnd());
}
Also used : ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) Pool(org.onap.so.openstack.beans.Pool) Test(org.junit.Test)

Example 3 with Pool

use of org.onap.so.openstack.beans.Pool in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetPoolInvalidTest.

@Test
public void createContrailSubnetPoolInvalidTest() {
    List<Pool> pools = new ArrayList<>();
    Pool pool1 = new Pool();
    pool1.setStart("start1");
    pool1.setEnd("end1");
    Pool pool2 = new Pool();
    pool2.setStart("start2");
    pools.add(pool1);
    pools.add(pool2);
    Subnet subnet = new Subnet();
    subnet.setAllocationPools(pools);
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    List<ContrailSubnetPool> cspools = result.getAllocationPools();
    assertEquals(1, cspools.size());
    assertEquals("start1", cspools.get(0).getStart());
    assertEquals("end1", cspools.get(0).getEnd());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) ArrayList(java.util.ArrayList) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) Pool(org.onap.so.openstack.beans.Pool) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Example 4 with Pool

use of org.onap.so.openstack.beans.Pool in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetPoolTest.

@Test
public void createContrailSubnetPoolTest() {
    List<Pool> pools = new ArrayList<>();
    Pool pool1 = new Pool();
    pool1.setStart("start1");
    pool1.setEnd("end1");
    Pool pool2 = new Pool();
    pool2.setStart("start2");
    pool2.setEnd("end2");
    pools.add(pool1);
    pools.add(pool2);
    Subnet subnet = new Subnet();
    subnet.setAllocationPools(pools);
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    List<ContrailSubnetPool> cspools = result.getAllocationPools();
    assertEquals(2, cspools.size());
    assertEquals("start2", cspools.get(1).getStart());
    assertEquals("end2", cspools.get(1).getEnd());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) ArrayList(java.util.ArrayList) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) Pool(org.onap.so.openstack.beans.Pool) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Aggregations

Pool (org.onap.so.openstack.beans.Pool)4 Test (org.junit.Test)3 ContrailSubnet (org.onap.so.adapters.network.beans.ContrailSubnet)3 ContrailSubnetPool (org.onap.so.adapters.network.beans.ContrailSubnetPool)3 Subnet (org.onap.so.openstack.beans.Subnet)3 ArrayList (java.util.ArrayList)2 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)1