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;
}
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());
}
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());
}
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());
}
Aggregations