Search in sources :

Example 1 with RouteTarget

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

the class MsoNetworkAdapterImpl method populateNetworkParams.

private Map<String, Object> populateNetworkParams(NetworkType neutronNetworkType, String networkName, String physicalNetwork, List<Integer> vlans, List<RouteTarget> routeTargets, String shared, String external, boolean os3template) {
    // Build the common set of HEAT template parameters
    Map<String, Object> stackParams = new HashMap<>();
    stackParams.put("network_name", networkName);
    if (neutronNetworkType == NetworkType.PROVIDER) {
        // For Provider type
        stackParams.put(PHYSICAL_NETWORK, physicalNetwork);
        stackParams.put("vlan", vlans.get(0).toString());
    } else if (neutronNetworkType == NetworkType.MULTI_PROVIDER) {
        // For Multi-provider, PO supports a custom resource extension of ProviderNet.
        // It supports all ProviderNet properties except segmentation_id, and adds a
        // comma-separated-list of VLANs as a "segments" property.
        // Note that this does not match the Neutron definition of Multi-Provider network,
        // which contains a list of 'segments', each having physical_network, network_type,
        // and segmentation_id.
        StringBuilder buf = new StringBuilder();
        String sep = "";
        for (Integer vlan : vlans) {
            buf.append(sep).append(vlan.toString());
            sep = ",";
        }
        String csl = buf.toString();
        stackParams.put(PHYSICAL_NETWORK, physicalNetwork);
        stackParams.put(VLANS, csl);
    }
    if (routeTargets != null) {
        String rtGlobal = "";
        String rtImport = "";
        String rtExport = "";
        String sep = "";
        for (RouteTarget rt : routeTargets) {
            boolean rtIsNull = false;
            if (rt != null) {
                String routeTarget = rt.getRouteTarget();
                String routeTargetRole = rt.getRouteTargetRole();
                logger.debug("Checking for an actually null route target: {}", rt);
                if (routeTarget == null || routeTarget.equals("") || routeTarget.equalsIgnoreCase("null"))
                    rtIsNull = true;
                if (routeTargetRole == null || routeTargetRole.equals("") || routeTargetRole.equalsIgnoreCase("null"))
                    rtIsNull = true;
            } else {
                rtIsNull = true;
            }
            if (!rtIsNull) {
                logger.debug("Input RT:{}", rt);
                String role = rt.getRouteTargetRole();
                String rtValue = rt.getRouteTarget();
                if ("IMPORT".equalsIgnoreCase(role)) {
                    sep = rtImport.isEmpty() ? "" : ",";
                    rtImport = os3template ? rtImport + sep + "target:" + rtValue : rtImport + sep + rtValue;
                } else if ("EXPORT".equalsIgnoreCase(role)) {
                    sep = rtExport.isEmpty() ? "" : ",";
                    rtExport = os3template ? rtExport + sep + "target:" + rtValue : rtExport + sep + rtValue;
                } else // covers BOTH, empty etc
                {
                    sep = rtGlobal.isEmpty() ? "" : ",";
                    rtGlobal = os3template ? rtGlobal + sep + "target:" + rtValue : rtGlobal + sep + rtValue;
                }
            }
        }
        if (!rtImport.isEmpty()) {
            stackParams.put("route_targets_import", rtImport);
        }
        if (!rtExport.isEmpty()) {
            stackParams.put("route_targets_export", rtExport);
        }
        if (!rtGlobal.isEmpty()) {
            stackParams.put("route_targets", rtGlobal);
        }
    }
    if (commonUtils.isNullOrEmpty(shared)) {
        stackParams.put("shared", "False");
    } else {
        stackParams.put("shared", shared);
    }
    if (commonUtils.isNullOrEmpty(external)) {
        stackParams.put("external", "False");
    } else {
        stackParams.put("external", external);
    }
    return stackParams;
}
Also used : HashMap(java.util.HashMap) RouteTarget(org.onap.so.openstack.beans.RouteTarget)

Example 2 with RouteTarget

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

the class StackService method updateNetwork.

