Exemple #1
0
 def delete_prefix(self, prefix):
     """Delete a range of keys with a prefix in etcd."""
     delete_request = self._build_delete_request(
         prefix, range_end=utils.prefix_range_end(utils.to_bytes(prefix)))
     return self.kvstub.DeleteRange(delete_request,
                                    self.timeout,
                                    credentials=self.call_credentials,
                                    metadata=self.metadata)
Exemple #2
0
    def watch_prefix_once(self, key_prefix, timeout=None, **kwargs):
        """
        Watch a range of keys with a prefix and stop after the first event.

        If the timeout was specified and event didn't arrive method
        will raise ``WatchTimedOut`` exception.
        """
        kwargs['range_end'] = \
            utils.prefix_range_end(utils.to_bytes(key_prefix))
        return self.watch_once(key_prefix, timeout=timeout, **kwargs)
 def test_transaction_range_conditions(self, etcd):
     etcdctl('put', '/doot/key1', 'dootdoot')
     etcdctl('put', '/doot/key2', 'notdootdoot')
     range_end = utils.prefix_range_end(utils.to_bytes('/doot/'))
     compare = [etcd.transactions.value('/doot/', range_end) == 'dootdoot']
     status, _ = etcd.transaction(compare=compare, success=[], failure=[])
     assert not status
     etcdctl('put', '/doot/key2', 'dootdoot')
     status, _ = etcd.transaction(compare=compare, success=[], failure=[])
     assert status
Exemple #4
0
    def watch_prefix(self, key_prefix, **kwargs):
        """
        Watch a range of keys with a prefix.

        :param key_prefix: prefix to watch

        :returns: tuple of ``events_iterator`` and ``cancel``.
        """
        kwargs['range_end'] = \
            utils.prefix_range_end(utils.to_bytes(key_prefix))
        return self.watch(key_prefix, **kwargs)
Exemple #5
0
    def get_prefix_response(self, key_prefix, **kwargs):
        """Get a range of keys with a prefix."""
        if any(kwarg in kwargs for kwarg in ("key", "range_end")):
            raise TypeError("Don't use key or range_end with prefix")

        range_request = self._build_get_range_request(
            key=key_prefix,
            range_end=utils.prefix_range_end(utils.to_bytes(key_prefix)),
            **kwargs)

        return self.kvstub.Range(range_request,
                                 self.timeout,
                                 credentials=self.call_credentials,
                                 metadata=self.metadata)
Exemple #6
0
    def add_watch_prefix_callback(self, key_prefix, callback, **kwargs):
        """
        Watch a prefix and call a callback on every response.

        If timeout was declared during the client initialization and
        the watch cannot be created during that time the method raises
        a ``WatchTimedOut`` exception.

        :param key_prefix: prefix to watch
        :param callback: callback function

        :returns: watch_id. Later it could be used for cancelling watch.
        """
        kwargs['range_end'] = \
            utils.prefix_range_end(utils.to_bytes(key_prefix))

        return self.add_watch_callback(key_prefix, callback, **kwargs)