File: //opt/alt/python311/lib/python3.11/site-packages/pyroute2/nslink/__pycache__/nslink.cpython-311.pyc
�
�;f� � �� � d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
Z
ddlmZ ddl
mZmZ dd lmZmZmZ ej e� � Z G d
� de� � Z G d� 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 � � e Zd Zd� Zd� Zd� ZdS )�FDc � � || _ dD ]9}t | |t t t |� � | j � � � � �:d S )N)�read�write�close)�fd�setattrr �getattr�os)�selfr �names �I/opt/alt/python311/lib/python3.11/site-packages/pyroute2/nslink/nslink.py�__init__zFD.__init__T sQ � ����.� E� E�D��D�$����D�(9�(9�4�7� C� C�D�D�D�D� E� E� c � � | j S �N)r �r s r �filenoz FD.filenoY s � ��w�r c � � d S r � r s r �flushzFD.flush\ s � ��tr N)�__name__�
__module__�__qualname__r r r"