From c39570fa376a7b3d688fe82d486bc408d6799f7e Mon Sep 17 00:00:00 2001 From: zhengyin Date: Thu, 10 Oct 2019 20:18:45 +0800 Subject: [PATCH] pybind/rbd: add pool config_set/get/remove api in rbd.pyx Signed-off-by: Zheng Yin --- src/pybind/rbd/rbd.pyx | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index 9aae566c623..3a0bd7b5f1c 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -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 = 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. -- 2.39.5