Search in sources :

Example 1 with CreateL3VPNInputBuilder

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

the class ConfigureL3VpnCommand method createL3VpnCLI.

private void createL3VpnCLI() throws InterruptedException, ExecutionException {
    if (vid == null) {
        session.getConsole().println("Please supply a valid VPN ID");
        session.getConsole().println(getHelp("create"));
        return;
    }
    if (rd == null) {
        session.getConsole().println("Please supply a valid RD");
        session.getConsole().println(getHelp("create"));
        return;
    }
    if (irt == null) {
        session.getConsole().println("Please supply a valid list of import RTs separated by {,}");
        session.getConsole().println(getHelp("create"));
        return;
    }
    if (ert == null) {
        session.getConsole().println("Please supply a valid list of export RTs separated by {,}");
        session.getConsole().println(getHelp("create"));
        return;
    }
    Uuid vuuid = new Uuid(vid);
    RpcResult<CreateL3VPNOutput> createL3VpnRpcResult = null;
    {
        ArrayList<String> rdList = new ArrayList<>(Arrays.asList(rd.split(",")));
        ArrayList<String> irtList = new ArrayList<>(Arrays.asList(irt.split(",")));
        ArrayList<String> ertList = new ArrayList<>(Arrays.asList(ert.split(",")));
        Uuid tuuid = null;
        if (tid != null) {
            tuuid = new Uuid(tid);
        }
        List<L3vpn> l3vpns = new ArrayList<>();
        L3vpn l3vpn = new L3vpnBuilder().setId(vuuid).setName(name).setRouteDistinguisher(rdList).setImportRT(irtList).setExportRT(ertList).setTenantId(tuuid).build();
        l3vpns.add(l3vpn);
        Future<RpcResult<CreateL3VPNOutput>> result = neutronvpnService.createL3VPN(new CreateL3VPNInputBuilder().setL3vpn(l3vpns).build());
        createL3VpnRpcResult = result.get();
        if (createL3VpnRpcResult.isSuccessful()) {
            session.getConsole().println("L3VPN created successfully");
            LOG.trace("createl3vpn: {}", result);
        } else {
            session.getConsole().println("Error populating createL3VPN : " + result.get().getErrors());
            session.getConsole().println(getHelp("create"));
        }
    }
    /**
     * passing a subnetId list alongwith create-l3-vpn CLI implicitly indicates that
     * association of network(s) to VPN is being intended.
     */
    if (createL3VpnRpcResult.isSuccessful()) {
        {
            List<Uuid> networkIdList = new ArrayList<>();
            if (sid != null) {
                for (String sidStr : sid.split(",")) {
                    Uuid subnetId = new Uuid(sidStr);
                    Uuid networkId = neutronVpnManager.getNetworkForSubnet(subnetId);
                    if (networkId != null) {
                        networkIdList.add(networkId);
                    } else {
                        session.getConsole().println("Could not find network for subnet " + subnetId.getValue() + ". Not proceeding with adding subnet to VPN");
                    }
                }
                if (!networkIdList.isEmpty()) {
                    Future<RpcResult<AssociateNetworksOutput>> result = neutronvpnService.associateNetworks(new AssociateNetworksInputBuilder().setVpnId(vuuid).setNetworkId(networkIdList).build());
                    RpcResult<AssociateNetworksOutput> associateNetworksRpcResult = result.get();
                    if (associateNetworksRpcResult.isSuccessful()) {
                        session.getConsole().println("Subnet(s) added to VPN successfully");
                        LOG.trace("associateNetworks: {}", result);
                    } else {
                        session.getConsole().println("Error while adding subnet(s) to VPN: " + result.get().getErrors());
                        session.getConsole().println(getHelp("create"));
                    }
                }
            }
        }
    }
}
Also used : CreateL3VPNOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutput) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) L3vpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn) AssociateNetworksInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksInputBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AssociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) L3vpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpnBuilder) CreateL3VPNInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNInputBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 AssociateNetworksInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksInputBuilder)1 AssociateNetworksOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput)1 CreateL3VPNInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNInputBuilder)1 CreateL3VPNOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutput)1 L3vpn (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn)1 L3vpnBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpnBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1