diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-30 13:26:22 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-30 15:44:45 +0300 |
commit | 0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch) | |
tree | 291d72dbd7e9865399f668c84d11ed86fb190bbf /library/python/nstools | |
parent | cb2c8d75065e5b3c47094067cb4aa407d4813298 (diff) | |
download | ydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz |
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'library/python/nstools')
-rw-r--r-- | library/python/nstools/__init__.py | 6 | ||||
-rw-r--r-- | library/python/nstools/nstools.pyx | 28 | ||||
-rw-r--r-- | library/python/nstools/ya.make | 14 |
3 files changed, 48 insertions, 0 deletions
diff --git a/library/python/nstools/__init__.py b/library/python/nstools/__init__.py new file mode 100644 index 0000000000..34cc0f9574 --- /dev/null +++ b/library/python/nstools/__init__.py @@ -0,0 +1,6 @@ +from .nstools import unshare_ns, move_to_ns + +__all__ = [ + 'unshare_ns', + 'move_to_ns' +] diff --git a/library/python/nstools/nstools.pyx b/library/python/nstools/nstools.pyx new file mode 100644 index 0000000000..5ef30373ff --- /dev/null +++ b/library/python/nstools/nstools.pyx @@ -0,0 +1,28 @@ +from cpython.exc cimport PyErr_SetFromErrno + +cdef extern from "<sched.h>" nogil: + int setns(int fd, int mode) + int unshare(int flags) + + cpdef enum: + Fs "CLONE_FS" + # Cgroup "CLONE_NEWCGROUP" + Ipc "CLONE_NEWIPC" + Network "CLONE_NEWNET" + Mount "CLONE_NEWNS" + Pid "CLONE_NEWPID" + User "CLONE_NEWUSER" + Uts "CLONE_NEWUTS" + +def unshare_ns(int flags): + cdef int ret = unshare(flags) + if ret != 0: + PyErr_SetFromErrno(OSError) + +def move_to_ns(object fileobject, int mode): + if not isinstance(fileobject, int): + fileobject = fileobject.fileno() + + cdef int ret = setns(fileobject, mode) + if ret != 0: + PyErr_SetFromErrno(OSError) diff --git a/library/python/nstools/ya.make b/library/python/nstools/ya.make new file mode 100644 index 0000000000..49eddeb919 --- /dev/null +++ b/library/python/nstools/ya.make @@ -0,0 +1,14 @@ +PY23_LIBRARY() + +IF(OS_LINUX) +PY_SRCS( + __init__.py + nstools.pyx +) +ELSE() +PY_SRCS( + nstools.py +) +ENDIF() + +END() |