From 5ed84ad3eb8f9af1a070c60defbce3fb3f16d247 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Fri, 29 Apr 2022 10:52:25 -0600 Subject: [PATCH] python: Make Cgroup.mount_points() more pythonic Rename cgroup_list_mount_points() to mount_points() and convert it to an @staticmethod. Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- src/python/libcgroup.pyx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index e3e27d26..f1d361d9 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -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: -- 2.47.2