private void updateNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws NetworkException {
    backout.setFalse();
    UpdateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), UpdateNetworkRequest.class);
    HashMap<String, String> params = (HashMap<String, String>) req.getNetworkParams();
    if (params == null) {
        params = new HashMap<>();
    }
    String shared = null;
    String external = null;
    String physicalNetworkName = null;
    List<Integer> vlans = null;
    List<RouteTarget> routeTargets = null;
    List<String> fqdns = null;
    List<String> routeTable = null;
    if (params.containsKey(SHARED))
        shared = params.get(SHARED);
    if (params.containsKey(EXTERNAL))
        external = params.get(EXTERNAL);
    if (req.isContrailRequest()) {
        ContrailNetwork ctn = req.getContrailNetwork();
        if (ctn == null) {
            ctn = new ContrailNetwork();
            req.setContrailNetwork(ctn);
        }
        if (shared == null && ctn.getShared() != null) {
            shared = ctn.getShared();
        }
        if (shared == null && ctn.getExternal() != null) {
            external = ctn.getExternal();
        }
        routeTargets = req.getContrailNetwork().getRouteTargets();
        fqdns = req.getContrailNetwork().getPolicyFqdns();
        routeTable = req.getContrailNetwork().getRouteTableFqdns();
    } else {
        ProviderVlanNetwork pvn = req.getProviderVlanNetwork();
        if (pvn == null) {
            pvn = new ProviderVlanNetwork();
            req.setProviderVlanNetwork(pvn);
        }
        physicalNetworkName = req.getProviderVlanNetwork().getPhysicalNetworkName();
        vlans = req.getProviderVlanNetwork().getVlans();
    }
    networkAdapterImpl.updateNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkStackId(), req.getNetworkName(), physicalNetworkName, vlans, routeTargets, shared, external, req.getSubnets(), fqdns, routeTable, req.getMsoRequest(), canonicalStackId);
    success.setTrue();
}
Also used : HashMap(java.util.HashMap) ContrailNetwork(org.onap.so.adapters.nwrest.ContrailNetwork) StringReader(java.io.StringReader) UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest) ProviderVlanNetwork(org.onap.so.adapters.nwrest.ProviderVlanNetwork) RouteTarget(org.onap.so.openstack.beans.RouteTarget)

Example 3 with RouteTarget

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

the class StackService method createNetwork.

private void createNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success, MutableBoolean os3) throws NetworkException {
    CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
    HashMap<String, String> params = (HashMap<String, String>) req.getNetworkParams();
    if (params == null) {
        params = new HashMap<>();
    }
    String shared = null;
    String external = null;
    String physicalNetworkName = null;
    List<Integer> vlans = null;
    List<RouteTarget> routeTargets = null;
    List<String> fqdns = null;
    List<String> routeTable = null;
    if (params.containsKey(SHARED))
        shared = params.get(SHARED);
    if (params.containsKey(EXTERNAL))
        external = params.get(EXTERNAL);
    if (req.isContrailRequest()) {
        ContrailNetwork ctn = req.getContrailNetwork();
        if (ctn == null) {
            ctn = new ContrailNetwork();
            req.setContrailNetwork(ctn);
        }
        if (shared == null && ctn.getShared() != null) {
            shared = ctn.getShared();
        }
        if (shared == null && ctn.getExternal() != null) {
            external = ctn.getExternal();
        }
        routeTargets = req.getContrailNetwork().getRouteTargets();
        fqdns = req.getContrailNetwork().getPolicyFqdns();
        routeTable = req.getContrailNetwork().getRouteTableFqdns();
    } else {
        ProviderVlanNetwork pvn = req.getProviderVlanNetwork();
        if (pvn == null) {
            pvn = new ProviderVlanNetwork();
            req.setProviderVlanNetwork(pvn);
        }
        physicalNetworkName = req.getProviderVlanNetwork().getPhysicalNetworkName();
        vlans = req.getProviderVlanNetwork().getVlans();
    }
    networkAdapterImpl.createNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), physicalNetworkName, vlans, routeTargets, shared, external, req.getFailIfExists(), false, req.getSubnets(), fqdns, routeTable, req.getMsoRequest(), canonicalStackId, os3);
    success.setTrue();
    backout.setValue(req.getBackout());
}
Also used : CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) HashMap(java.util.HashMap) ContrailNetwork(org.onap.so.adapters.nwrest.ContrailNetwork) StringReader(java.io.StringReader) ProviderVlanNetwork(org.onap.so.adapters.nwrest.ProviderVlanNetwork) RouteTarget(org.onap.so.openstack.beans.RouteTarget)

Aggregations

HashMap (java.util.HashMap)3 RouteTarget (org.onap.so.openstack.beans.RouteTarget)3 StringReader (java.io.StringReader)2 ContrailNetwork (org.onap.so.adapters.nwrest.ContrailNetwork)2 ProviderVlanNetwork (org.onap.so.adapters.nwrest.ProviderVlanNetwork)2 CreateNetworkRequest (org.onap.so.adapters.nwrest.CreateNetworkRequest)1 UpdateNetworkRequest (org.onap.so.adapters.nwrest.UpdateNetworkRequest)1