From: zhengyin Date: Fri, 2 Aug 2019 07:26:20 +0000 (-0400) Subject: pybind/rbd: add config_image_set/get/remove api in rbd.pyx X-Git-Tag: v15.1.0~1787^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6eb39dbb64f818bd9b7814241ae66929765751c1;p=ceph.git pybind/rbd: add config_image_set/get/remove api in rbd.pyx Signed-off-by: Zheng Yin --- diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index 0ce81e7285d..fa04f5f57e2 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -4459,10 +4459,87 @@ written." % (self.name, ret, length)) """ List image-level config overrides. - :returns: :class:`ConfigPoolIterator` + :returns: :class:`ConfigImageIterator` """ return ConfigImageIterator(self) + + def config_set(self, key, value): + """ + Set an image-level configuration override. + + :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: + char *_key = conf_key + char *_value = value + with nogil: + ret = rbd_metadata_set(self.image, _key, _value) + + if ret != 0: + raise make_ex(ret, 'error setting config %s for image %s' % + (key, self.name)) + + + def config_get(self, key): + """ + Get an image-level configuration override. + + :param key: key + :type key: str + :returns: str - value + """ + conf_key = 'conf_' + key + conf_key = cstr(conf_key, 'key') + cdef: + 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_metadata_get(self.image, _key, value, &size) + if ret != -errno.ERANGE: + break + if ret == -errno.ENOENT: + raise KeyError('no config %s for image %s' % (key, self.name)) + if ret != 0: + raise make_ex(ret, 'error getting config %s for image %s' % + (key, self.name)) + return decode_cstr(value) + finally: + free(value) + + + def config_remove(self, key): + """ + Remove an image-level configuration override. + + :param key: key + :type key: str + """ + conf_key = 'conf_' + key + conf_key = cstr(conf_key, 'key') + cdef: + char *_key = conf_key + with nogil: + ret = rbd_metadata_remove(self.image, _key) + + if ret == -errno.ENOENT: + raise KeyError('no config %s for image %s' % (key, self.name)) + if ret != 0: + raise make_ex(ret, 'error removing config %s for image %s' % + (key, self.name)) + + def snap_get_namespace_type(self, snap_id): """ Get the snapshot namespace type.