Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/pyroute2/ndb/objects/__pycache__/interface.cpython-39.pyc
Ðазад
a ]�h�� � @ s� d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z ddl mZ ddlm Z ddlmZ d d lmZmZ d dlmZ dd � ZdZe�� �dd��d�Ze�� �d��ddd�Ze �� �d��ddd�Zejj�� �dd��dd��ddd�Z degdegde gdeggdegdegdegdejjgde ggeegid�Z!dZ"dd� e"D �Z#e#�$� D ]V\Z%Z&de% Z%e!d �'e%e&g� e&�� �dd!��d��ddd�Z(e!d" �'e%e(g� �q^d#d$� Z)G d%d&� d&e�Z*G d'd(� d(e�Z+dS ))a .. testsetup:: from pyroute2 import IPMock as IPRoute from pyroute2 import NDB from pyroute2 import config config.mock_iproute = True .. testsetup:: preset_1 from pyroute2 import NDB from pyroute2 import config config.mock_iproute = True ndb = NDB( sources=[ {'target': 'localhost', 'kind': 'IPMock'}, {'target': 'worker1.sample.com', 'kind': 'IPMock'}, {'target': 'worker2.sample.com', 'kind': 'IPMock'}, ] ) .. testsetup:: preset_br0_1 from pyroute2 import NDB from pyroute2 import config config.mock_iproute = True ndb = NDB() ndb.interfaces.create(ifname='eth1', kind='dummy').commit() ndb.interfaces.create(ifname='br0', kind='bridge').commit() ndb.interfaces.create(ifname='bond0', kind='bond').commit() .. testsetup:: preset_br0_2 from pyroute2 import NDB from pyroute2 import config config.mock_iproute = True ndb = NDB() ndb.interfaces.create(ifname='br0', kind='bridge').commit() ndb.interfaces['br0'].add_port('eth0').commit() List interfaces =============== List interface keys: .. testcode:: with NDB(log='on') as ndb: for key in ndb.interfaces: print(key) .. testoutput:: :hide: ('localhost', 0, 0, 772, 1, 1, 0, '00:00:00:00:00:00', '00:00:00:00:00:00', 'lo', 65536, None, 'noqueue', None, 1000, 'UNKNOWN', 0, None, None, None, 0, None, 0, 1, 1, 1, 0, None, None, 0, 65535, 65536, None, None, None, 0, 0, None, None, None, None, None, None, 65536, None, None, 'up', None, None, None, None, None, None, None, None, '[]') ('localhost', 0, 0, 772, 2, 1, 0, '52:54:00:72:58:b2', 'ff:ff:ff:ff:ff:ff', 'eth0', 1500, None, 'fq_codel', None, 1000, 'UNKNOWN', 0, None, None, None, 0, None, 0, 1, 1, 1, 0, None, None, 0, 65535, 65536, None, None, None, 0, 0, None, None, None, None, None, None, 65536, None, None, 'up', None, None, None, None, None, None, None, None, '[]') NDB views support some dict methods: `items()`, `values()`, `keys()`: .. testcode:: with NDB(log='on') as ndb: for key, nic in ndb.interfaces.items(): nic.set('state', 'up') nic.commit() Get interface objects ===================== The keys may be used as selectors to get interface objects: .. testcode:: with NDB() as ndb: for key in ndb.interfaces: print(ndb.interfaces[key]) .. testoutput:: :hide: :options: +ELLIPSIS ... Also possible selector formats are `dict()` and simple string. The latter means the interface name: .. testcode:: preset_1 eth0 = ndb.interfaces['eth0'] Dict selectors are necessary to get interfaces by other properties: .. testcode:: preset_1 wrk1_eth0 = ndb.interfaces[{'target': 'worker1.sample.com', 'ifname': 'eth0'}] wrk2_eth0 = ndb.interfaces[{'target': 'worker2.sample.com', 'address': '52:54:00:72:58:b2'}] Change nic properties ===================== Changing MTU and MAC address: .. testcode:: preset_1 with ndb.interfaces['eth0'] as eth0: eth0['mtu'] = 1248 eth0['address'] = '00:11:22:33:44:55' # --> <-- eth0.commit() is called by the context manager One can change a property either using the assignment statement, or using the `.set()` routine: .. testcode:: preset_1 # same code with ndb.interfaces['eth0'] as eth0: eth0.set('mtu', 1248) eth0.set('address', '00:11:22:33:44:55') Create virtual interfaces ========================= Create a bridge and add a port, `eth0`: .. testcode:: preset_1 with ndb.interfaces.create(ifname='br0', kind='bridge') as br0: br0.add_port('eth0') Bridge and bond ports ===================== Add bridge and bond ports one can use specific API: .. testcode:: preset_br0_1 with ndb.interfaces['br0'] as br0: br0.add_port('eth0') br0.add_port('eth1') br0.set('br_max_age', 1024) br0.set('br_forward_delay', 1500) with ndb.interfaces['bond0'] as bond0: bond0.add_port('eth0') bond0.add_port('eth1') To remove a port: .. testcode:: preset_br0_2 with ndb.interfaces['br0'] as br0: br0.del_port('eth0') Or by setting the master property on a port, in the same way as with `IPRoute`: .. testcode:: preset_br0_1 index = ndb.interfaces['br0']['index'] # add a port to a bridge with ndb.interfaces['eth0'] as eth0: eth0.set('master', index) # remove a port from a bridge with ndb.interfaces['eth0'] as eth0: eth0.set('master', 0) � N)� basestring)� AF_BRIDGE)�NetlinkError)�ifinfmsg)�p2pmsg)�LinkFieldFilter� )�AuthManager� check_auth)�RTNL_Objectc C s� |d d@ s6| � d| j| j| jf ||d |d f� |�d�rDd S |�d�}g |d<