Search in sources :

Example 11 with ContrailSubnet

use of org.onap.so.adapters.network.beans.ContrailSubnet in project so by onap.

the class MsoNetworkAdapterImpl method mergeSubnetsAIC3.

/**
 * Subnet Output structure from Juniper { "ipam_subnets": [ { "subnet": { "ip_prefix": "10.100.1.0",
 * "ip_prefix_len": 28 }, "addr_from_start": null, "enable_dhcp": false, "default_gateway": "10.100.1.1",
 * "dns_nameservers": [], "dhcp_option_list": null, "subnet_uuid": "10391fbf-6b9c-4160-825d-2d018b7649cf",
 * "allocation_pools": [ { "start": "10.100.1.3", "end": "10.100.1.5" }, { "start": "10.100.1.6", "end":
 * "10.100.1.9" } ], "host_routes": null, "dns_server_address": "10.100.1.13", "subnet_name":
 * "subnet_MsoNW1_692c9032-e1a2-4d64-828c-7b9a4fcc05b0" }, { "subnet": { "ip_prefix": "10.100.2.16",
 * "ip_prefix_len": 28 }, "addr_from_start": null, "enable_dhcp": true, "default_gateway": "10.100.2.17",
 * "dns_nameservers": [], "dhcp_option_list": null, "subnet_uuid": "c7aac5ea-66fe-443a-85f9-9c38a608c0f6",
 * "allocation_pools": [ { "start": "10.100.2.18", "end": "10.100.2.20" } ], "host_routes": null,
 * "dns_server_address": "10.100.2.29", "subnet_name": "subnet_MsoNW1_692c9032-e1a2-4d64-828c-7b9a4fcc05b1" } ],
 * "host_routes": null }
 **
 */
private String mergeSubnetsAIC3(String heatTemplate, List<Subnet> subnets, Map<String, Object> stackParams) throws MsoException {
    // Resource Property
    List<ContrailSubnet> cslist = new ArrayList<>();
    for (Subnet subnet : subnets) {
        logger.debug("Input Subnet:{}", subnet);
        ContrailSubnet cs = new ContrailSubnetMapper(subnet).map();
        logger.debug("Contrail Subnet:{}", cs);
        cslist.add(cs);
    }
    JsonNode node = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        node = mapper.convertValue(cslist, JsonNode.class);
        String jsonString = mapper.writeValueAsString(cslist);
        logger.debug("Json Subnet List:{}", jsonString);
    } catch (Exception e) {
        String error = "Error creating JsonNode from input subnets";
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.DataError.getValue(), error, e);
        throw new MsoAdapterException(error);
    }
    // update parameters
    if (node != null) {
        stackParams.put("subnet_list", node);
    }
    // Outputs - All subnets are in one ipam_subnets structure
    String outputTempl = "  subnet:\n" + "    description: Openstack subnet identifier\n" + "    value: { get_attr: [network, network_ipam_refs, 0, attr]}\n";
    // append outputs in heatTemplate
    int outputsIdx = heatTemplate.indexOf("outputs:");
    heatTemplate = insertStr(heatTemplate, outputTempl, outputsIdx + 8);
    logger.debug("Template updated with all AIC3.0 subnets:{}", heatTemplate);
    return heatTemplate;
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ContrailSubnetMapper(org.onap.so.adapters.network.mappers.ContrailSubnetMapper) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException)

Example 12 with ContrailSubnet

use of org.onap.so.adapters.network.beans.ContrailSubnet in project so by onap.

the class ContrailSubnetMapper method map.

public ContrailSubnet map() {
    final ContrailSubnet result = new ContrailSubnet();
    if (inputSubnet != null) {
        final String subnetname = this.getSubnetName(inputSubnet);
        result.setSubnetName(subnetname);
        result.setEnableDhcp(inputSubnet.getEnableDHCP());
        result.setDefaultGateway(inputSubnet.getGatewayIp());
        Optional<ContrailSubnetIp> csIp = createSubnet(inputSubnet);
        if (csIp.isPresent()) {
            result.setSubnet(csIp.get());
        }
        Optional<List<ContrailSubnetPool>> pools = this.createContrailSubnetPool(inputSubnet);
        if (pools.isPresent()) {
            result.setAllocationPools(pools.get());
        }
        Optional<ContrailSubnetHostRoutes> routes = this.createContrailSubnetHostRoutes(inputSubnet);
        if (routes.isPresent()) {
            result.setHostRoutes(routes.get());
        }
    }
    return result;
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ContrailSubnetIp(org.onap.so.adapters.network.beans.ContrailSubnetIp) ContrailSubnetHostRoutes(org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ContrailSubnet (org.onap.so.adapters.network.beans.ContrailSubnet)12 Subnet (org.onap.so.openstack.beans.Subnet)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)7 ContrailSubnetHostRoutes (org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes)4 ContrailSubnetHostRoute (org.onap.so.adapters.network.beans.ContrailSubnetHostRoute)3 ContrailSubnetPool (org.onap.so.adapters.network.beans.ContrailSubnetPool)3 HostRoute (org.onap.so.openstack.beans.HostRoute)3 Pool (org.onap.so.openstack.beans.Pool)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 ContrailSubnetIp (org.onap.so.adapters.network.beans.ContrailSubnetIp)1 NetworkException (org.onap.so.adapters.network.exceptions.NetworkException)1 ContrailSubnetMapper (org.onap.so.adapters.network.mappers.ContrailSubnetMapper)1 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)1 MsoException (org.onap.so.openstack.exceptions.MsoException)1