]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs/pybind: Add get_pool_id, get_pool_replication
authorKotresh HR <khiremat@redhat.com>
Wed, 4 Mar 2020 12:03:34 +0000 (17:33 +0530)
committerKotresh HR <khiremat@redhat.com>
Tue, 14 Apr 2020 10:39:34 +0000 (16:09 +0530)
Fixes: https://tracker.ceph.com/issues/44171
Signed-off-by: Kotresh HR <khiremat@redhat.com>
src/pybind/cephfs/cephfs.pyx

index 07b17067609c48d28698b95fbd42bb569d565d60..9fee58933fd5088f22b57e4bb8532487305a9b53 100644 (file)
@@ -225,6 +225,8 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_futimens(ceph_mount_info *cmount, int fd, timespec times[2])
     int ceph_get_file_replication(ceph_mount_info *cmount, int fh)
     int ceph_get_path_replication(ceph_mount_info *cmount, const char *path)
+    int ceph_get_pool_id(ceph_mount_info *cmount, const char *pool_name)
+    int ceph_get_pool_replication(ceph_mount_info *cmount, int pool_id)
 
 
 class Error(Exception):
@@ -2195,3 +2197,44 @@ cdef class LibCephFS(object):
             raise make_ex(ret, "error in get_path_replication")
 
         return ret
+
+    def get_pool_id(self, pool_name):
+        """
+        Get the id of the named pool.
+
+        :param pool_name: the name of the pool.
+        """
+
+        self.require_state("mounted")
+        pool_name = cstr(pool_name, 'pool_name')
+
+        cdef:
+            char* _pool_name = pool_name
+
+        with nogil:
+            ret = ceph_get_pool_id(self.cluster, _pool_name)
+        if ret < 0:
+            raise make_ex(ret, "error in get_pool_id")
+
+        return ret
+
+    def get_pool_replication(self, pool_id):
+        """
+        Get the pool replication factor.
+
+        :param pool_id: the pool id to look up
+        """
+
+        self.require_state("mounted")
+        if not isinstance(pool_id, int):
+            raise TypeError('pool_id must be an int')
+
+        cdef:
+            int _pool_id = pool_id
+
+        with nogil:
+            ret = ceph_get_pool_replication(self.cluster, _pool_id)
+        if ret < 0:
+            raise make_ex(ret, "error in get_pool_replication")
+
+        return ret