use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalRouter.
public void addExternalRouter(Router update) {
Uuid routerId = update.getUuid();
Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
Uuid gatewayPortId = update.getGatewayPortId();
// Create and add Routers object for this Router to the ExtRouters list
// Create a Routers object
InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
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;
}
Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
LOG.trace("Creating/Updating a new Routers node: {}", routerId.getValue());
RoutersBuilder builder = null;
if (optionalRouters.isPresent()) {
builder = new RoutersBuilder(optionalRouters.get());
} else {
builder = new RoutersBuilder().setKey(new RoutersKey(routerId.getValue()));
}
builder.setRouterName(routerId.getValue());
builder.setNetworkId(extNetId);
builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
ArrayList<ExternalIps> externalIps = new ArrayList<>();
for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
}
builder.setExternalIps(externalIps);
if (gatewayPortId != null) {
LOG.trace("Setting/Updating gateway Mac for router {}", routerId.getValue());
Port port = neutronvpnUtils.getNeutronPort(gatewayPortId);
if (port != null && port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_GATEWAY_INF)) {
builder.setExtGwMacAddress(port.getMacAddress().getValue());
}
}
List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
builder.setSubnetIds(subList);
Routers routers = builder.build();
// Add Routers object to the ExtRouters list
LOG.trace("Creating extrouters {}", routers);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, builder.build());
LOG.trace("Wrote successfully Routers to CONFIG Datastore");
} catch (ReadFailedException | TransactionCommitFailedException ex) {
LOG.error("Creation of extrouters failed for router {} failed", routerId.getValue(), ex);
}
}
Aggregations