use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method disassociateExtNetworkFromVpn.
private boolean disassociateExtNetworkFromVpn(@Nonnull Uuid vpnId, @Nonnull Network extNet) {
if (!removeExternalNetworkFromVpn(extNet)) {
return false;
}
// check, if there is another Provider Networks associated with given VPN
List<Uuid> vpnNets = getNetworksForVpn(vpnId);
if (vpnNets != null) {
for (Uuid netId : vpnNets) {
if (neutronvpnUtils.getIsExternal(getNeutronNetwork(netId))) {
LOG.error("dissociateExtNetworkFromVpn: Internet VPN {} is still associated with Provider Network " + "{}", vpnId.getValue(), netId.getValue());
return true;
}
}
}
LOG.info("disassociateExtNetworkFromVpn: set type {} for VPN {}", VpnInstanceOpDataEntry.BgpvpnType.BGPVPNExternal, vpnId.getValue());
neutronvpnUtils.updateVpnInstanceOpWithType(VpnInstanceOpDataEntry.BgpvpnType.BGPVPNExternal, vpnId);
for (Uuid snId : neutronvpnUtils.getPrivateSubnetsToExport(extNet)) {
Subnetmap sm = neutronvpnUtils.getSubnetmap(snId);
if (sm == null) {
LOG.error("disassociateExtNetworkFromVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
continue;
}
updateVpnInternetForSubnet(sm, vpnId, false);
}
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), IpVersionChoice.IPV6, false);
LOG.info("disassociateExtNetworkFromVpn: withdraw IPv6 Internet default route from VPN {}", vpnId.getValue());
neutronvpnUtils.updateVpnInstanceWithFallback(vpnId.getValue(), false);
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnMaps.
private void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
VpnMapBuilder builder;
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
try {
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
builder = new VpnMapBuilder(optionalVpnMap.get());
} else {
builder = new VpnMapBuilder().setKey(new VpnMapKey(vpnId)).setVpnId(vpnId);
}
if (name != null) {
builder.setName(name);
}
if (tenantId != null) {
builder.setTenantId(tenantId);
}
if (router != null) {
builder.setRouterId(router);
}
if (networks != null) {
List<Uuid> nwList = builder.getNetworkIds();
if (nwList == null) {
nwList = new ArrayList<>();
}
nwList.addAll(networks);
builder.setNetworkIds(nwList);
}
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("Creating/Updating vpnMaps node: {} ", vpnId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, builder.build());
LOG.debug("VPNMaps DS updated for VPN {} ", vpnId.getValue());
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method clearFromVpnMaps.
private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
Optional<VpnMap> optionalVpnMap;
try {
optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (ReadFailedException e) {
LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
return;
}
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
if (routerId != null) {
if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
try {
// remove entire node in case of internal VPN
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("removing vpnMaps node: {} ", vpnId);
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
return;
}
vpnMapBuilder.setRouterId(null);
}
if (networkIds != null) {
List<Uuid> vpnNw = vpnMap.getNetworkIds();
vpnNw.removeAll(networkIds);
if (vpnNw.isEmpty()) {
LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
vpnMapBuilder.setNetworkIds(null);
} else {
vpnMapBuilder.setNetworkIds(vpnNw);
}
}
try {
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, vpnMapBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
} else {
LOG.error("VPN : {} not found", vpnId.getValue());
}
LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method addExternalNetworkToVpn.
private boolean addExternalNetworkToVpn(Network extNet, Uuid vpnId) {
Uuid extNetId = extNet.getUuid();
InstanceIdentifier<Networks> extNetIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
try {
Optional<Networks> optionalExtNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier);
if (!optionalExtNets.isPresent()) {
LOG.error("addExternalNetworkToVpn: Provider Network {} is not present in ConfigDS", extNetId.getValue());
return false;
}
NetworksBuilder builder = new NetworksBuilder(optionalExtNets.get());
builder.setVpnid(vpnId);
Networks networks = builder.build();
// Add Networks object to the ExternalNetworks list
LOG.trace("addExternalNetworkToVpn: Set VPN Id {} for Provider Network {}", vpnId.getValue(), extNetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier, networks);
return true;
} catch (TransactionCommitFailedException | ReadFailedException ex) {
LOG.error("addExternalNetworkToVpn: Failed to set VPN Id {} to Provider Network {}: ", vpnId.getValue(), extNetId.getValue(), ex);
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method dissociateNetworks.
/**
* It handles the invocations to the neutronvpn:dissociateNetworks RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<DissociateNetworksOutput>> dissociateNetworks(DissociateNetworksInput input) {
DissociateNetworksOutputBuilder opBuilder = new DissociateNetworksOutputBuilder();
SettableFuture<RpcResult<DissociateNetworksOutput>> result = SettableFuture.create();
LOG.debug("dissociateNetworks {}", input);
StringBuilder returnMsg = new StringBuilder();
Uuid vpnId = input.getVpnId();
try {
if (neutronvpnUtils.getVpnMap(vpnId) != null) {
List<Uuid> netIds = input.getNetworkId();
if (netIds != null && !netIds.isEmpty()) {
List<String> failed = dissociateNetworksFromVpn(vpnId, netIds);
if (!failed.isEmpty()) {
returnMsg.append(failed);
}
}
} else {
returnMsg.append("VPN not found : ").append(vpnId.getValue());
}
if (returnMsg.length() != 0) {
opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
result.set(RpcResultBuilder.<DissociateNetworksOutput>success().withResult(opBuilder.build()).build());
} else {
result.set(RpcResultBuilder.<DissociateNetworksOutput>success().build());
}
} catch (Exception ex) {
result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
}
LOG.debug("dissociateNetworks returns..");
return result;
}
Aggregations