RTNL sources

Local RTNL

Local RTNL source is a simple IPRoute instance. By default NDB starts with one local RTNL source names localhost:

>>> ndb = NDB()
>>> ndb.sources.summary().format("json")
[
    {
        "name": "localhost",
        "spec": "{'target': 'localhost', 'nlm_generator': 1}",
        "state": "running"
    },
    {
        "name": "localhost/nsmanager",
        "spec": "{'target': 'localhost/nsmanager'}",
        "state": "running"
    }
]
>>> ndb.sources['localhost']
[running] <IPRoute {'target: 'localhost', 'nlm_generator': 1}>

The localhost RTNL source starts an additional async cache thread. The nlm_generator option means that instead of collections the IPRoute object returns generators, so IPRoute responses will not consume memory regardless of the RTNL objects number:

>>> ndb.sources['localhost'].nl.link('dump')
<generator object RTNL_API.filter_messages at 0x7f61a99a34a0>

See also: IPRoute and related modules

Network namespaces

There are two ways to connect additional sources to an NDB instance. One is to specify sources when creating an NDB object:

ndb = NDB(sources=[{'target': 'localhost'}, {'netns': 'test01'}])

Another way is to call ndb.sources.add() method:

ndb.sources.add(netns='test01')

This syntax: {target': 'localhost'} and {'netns': 'test01'} is the short form. The full form would be:

{'target': 'localhost', # the label for the DB
 'kind': 'local',       # use IPRoute class to start the source
 'nlm_generator': 1}    #

{'target': 'test01',    # the label
 'kind': 'netns',       # use NetNS class
 'netns': 'test01'}     #

See also: NetNS management