跳转到主要内容

从Python进入内核命名空间

项目描述

Travis CI build status

此Python包允许通过执行“setns”系统调用进入Linux内核命名空间(挂载、IPC、net、PID、user和UTS)。命令行界面试图与nsenter C程序类似。

需要Python 2.6或更高版本

参见博客文章“从Python进入内核命名空间”的简介。

从PyPI安装

sudo pip3 install nsenter

从git源安装

python3 setup.py install

示例命令行使用

docker run -d --name=redis -t redis
sudo nsenter --all --target=`docker inspect --format '{{ .State.Pid }}' redis` /bin/bash

从Python的示例使用

import subprocess
from nsenter import Namespace

with Namespace(mypid, 'net'):
    # output network interfaces as seen from within the mypid's net NS:
    subprocess.check_output(['ip', 'a'])

# or enter an arbitrary namespace:
with Namespace('/var/run/netns/foo', 'net'):
    # output network interfaces as seen from within the net NS "foo":
    subprocess.check_output(['ip', 'a'])

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

nsenter-0.2.tar.gz (4.3 kB 查看哈希值)

上传于 源代码

构建分发

nsenter-0.2-py3-none-any.whl (12.3 kB 查看哈希值)

上传于 Python 3

支持者