]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/pybind/rados: add binding for rados_notify2
authorJeff Layton <jlayton@redhat.com>
Tue, 5 Feb 2019 10:59:17 +0000 (10:59 +0000)
committerRicardo Dias <rdias@suse.com>
Tue, 5 Feb 2019 11:00:38 +0000 (11:00 +0000)
Add a new Ioctx.notify operation that we can call to send a rados
notification over an object.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/pybind/rados/rados.pyx

index f65b10d01389dec685076bcbf7182021e5d3b999..dfa3b922c1c67bbce76c060f9b862627e4ec2689 100644 (file)
@@ -305,6 +305,7 @@ cdef extern from "rados/librados.h" nogil:
     void rados_read_op_set_flags(rados_read_op_t read_op, int flags)
     int rados_omap_get_next(rados_omap_iter_t iter, const char * const* key, const char * const* val, size_t * len)
     void rados_omap_get_end(rados_omap_iter_t iter)
+    int rados_notify2(rados_ioctx_t io, const char * o, const char *buf, int buf_len, uint64_t timeout_ms, char **reply_buffer, size_t *reply_buffer_len)
 
 
 LIBRADOS_OP_FLAG_EXCL = _LIBRADOS_OP_FLAG_EXCL
@@ -3073,6 +3074,40 @@ returned %d, but should return zero on success." % (self.name, ret))
                           (key, xattr_name))
         return True
 
+    @requires(('obj', str_type), ('msg', str_type), ('timeout_ms', int))
+    def notify(self, obj, msg='', timeout_ms=5000):
+        """
+        Send a rados notification to an object.
+
+        :param obj: the name of the object to notify
+        :type obj: str
+        :param msg: optional message to send in the notification
+        :type msg: str
+        :param timeout_ms: notify timeout (in ms)
+        :type timeout_ms: int
+
+        :raises: :class:`TypeError`
+        :raises: :class:`Error`
+        :returns: bool - True on success, otherwise raise an error
+        """
+        self.require_ioctx_open()
+
+        msglen = len(msg)
+        obj = cstr(obj, 'obj')
+        msg = cstr(msg, 'msg')
+        cdef:
+            char *_obj = obj
+            char *_msg = msg
+            int _msglen = msglen
+            uint64_t _timeout_ms = timeout_ms
+
+        with nogil:
+            ret = rados_notify2(self.io, _obj, _msg, _msglen, _timeout_ms,
+                                NULL, NULL)
+        if ret < 0:
+            raise make_ex(ret, "Failed to notify %r" % (obj))
+        return True
+
     def list_objects(self):
         """
         Get ObjectIterator on rados.Ioctx object.