L2TPManager

class lnst.RecipeCommon.L2TPManager.L2TPManager

This class serves as an LNST interface to create the L2TP tunnels in an LNST recipe.

Users should use the Host.init_class() method to create a host specific instance of the class as shown in the following example:

from lnst.Controller import BaseRecipe
from lnst.Controller.Requirements import HostReq
from lnst.RecipeCommon.L2TPManager import L2TPManager

class L2TPRecipe(BaseRecipe):
    m1 = HostReq()

    def test(self):
        m1 = self.matched.m1
        m1.l2tp = m1.init_class(L2TPManager)

This class provides only the API to create and destroy the L2TP tunnels. To create a session for an L2TP tunnel you have to use the L2TPSessionDevice.

LNST will not cleanup any of the tunnels created in a recipe, so it is user’s responsibility to delete all previously created tunnels. This applies also to situation when an exception is raised during the recipe execution.

This can be handled by a code similar to the following:

class L2TPRecipe(BaseRecipe):
    def test(self):
        m1 = self.matched.m1
        m1.l2tp = m1.init_class(L2TPManager)

        try:
            self._test()
        finally:
            m1.l2tp.cleanup()

    def _test(self):
        m1 = self.matched.m1

        m1.l2tp.create_tunnel(
                tunnel_id=1000,
                peer_tunnel_id=1000,
                encap="udp",
                local="192.168.200.1",
                remote="192.168.200.2",
                udp_sport=5000,
                udp_dport=5000
        )
property l2tp_api

This is a handle for the pyroute2’s netlink l2tp API.

create_tunnel(**kwargs)

This method creates an L2TP tunnel based on the keyword arguments. These arguments should match the pyroute2’s L2tp.create_tunnel() arguments.

cleanup()

This method deletes all tunnels created previously through the instance of this object. The method serves as a convenient way to cleanup at the end of a recipe.

delete_tunnel(tunnel_id)

This method deletes the tunnel with the specified tunnel_id.