Current File : /opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb/__pycache__//view.cpython-311.pyc
�
�;fB � �H � d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl m
Z
ddlmZm
Z
ddlmZ ddlmZ dd lmZ dd
lmZ ddlmZmZ ddlmZmZ dd
lmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z' G d� d� � Z( G d� de)� � Z* G d� de*� � Z+dS )a�
Accessing objects
=================
NDB objects are grouped into "views":
* interfaces
* addresses
* routes
* neighbours
* rules
* netns
* ...
Views are dictionary-like objects that accept strings or dict selectors::
# access eth0
ndb.interfaces["eth0"]
# access eth0 in the netns test01
ndb.sources.add(netns="test01")
ndb.interfaces[{"target": "test01", "ifname": "eth0"}]
# access a route to 10.4.0.0/24
ndb.routes["10.4.0.0/24"]
# same with a dict selector
ndb.routes[{"dst": "10.4.0.0", "dst_len": 24}]
Objects cache
=============
NDB create objects on demand, it doesn't create thousands of route objects
for thousands of routes by default. The object is being created only when
accessed for the first time, and stays in the cache as long as it has any
not committed changes. To inspect cached objects, use views' `.cache`::
>>> ndb.interfaces.cache.keys()
[(('target', u'localhost'), ('tflags', 0), ('index', 1)), # lo
(('target', u'localhost'), ('tflags', 0), ('index', 5))] # eth3
There is no asynchronous cache invalidation, the cache is being cleaned up
every time when an object is accessed.
API
===
� N)�OrderedDict)�partial)�cli�config)�
basestring� )�
check_auth)�RSLV_DELETE)�Address)� Interface�Vlan)� FDBRecord� Neighbour)�NetNS)�Route)�Rule)�Record� RecordSet)�Source�SourceProxyc � � e Zd Zd� Zd� Zd� ZdS )�
TmpHandlerc �0 � || _ || _ || _ d S �N)�ndb�event�handler)�selfr r r s �D/opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb/view.py�__init__zTmpHandler.__init__L s � ������
������ c � � | j j � | j j j | j | j � � | S r )r �task_manager�register_handler�schema�classesr r �r s r � __enter__zTmpHandler.__enter__Q s; � ����.�.��H�O�#�D�J�/���
�
�
� �r! c � � | j j � | j j j | j | j � � d S r )r r# �unregister_handlerr% r&