]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
python: Make Cgroup.mount_points() more pythonic
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 29 Apr 2022 16:52:25 +0000 (10:52 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 29 Apr 2022 16:52:25 +0000 (10:52 -0600)
Rename cgroup_list_mount_points() to mount_points() and
convert it to an @staticmethod.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
src/python/libcgroup.pyx

index e3e27d2641581127ab925e62de5b7ae47c77838f..f1d361d904a262fc0aed076806b807efe5d7c777 100644 (file)
@@ -51,11 +51,15 @@ cdef class Cgroup:
     cdef public:
         object name, controllers, version
 
-    def __cinit__(self, name, version):
+    @staticmethod
+    def cgroup_init():
         ret = cgroup.cgroup_init()
         if ret != 0:
             raise RuntimeError("Failed to initialize libcgroup: {}".format(ret))
 
+    def __cinit__(self, name, version):
+        Cgroup.cgroup_init()
+
         self._cgp = cgroup.cgroup_new_cgroup(c_str(name))
         if self._cgp == NULL:
             raise RuntimeError("Failed to create cgroup {}".format(name))
@@ -277,18 +281,24 @@ cdef class Cgroup:
         if ret != 0:
             raise RuntimeError("Failed to create cgroup: {}".format(ret))
 
-    def cgroup_list_mount_points(self, version):
+    @staticmethod
+    def mount_points(version):
         """List cgroup mount points of the specified version
 
         Arguments:
         version - It specifies the cgroup version
 
+        Return:
+        The cgroup mount points in a list
+
         Description:
         Parse the /proc/mounts and list the cgroup mount points matching the
         version
         """
         cdef char **a
 
+        Cgroup.cgroup_init()
+
         mount_points = []
         ret = cgroup.cgroup_list_mount_points(version, &a)
         if ret is not 0: