]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: add pybindings for cgroup_setup_mode() helpers
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 24 Apr 2023 09:02:44 +0000 (09:02 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 26 Apr 2023 19:27:24 +0000 (13:27 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Fixed a few comment typos

src/python/cgroup.pxd
src/python/libcgroup.pyx

index 4e48b8aca6c18160224bd42afcd38781bf0bc1e9..a27088e5df04ed0aaca04e50d4bc61131e9a0731 100644 (file)
@@ -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:
index 7e8a2d8d27fd5cc016150b843835adde33769ac6..d7b0d42fe98a1ab47dcd078f3e4c8c9bccba0d6d 100644 (file)
@@ -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);