From: Kamalesh Babulal Date: Mon, 24 Apr 2023 09:02:44 +0000 (+0000) Subject: python: add pybindings for cgroup_setup_mode() helpers X-Git-Tag: v3.1.0~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a50a81bd3538ad5a3149e00a5a6ddb428f73e259;p=thirdparty%2Flibcgroup.git python: add pybindings for cgroup_setup_mode() helpers Add pybindings for the cgroup_setup_mode() helper functions: - is_cgroup_mode_legacy() - is_cgroup_mode_hybrid() - is_cgroup_mode_unified() Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka TJH: Fixed a few comment typos --- diff --git a/src/python/cgroup.pxd b/src/python/cgroup.pxd index 4e48b8ac..a27088e5 100644 --- a/src/python/cgroup.pxd +++ b/src/python/cgroup.pxd @@ -9,6 +9,7 @@ # cython: language_level = 3str from posix.types cimport pid_t, uid_t, gid_t, mode_t +from libcpp cimport bool cdef extern from "libcgroup.h": cdef struct cgroup: @@ -107,4 +108,11 @@ cdef extern from "libcgroup.h": int cgroup_compare_cgroup(cgroup *cgroup_a, cgroup *cgroup_b) int cgroup_get_procs(char *name, char *controller, pid_t **pids, int *size) + + bool is_cgroup_mode_legacy() + + bool is_cgroup_mode_hybrid() + + bool is_cgroup_mode_unified() + # vim: set et ts=4 sw=4: diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index 7e8a2d8d..d7b0d42f 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -627,6 +627,33 @@ cdef class Cgroup: return pid_list + @staticmethod + def is_cgroup_mode_legacy(): + """Check if the current setup mode is legacy (v1) + + Return: + True if the mode is legacy, else false + """ + return cgroup.is_cgroup_mode_legacy() + + @staticmethod + def is_cgroup_mode_hybrid(): + """Check if the current setup mode is hybrid (v1/v2) + + Return: + True if the mode is hybrid, else false + """ + return cgroup.is_cgroup_mode_hybrid() + + @staticmethod + def is_cgroup_mode_unified(): + """Check if the current setup mode is unified (v2) + + Return: + True if the mode is unified, else false + """ + return cgroup.is_cgroup_mode_unified() + def __dealloc__(self): cgroup.cgroup_free(&self._cgp);