use of org.onap.so.openstack.beans.Subnet in project so by onap.
the class NetworkAdapterObjectMapper method buildOpenstackSubnetList.
/**
* Use BB L3Network object to build subnets list of type org.onap.so.openstack.beans.Subnet
*
* @param L3Network
* @return List<org.onap.so.openstack.beans.Subnet>
*/
protected List<Subnet> buildOpenstackSubnetList(L3Network l3Network) {
List<org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet> subnets = l3Network.getSubnets();
List<org.onap.so.openstack.beans.Subnet> subnetList = new ArrayList<>();
// create mapper from onap Subnet to openstack bean Subnet
if (modelMapper.getTypeMap(org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet.class, org.onap.so.openstack.beans.Subnet.class) == null) {
PropertyMap<org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet, org.onap.so.openstack.beans.Subnet> personMap = new PropertyMap<org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet, org.onap.so.openstack.beans.Subnet>() {
@Override
protected void configure() {
map().setSubnetName(source.getSubnetName());
map(source.getSubnetId(), destination.getSubnetId());
map(source.getNeutronSubnetId(), destination.getNeutronId());
map(source.getGatewayAddress(), destination.getGatewayIp());
map(source.getIpVersion(), destination.getIpVersion());
map(source.isDhcpEnabled(), destination.getEnableDHCP());
map(source.getSubnetSequence(), destination.getSubnetSequence());
}
};
modelMapper.addMappings(personMap);
}
for (org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet subnet : subnets) {
org.onap.so.openstack.beans.Subnet openstackSubnet = modelMapper.map(subnet, org.onap.so.openstack.beans.Subnet.class);
if (StringUtils.isEmpty(openstackSubnet.getGatewayIp())) {
openstackSubnet.setGatewayIp("NULL");
}
// update cidr value
if (subnet.getNetworkStartAddress() != null && subnet.getCidrMask() != null)
openstackSubnet.setCidr(subnet.getNetworkStartAddress().concat(FORWARD_SLASH).concat(subnet.getCidrMask()));
List<org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute> hostRouteList = subnet.getHostRoutes();
List<org.onap.so.openstack.beans.HostRoute> openstackHostRouteList = new ArrayList<>();
org.onap.so.openstack.beans.HostRoute openstackHostRoute;
// TODO only 2 fields available on openstack object. Confirm it is sufficient or add as needed
for (org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute hostRoute : hostRouteList) {
openstackHostRoute = new org.onap.so.openstack.beans.HostRoute();
openstackHostRoute.setNextHop(hostRoute.getNextHop());
openstackHostRoute.setPrefix(hostRoute.getRoutePrefix());
// add host route to the list
openstackHostRouteList.add(openstackHostRoute);
}
if (subnet.getDhcpStart() != null && !subnet.getDhcpStart().equals("")) {
org.onap.so.openstack.beans.Pool openstackAllocationPool = new org.onap.so.openstack.beans.Pool();
openstackAllocationPool.setStart(subnet.getDhcpStart());
openstackAllocationPool.setEnd(subnet.getDhcpEnd());
List<org.onap.so.openstack.beans.Pool> allocationPools = new ArrayList<>();
allocationPools.add(openstackAllocationPool);
openstackSubnet.setAllocationPools(allocationPools);
}
openstackSubnet.setHostRoutes(openstackHostRouteList);
// add subnet to the list
subnetList.add(openstackSubnet);
}
return subnetList;
}
use of org.onap.so.openstack.beans.Subnet in project so by onap.
the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesMissingFieldTest.
@Test
public void createContrailSubnetHostRoutesMissingFieldTest() {
List<HostRoute> hostRoutes = new ArrayList<>();
HostRoute hostRoute1 = new HostRoute();
hostRoute1.setNextHop("next-hop1");
HostRoute hostRoute2 = new HostRoute();
hostRoute2.setNextHop("next-hop2");
hostRoute2.setPrefix("prefix2");
hostRoutes.add(hostRoute1);
hostRoutes.add(hostRoute2);
Subnet subnet = new Subnet();
subnet.setHostRoutes(hostRoutes);
ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
ContrailSubnet result = mapper.map();
ContrailSubnetHostRoutes routes = result.getHostRoutes();
assertEquals(2, routes.getHostRoutes().size());
assertEquals("next-hop1", routes.getHostRoutes().get(0).getNextHop());
assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix());
}
use of org.onap.so.openstack.beans.Subnet in project so by onap.
the class ContrailSubnetMappersTest method createSubnetTestValidCidr.
@Test
public void createSubnetTestValidCidr() {
Subnet subnet = new Subnet();
subnet.setCidr("test/value");
ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
ContrailSubnet result = mapper.map();
assertEquals("test", result.getSubnet().getIpPrefix());
assertEquals("value", result.getSubnet().getIpPrefixLen());
}
use of org.onap.so.openstack.beans.Subnet 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.Subnet in project so by onap.
the class ContrailSubnetMappersTest method createSubnetTestNullCidr.
@Test
public void createSubnetTestNullCidr() {
Subnet subnet = new Subnet();
ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
ContrailSubnet result = mapper.map();
assertEquals(null, result.getSubnet().getIpPrefix());
assertEquals(null, result.getSubnet().getIpPrefixLen());
}
Aggregations