]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/rbd: add pool config_set/get/remove api in rbd.pyx
authorzhengyin <zhengyin@cmss.chinamobile.com>
Thu, 10 Oct 2019 12:18:45 +0000 (20:18 +0800)
committerzhengyin <zhengyin@cmss.chinamobile.com>
Thu, 10 Oct 2019 12:18:45 +0000 (20:18 +0800)
Signed-off-by: Zheng Yin <zhengyin@cmss.chinamobile.com>
src/pybind/rbd/rbd.pyx

index 9aae566c623676c9a828f7fcdf0d9832933d064c..3a0bd7b5f1c7fdc52c53d71ed24a7984c8641a7c 100644 (file)
@@ -2146,6 +2146,90 @@ class RBD(object):
         """
         return ConfigPoolIterator(ioctx)
 
+    def config_get(self, ioctx, key):
+        """
+        Get a pool-level configuration override.
+
+        :param ioctx: determines which RADOS pool is read
+        :type ioctx: :class:`rados.Ioctx`
+        :param key: key
+        :type key: str
+        :returns: str - value
+        """
+        conf_key = 'conf_' + key
+        conf_key = cstr(conf_key, 'key')
+        cdef:
+            rados_ioctx_t _ioctx = convert_ioctx(ioctx)
+            char *_key = conf_key
+            size_t size = 4096
+            char *value = NULL
+            int ret
+        try:
+            while True:
+                value = <char *>realloc_chk(value, size)
+                with nogil:
+                    ret = rbd_pool_metadata_get(_ioctx, _key, value, &size)
+                if ret != -errno.ERANGE:
+                    break
+            if ret == -errno.ENOENT:
+                raise KeyError('no config %s for pool %s' % (key, ioctx.get_pool_name()))
+            if ret != 0:
+                raise make_ex(ret, 'error getting config %s for pool %s' %
+                             (key, ioctx.get_pool_name()))
+            return decode_cstr(value)
+        finally:
+            free(value)
+
+    def config_set(self, ioctx, key, value):
+        """
+        Get a pool-level configuration override.
+
+        :param ioctx: determines which RADOS pool is read
+        :type ioctx: :class:`rados.Ioctx`
+        :param key: key
+        :type key: str
+        :param value: value
+        :type value: str
+        """
+        conf_key = 'conf_' + key
+        conf_key = cstr(conf_key, 'key')
+        value = cstr(value, 'value')
+        cdef:
+            rados_ioctx_t _ioctx = convert_ioctx(ioctx)
+            char *_key = conf_key
+            char *_value = value
+        with nogil:
+            ret = rbd_pool_metadata_set(_ioctx, _key, _value)
+
+        if ret != 0:
+            raise make_ex(ret, 'error setting config %s for pool %s' %
+                          (key, ioctx.get_pool_name()))
+
+    def config_remove(self, ioctx, key):
+        """
+        Remove a pool-level configuration override.
+
+        :param ioctx: determines which RADOS pool is read
+        :type ioctx: :class:`rados.Ioctx`
+        :param key: key
+        :type key: str
+        :returns: str - value
+        """
+        conf_key = 'conf_' + key
+        conf_key = cstr(conf_key, 'key')
+        cdef:
+            rados_ioctx_t _ioctx = convert_ioctx(ioctx)
+            char *_key = conf_key
+        with nogil:
+            ret = rbd_pool_metadata_remove(_ioctx, _key)
+
+        if ret == -errno.ENOENT:
+            raise KeyError('no config %s for pool %s' %
+                           (key, ioctx.get_pool_name()))
+        if ret != 0:
+            raise make_ex(ret, 'error removing config %s for pool %s' %
+                          (key, ioctx.get_pool_name()))
+
     def group_create(self, ioctx, name):
         """
         Create a group.