Skip to main content

Python Netlink library

Project description

Pyroute2 is a pure Python netlink and messaging/RPC library. It requires only Python stdlib, no 3rd party libraries. Later it can change, but the deps tree will remain as simple, as it is possible.

The library contains all you need to build either one-node, or distributed netlink-related solutions. It consists of two major parts:

  • Netlink parsers: NETLINK_ROUTE, TASKSTATS, etc.

  • Messaging infrastructure: broker, clients, etc.

RPC sample

Actually, either side can act as a server or a client, there is no pre-defined roles. But for simplicity, they’re referred here as “server” and “client”.

Server side:

from pyroute2.rpc import Node
from pyroute2.rpc import public


class Namespace(object):
    '''
    This class acts as a namespace, that contains
    methods to be published via RPC. Any method,
    available through RPC, must be marked as @public.
    '''

    @public
    def echo(self, msg):
        '''
        Simple echo method, that returns a modified
        string.
        '''
        return '%s passed' % (msg)

# start the RPC node and register the namespace
node = Node()
node.register(Namespace())

# listen for network connections
node.serve('tcp://localhost:9824')

# wait for exit -- activity will be done in the
# background thread
raw_input(' hit return to exit >> ')

Client side:

from pyroute2.rpc import Node

# start the RPC node and connect to the 'server'
node = Node()
proxy = node.connect('tcp://localhost:9824')

# call a remote method through the proxy instance
print(proxy.echo('test'))

It will print out test passed.

installation

make install or pip install pyroute2

requires

Python >= 2.6

  • test reqs (optional): python-coverage, python-nose

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyroute2-0.2.8.tar.gz (62.6 kB view details)

Uploaded Source

File details

Details for the file pyroute2-0.2.8.tar.gz.

File metadata

  • Download URL: pyroute2-0.2.8.tar.gz
  • Upload date:
  • Size: 62.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyroute2-0.2.8.tar.gz
Algorithm Hash digest
SHA256 2ed32b6926da5e38b5fb69824d54bd89051ef7714a3f5ee8270c563a7321cddb
MD5 ac74d0fb29bba995b5538f53ea1c86a2
BLAKE2b-256 ddc3aa462911a90ffd0d0b0fea3e6ca1e2eb624050bdd0054f128f73c3960e69

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page