# 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 module

## 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

## Remote systems

It is possible also to connect to remote systems using SSH. In order to use this kind of sources it is required to install the mitogen module. The remote kind of sources uses the RemoteIPRoute class. The short form:

    ndb.sources.add(hostname='worker1.example.com')

In some more extended form:

    ndb.sources.add(**{'target': 'worker1.example.com',
                       'kind': 'remote',
                       'hostname': 'worker1.example.com',
                       'username': 'jenkins',
                       'check_host_keys': False})

See also: RemoteIPRoute