Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/pyroute2/netns/__pycache__/__init__.cpython-39.pyc
Ðазад
a ]�h�) � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl mZ ddlm Z zeZW n ey� ejZY n0 ddiddiddid d d�ddidd id dd�ddiddiddiddid�Ze�ejdd� i ��ejd�ZdZdZdZdZdZdZg adadd� Zd5dd�Zd6dd�Z efdd�Z!efd d!�Z"d"efd#d$�Z#d7d%d&�Z$d8d'd(�Z%d9d)d*�Z&d:d+d,�Z'ej(dfd-d.�Z)d;d/d0�Z*d<d1d2�Z+d=d3d4�Z,dS )>a� Basic network namespace management ================================== Pyroute2 provides basic namespaces management support. Here's a quick overview of typical netns tasks and related pyroute2 tools. Move an interface to a namespace -------------------------------- Though this task is managed not via `netns` module, it should be mentioned here as well. To move an interface to a netns, one should provide IFLA_NET_NS_FD nla in a set link RTNL request. The nla is an open FD number, that refers to already created netns. The pyroute2 library provides also a possibility to specify not a FD number, but a netns name as a string. In that case the library will try to lookup the corresponding netns in the standard location. Create veth and move the peer to a netns with IPRoute:: from pyroute2 import IPRoute ipr = IPRoute() ipr.link('add', ifname='v0p0', kind='veth', peer='v0p1') idx = ipr.link_lookup(ifname='v0p1')[0] ipr.link('set', index=idx, net_ns_fd='netns_name') Create veth and move the peer to a netns with IPDB:: from pyroute2 import IPDB ipdb = IPDB() ipdb.create(ifname='v0p0', kind='veth', peer='v0p1').commit() with ipdb.interfaces.v0p1 as i: i.net_ns_fd = 'netns_name' Manage interfaces within a netns -------------------------------- This task can be done with `NetNS` objects. A `NetNS` object spawns a child and runs it within a netns, providing the same API as `IPRoute` does:: from pyroute2 import NetNS ns = NetNS('netns_name') # do some stuff within the netns ns.close() One can even start `IPDB` on the top of `NetNS`:: from pyroute2 import NetNS from pyroute2 import IPDB ns = NetNS('netns_name') ipdb = IPDB(nl=ns) # do some stuff within the netns ipdb.release() ns.close() Spawn a process within a netns ------------------------------ For that purpose one can use `NSPopen` API. It works just as normal `Popen`, but starts a process within a netns. List, set, create, attach and remove netns ------------------------------------------ These functions are described below. To use them, import `netns` module:: from pyroute2 import netns netns.listnetns() Please be aware, that in order to run system calls the library uses `ctypes` module. It can fail on platforms where SELinux is enforced. If the Python interpreter, loading this module, dumps the core, one can check the SELinux state with `getenforce` command. � N)�config)� basestring�64biti4 �32bitiZ i� i� )r r i iw i^ iS )Zx86_�i386�i686�mipsZloonZarmvZaarcZppc6Zs390�loongarch64Zrisc� i @� i i @ i z/var/run/netnsc C s8 | }t j�| �}|s dt| f }t|d�r4|�d�}|S )Nz%s/%s�encode�ascii)�os�path�dirname� NETNS_RUN_DIR�hasattrr )�name� netnspathr � r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/pyroute2/netns/__init__.py�_get_netnspath� s r c C s. | d ur| S t d u r*tjtj�d�dd�a t S )N�cT)Z use_errno)�__libc�ctypes�CDLL�utilZfind_library��libcr r r � _get_libc� s r c C s6 | r | }nt }zt�|�W S ty0 g Y S 0 dS )z, List available network namespaces. N)r r �listdir�FileNotFoundError)�nspathZnsdirr r r � listnetns� s r# c C sp i }t | d�D ]\}tj�| |�}zt�|�}W n tyD Y qY n0 |j|vrZi ||j<