File: //opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb/__pycache__/source.cpython-311.pyc
�
�;f?B � �` � d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
mZ ddlm
Z
ddlmZ ddlmZ ddlmZ ddlmZ d d
lmZmZ d dlmZmZmZ ej � d� � rdd
lm Z ddl!m"Z" ddl#m$Z$ ndZ$dZ"d Z%dZ& G d� de'� � Z( G d� de)� � Z*dS )aa
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: :ref:`iproute`
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: :ref:`netns`
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 <https://github.com/dw/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: :ref:`remote`
� N)�
basestring)�IPRoute)�NetlinkError)�NetlinkSocketBase)�ifinfmsg)�
RemoteIPRoute� )�ShutdownException�State)�
cmsg_event�cmsg_failed�cmsg_sstart�linux)�netns)�NetNSManager)�NetNS� c � � e Zd Zd� Zd� ZdS )�SourceProxyc �R � || _ t j � � | _ || _ d S �N)�ndb�queue�Queue�events�target)�selfr r s �F/opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb/source.py�__init__zSourceProxy.__init__t s! � �����k�m�m�������� c � � t t j � � j � � }t j � � x| j j |<