]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/rados: add get_id and get_name method in class Ioctx
authorzhengyin <zhengyin@cmss.chinamobile.com>
Wed, 14 Aug 2019 02:27:15 +0000 (22:27 -0400)
committerzhengyin <zhengyin@cmss.chinamobile.com>
Wed, 14 Aug 2019 09:22:58 +0000 (05:22 -0400)
Signed-off-by: Zheng Yin <zhengyin@cmss.chinamobile.com>
src/pybind/rados/rados.pyx
src/test/pybind/test_rados.py

index 9220880d10a30b2b740ce9677fa5ae5a09e95d7d..01b25d207d268fb201ca704b6b603138eacfd540 100644 (file)
@@ -232,6 +232,8 @@ cdef extern from "rados/librados.h" nogil:
     void rados_ioctx_snap_set_read(rados_ioctx_t io, rados_snap_t snap)
     int rados_ioctx_snap_list(rados_ioctx_t io, rados_snap_t * snaps, int maxlen)
     int rados_ioctx_snap_get_stamp(rados_ioctx_t io, rados_snap_t id, time_t * t)
+    uint64_t rados_ioctx_get_id(rados_ioctx_t io)
+    int rados_ioctx_get_pool_name(rados_ioctx_t io, char *buf, unsigned maxlen)
 
     int rados_ioctx_selfmanaged_snap_create(rados_ioctx_t io,
                                             rados_snap_t *snapid)
@@ -3192,6 +3194,43 @@ returned %d, but should return zero on success." % (self.name, ret))
         self.require_ioctx_open()
         return SnapIterator(self)
 
+    def get_pool_id(self):
+        """
+        Get pool id
+
+        :returns: int - pool id
+        """
+        with nogil:
+            ret = rados_ioctx_get_id(self.io)
+        return ret;
+
+    def get_pool_name(self):
+        """
+        Get pool name
+
+        :returns: str - pool name
+        """
+        cdef:
+            int name_len = 10
+            char *name = NULL
+
+        try:
+            while True:
+                name = <char *>realloc_chk(name, name_len)
+                with nogil:
+                    ret = rados_ioctx_get_pool_name(self.io, name, name_len)
+                if ret > 0:
+                    break
+                elif ret != -errno.ERANGE:
+                    raise make_ex(ret, "get pool name error")
+                else:
+                    name_len = name_len * 2
+
+            return decode_cstr(name)
+        finally:
+            free(name)
+
+
     @requires(('snap_name', str_type))
     def create_snap(self, snap_name):
         """
index c4ed1d248b3d2705151dded3990923bd0af09f23..9f8358b32871c476b0a6148c42142467bfc5e689 100644 (file)
@@ -384,6 +384,12 @@ class TestIoctx(object):
             stored_xattrs[key] = value
         eq(stored_xattrs, xattrs)
 
+    def test_get_pool_id(self):
+        eq(self.ioctx.get_pool_id(), self.rados.pool_lookup('test_pool'))
+
+    def test_get_pool_name(self):
+        eq(self.ioctx.get_pool_name(), 'test_pool')
+
     def test_create_snap(self):
         assert_raises(ObjectNotFound, self.ioctx.remove_snap, 'foo')
         self.ioctx.create_snap('foo')