Search in sources :

Example 1 with DeleteL3VPNOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutput in project netvirt by opendaylight.

the class NeutronvpnManager method deleteL3VPN.

/**
 * It handles the invocations to the neutronvpn:deleteL3VPN RPC method.
 */
@Override
public Future<RpcResult<DeleteL3VPNOutput>> deleteL3VPN(DeleteL3VPNInput input) {
    DeleteL3VPNOutputBuilder opBuilder = new DeleteL3VPNOutputBuilder();
    SettableFuture<RpcResult<DeleteL3VPNOutput>> result = SettableFuture.create();
    List<RpcError> errorList = new ArrayList<>();
    int failurecount = 0;
    int warningcount = 0;
    List<Uuid> vpns = input.getId();
    for (Uuid vpn : vpns) {
        RpcError error;
        String msg;
        try {
            InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpn.getValue())).build();
            Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
            if (optionalVpn.isPresent()) {
                removeVpn(vpn);
            } else {
                errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::warn, "VPN with vpnid: {} does not exist", vpn.getValue())));
                warningcount++;
            }
        } catch (ReadFailedException ex) {
            errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION, formatAndLog(LOG::error, "Deletion of L3VPN failed when deleting for uuid {}", vpn.getValue()), ex.getMessage()));
            failurecount++;
        }
    }
    // if none succeeds; result is failure
    if (failurecount + warningcount == vpns.size()) {
        result.set(RpcResultBuilder.<DeleteL3VPNOutput>failed().withRpcErrors(errorList).build());
    } else {
        List<String> errorResponseList = new ArrayList<>();
        if (!errorList.isEmpty()) {
            for (RpcError rpcError : errorList) {
                errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag() + ", ErrorMessage: " + rpcError.getMessage());
            }
        } else {
            errorResponseList.add("Operation successful with no errors");
        }
        opBuilder.setResponse(errorResponseList);
        result.set(RpcResultBuilder.<DeleteL3VPNOutput>success().withResult(opBuilder.build()).build());
    }
    return result;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DeleteL3VPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutputBuilder) VpnInstanceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)

Example 2 with DeleteL3VPNOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutput in project netvirt by opendaylight.

the class ConfigureL3VpnCommand method deleteL3VpnCLI.

private void deleteL3VpnCLI() throws InterruptedException, ExecutionException {
    if (vid == null) {
        session.getConsole().println("Please supply a valid VPN ID");
        session.getConsole().println(getHelp("delete"));
        return;
    }
    Uuid vpnId = new Uuid(vid);
    // disassociation of network(s) (removal of subnet(s)) from VPN to be followed by deletion of VPN
    RpcResult<DissociateNetworksOutput> dissociateNetworksRpcResult = null;
    List<Uuid> networkIdList = null;
    networkIdList = neutronVpnManager.getNetworksForVpn(vpnId);
    if (networkIdList != null && !networkIdList.isEmpty()) {
        Future<RpcResult<DissociateNetworksOutput>> result = neutronvpnService.dissociateNetworks(new DissociateNetworksInputBuilder().setVpnId(vpnId).setNetworkId(networkIdList).build());
        dissociateNetworksRpcResult = result.get();
        if (dissociateNetworksRpcResult.isSuccessful()) {
            session.getConsole().println("Subnet(s) removed from VPN successfully");
            LOG.trace("dissociateNetworks: {}", result);
        } else {
            session.getConsole().println("Error while removing subnet(s) from VPN: " + result.get().getErrors());
            session.getConsole().println(getHelp("delete"));
        }
    }
    if (networkIdList == null || networkIdList.isEmpty() || dissociateNetworksRpcResult.isSuccessful()) {
        List<Uuid> vpnIdList = new ArrayList<>();
        vpnIdList.add(vpnId);
        Future<RpcResult<DeleteL3VPNOutput>> result = neutronvpnService.deleteL3VPN(new DeleteL3VPNInputBuilder().setId(vpnIdList).build());
        RpcResult<DeleteL3VPNOutput> rpcResult = result.get();
        if (rpcResult.isSuccessful()) {
            session.getConsole().println("L3VPN deleted successfully");
            LOG.trace("deletel3vpn: {}", result);
        } else {
            session.getConsole().println("Error populating deleteL3VPN : " + result.get().getErrors());
            session.getConsole().println(getHelp("delete"));
        }
    } else {
        session.getConsole().println("Not proceeding with deletion of L3VPN since error(s) encountered " + "in removing subnet(s) from VPN");
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DissociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutput) DeleteL3VPNOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) DeleteL3VPNInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNInputBuilder) DissociateNetworksInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksInputBuilder)

Aggregations

ArrayList (java.util.ArrayList)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)1 VpnInstanceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)1 DeleteL3VPNInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNInputBuilder)1 DeleteL3VPNOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutput)1 DeleteL3VPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutputBuilder)1 DissociateNetworksInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksInputBuilder)1 DissociateNetworksOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutput)1 RpcError (org.opendaylight.yangtools.yang.common.RpcError)1