NDB module — pyroute2 0.5.10 documentation

# NDB module

NDB is a high level network management module. IT allows to manage interfaces, routes, addresses etc. of connected systems, containers and network namespaces.

NDB work with remote systems via ssh, in that case mitogen module is required. It is possible to connect also OpenBSD and FreeBSD systems, but in read-only mode for now.

## Quick start

Print the routing information in the CSV format:

    with NDB() as ndb:
        for record in ndb.routes.summary(format='csv'):
            print(record)

Print all the interface names on the system:

    with NDB() as ndb:
        print([x.ifname for x in ndb.interfaces.summary()])

Print IP addresses of interfaces in several network namespaces:

    nslist = ['netns01',
              'netns02',
              'netns03']

    with NDB() as ndb:
        for nsname in nslist:
            ndb.sources.add(netns=nsname)
        for record in ndb.interfaces.summary(format='json'):
            print(record)

Add an IP address on an interface:

    with NDB() as ndb:
        with ndb.interfaces['eth0'] as i:
            i.ipaddr.create(address='10.0.0.1', prefixlen=24).commit()
            # ---> <---  NDB waits until the address actually
            #            becomes available

Change an interface property:

    with NDB() as ndb:
        with ndb.interfaces['eth0'] as i:
            i['state'] = 'up'
            i['address'] = '00:11:22:33:44:55'
        # ---> <---  the commit() is called authomatically by
        #            the context manager's __exit__()

## Reference

- Views and objects
  - Structure and API
  - Accessing objects
  - Objects cache
- Network interfaces
  - List interfaces
  - Get interface objects
  - Change nic properties
  - Create virtual interfaces
- IP addresses management
  - Using the view
  - Using interfaces
  - Accessing one address details
- Routes management
  - Simple routes
  - Multiple routing tables
  - Route metrics
- Database
  - Backends
  - SQL schema
- RTNL sources
  - Local RTNL
  - Network namespaces
  - Remote systems
- Debug and logging
  - Logging
  - Fetching DB data
  - RTNL events
  - RTNL objects
  - Object states
  - Object snapshots

work in progress