Search in sources :

Example 1 with ExternalFixedIpsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIpsKey in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalNetworkToRouter.

private void addExternalNetworkToRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    Map<ExternalFixedIpsKey, ExternalFixedIps> keyExternalFixedIpsMap = update.getExternalGatewayInfo().nonnullExternalFixedIps();
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        // Add this router to the ExtRouters list
        addExternalRouter(update);
        // Update External Subnets for this router
        updateExternalSubnetsForRouter(routerId, extNetId, new ArrayList<ExternalFixedIps>(keyExternalFixedIpsMap.values()));
        // Create and add Networks object for this External Network to the ExternalNetworks list
        InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        if (!optionalNets.isPresent()) {
            LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
            return;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
        List<Uuid> rtrList = (builder.getRouterIds() != null && !builder.getRouterIds().isEmpty()) ? new ArrayList<>(builder.getRouterIds()) : new ArrayList<>();
        rtrList.add(routerId);
        builder.setRouterIds(rtrList);
        if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
            builder.setVpnid(extNetId);
        }
        Networks networkss = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("Updating externalnetworks {}", networkss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
        LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
        LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ExternalFixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIpsKey) ExecutionException(java.util.concurrent.ExecutionException) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)1 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)1 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)1 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)1 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)1 ExternalFixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps)1 ExternalFixedIpsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIpsKey)1 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)1