Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/pyroute2/nslink/__pycache__/nslink.cpython-39.pyc
Ðазад
a ]�h� � @ s� d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m Z ddlmZ ddl mZmZ dd lmZmZmZ e�e�ZG d d� de�ZG dd � d ee�ZdS )ae NetNS objects ============= A NetNS object is IPRoute-like. It runs in the main network namespace, but also creates a proxy process running in the required netns. All the netlink requests are done via that proxy process. NetNS supports standard IPRoute API, so can be used instead of IPRoute, e.g., in IPDB:: # start the main network settings database: ipdb_main = IPDB() # start the same for a netns: ipdb_test = IPDB(nl=NetNS('test')) # create VETH ipdb_main.create(ifname='v0p0', kind='veth', peer='v0p1').commit() # move peer VETH into the netns with ipdb_main.interfaces.v0p1 as veth: veth.net_ns_fd = 'test' # please keep in mind, that netns move clears all the settings # on a VETH interface pair, so one should run netns assignment # as a separate operation only # assign addresses # please notice, that `v0p1` is already in the `test` netns, # so should be accessed via `ipdb_test` with ipdb_main.interfaces.v0p0 as veth: veth.add_ip('172.16.200.1/24') veth.up() with ipdb_test.interfaces.v0p1 as veth: veth.add_ip('172.16.200.2/24') veth.up() Please review also the test code, under `tests/test_netns.py` for more examples. By default, NetNS creates requested netns, if it doesn't exist, or uses existing one. To control this behaviour, one can use flags as for `open(2)` system call:: # create a new netns or fail, if it already exists netns = NetNS('test', flags=os.O_CREAT | os.O_EXCL) # create a new netns or use existing one netns = NetNS('test', flags=os.O_CREAT) # the same as above, the default behaviour netns = NetNS('test') To remove a network namespace:: from pyroute2 import NetNS netns = NetNS('test') netns.close() netns.remove() One should stop it first with `close()`, and only after that run `remove()`. � N)�partial)�RTNL_API)�RTMGRP_DEFAULTS)�MarshalRtnl)�remove�setns� )�RemoteSocket�Server� Transportc @ s$ e Zd Zdd� Zdd� Zdd� ZdS )�FDc C s. || _ dD ]}t| |ttt|�| j �� q d S )N)�read�write�close)�fd�setattrr �getattr�os)�selfr �name� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/pyroute2/nslink/nslink.py�__init__T s zFD.__init__c C s | j S �N)r �r r r r �filenoY s z FD.filenoc C s d S r r r r r r �flush\ s zFD.flushN)�__name__� __module__�__qualname__r r r r r r r r S s r c s� e Zd ZdZejddef� fdd� Zdd� Zdd� Z e jf� fd d � Z� fdd�Z � fd d�Z� fdd�Zdd� Zdd� Z� ZS )�NetNSa8 NetNS is the IPRoute API with network namespace support. **Why not IPRoute?** The task to run netlink commands in some network namespace, being in another network namespace, requires the architecture, that differs too much from a simple Netlink socket. NetNS starts a proxy process in a network namespace and uses `multiprocessing` communication channels between the main and the proxy processes to route all `recv()` and `sendto()` requests/responses. **Any specific API calls?** Nope. `NetNS` supports all the same, that `IPRoute` does, in the same way. It provides full `socket`-compatible API and can be used in poll/select as well. The only difference is the `close()` call. In the case of `NetNS` it is **mandatory** to close the socket before exit. Nc s� || _ || _|p|}dd� t�� D �\}| _dd� t�� D �\| _}t�� | _| jdk�rX|�� |�� |j �� |j �� zt | j | j|d� W n� ty� } z*| j�d|d�� t� |j� W Y d }~nZd }~0 t�y& } z8| j�dttjt|�| j �d�� t� d� W Y d }~n d }~0 0 z"t| j| j||d � W t� d� nt� d� 0 z4| j�� | j�� tt| �j|||d � || _W n t�y� | �� � Y n0 t�| j� t� | _d S )Nc S s g | ]}t t|���qS r �r r ��.0�xr r r � <listcomp>� � z"NetNS.__init__.<locals>.<listcomp>c S s g | ]}t t|���qS r r! r"