Пример #1
0
class Replace(Step):
    """\"Replace\" operation"""

    TAG = 16
    ARGS = ('key', protocol.STRING), \
           ('wanted', protocol.Option(protocol.STRING))

    def __init__(self, key, wanted):
        super(Replace, self).__init__(key, wanted)

        self._key = key
        self._wanted = wanted

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
Key for which the value needs to be replaced

:type: :class:`str`
'''))
    wanted = property(operator.attrgetter('_wanted'),
                      doc=utils.format_doc('''
Value to set the key to or None to delete the key

:type: :class:`str` or :data:`None`
'''))
Пример #2
0
class Assert(Step):
    '''"Assert" operation'''

    TAG = 8
    ARGS = ('key', protocol.STRING), \
        ('value', protocol.Option(protocol.STRING)),

    def __init__(self, key, value):
        super(Assert, self).__init__(key, value)

        self._key = key
        self._value = value

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key for which to assert the given value

            :type: :class:`str`
        '''))
    value = property(operator.attrgetter('_value'),
                     doc=utils.format_doc('''
            Expected value

            :type: :class:`str` or :data:`None`
        '''))
Пример #3
0
class Assert(Message):
    '''"assert" message'''

    __slots__ = '_allow_dirty', '_key', '_value',

    TAG = 0x0016 | Message.MASK
    ARGS = ALLOW_DIRTY_ARG, ('key', STRING), ('value', Option(STRING)),
    RETURN_TYPE = UNIT

    DOC = utils.format_doc('''
        Send an "assert" command to the server

        `assert key vo` throws an exception if the value associated with the
        key is not what was expected.

        :param key: Key to check
        :type key: :class:`str`
        :param value: Optional value to compare
        :type value: :class:`str` or :data:`None`
        :param allow_dirty: Allow reads from slave nodes
        :type allow_dirty: :class:`bool`
    ''')

    def __init__(self, allow_dirty, key, value):
        super(Assert, self).__init__()

        self._allow_dirty = allow_dirty
        self._key = key
        self._value = value

    allow_dirty = property(operator.attrgetter('_allow_dirty'))
    key = property(operator.attrgetter('_key'))
    value = property(operator.attrgetter('_value'))
Пример #4
0
class Exists(Message):
    '''"exists" message'''

    __slots__ = '_allow_dirty', '_key',

    TAG = 0x0007 | Message.MASK
    ARGS = ALLOW_DIRTY_ARG, ('key', STRING),
    RETURN_TYPE = BOOL

    DOC = utils.format_doc('''
        Send an "exists" command to the server

        This method returns a boolean which tells whether the given `key` is
        set on the server.

        :param key: Key to test
        :type key: :class:`str`
        :param allow_dirty: Allow reads from slave nodes
        :type allow_dirty: :class:`bool`

        :return: Whether the given key is set on the server
        :rtype: :class:`bool`
    ''')

    def __init__(self, allow_dirty, key):
        super(Exists, self).__init__()

        self._allow_dirty = allow_dirty
        self._key = key

    key = property(operator.attrgetter('_key'))
    allow_dirty = property(operator.attrgetter('_allow_dirty'))
Пример #5
0
class UserFunction(Message):
    '''"user_function" message'''

    __slots__ = '_function', '_arg',

    TAG = 0x0015 | Message.MASK
    ARGS = ('function', STRING), ('argument', Option(STRING)),
    RETURN_TYPE = Option(STRING)

    DOC = utils.format_doc('''
        Send a "user_function" command to the server

        This method returns the result of the function invocation.

        :param function: Name of the user function to invoke
        :type function: :class:`str`
        :param argument: Argument to pass to the function
        :type argument: :class:`str` or :data:`None`

        :return: Result of the function invocation
        :rtype: :class:`str` or :data:`None`
    ''')

    def __init__(self, function, argument):
        super(UserFunction, self).__init__()

        self._function = function
        self._argument = argument

    function = property(operator.attrgetter('_function'))
    argument = property(operator.attrgetter('_argument'))
Пример #6
0
class MultiGetOption(Message):
    '''"multi_get_option" message'''

    __slots__ = '_allow_dirty', '_keys',

    TAG = 0x0031 | Message.MASK
    ARGS = ALLOW_DIRTY_ARG, ('keys', List(STRING)),
    RETURN_TYPE = Array(Option(STRING))

    DOC = utils.format_doc('''
        Send a "multi_get_option" command to the server

        This method returns a list of value options for all requested keys.

        :param keys: Keys to look up
        :type keys: iterable of :class:`str`
        :param allow_dirty: Allow reads from slave nodes
        :type allow_dirty: :class:`bool`

        :return: Requested values
        :rtype: iterable of (`str` or `None`)
    ''')

    def __init__(self, allow_dirty, keys):
        super(MultiGetOption, self).__init__()

        self._allow_dirty = allow_dirty
        self._keys = keys

    allow_dirty = property(operator.attrgetter('_allow_dirty'))
    keys = property(operator.attrgetter('_keys'))
Пример #7
0
class Get(Message):
    '''"get" message'''

    __slots__ = '_consistency', '_key',

    TAG = 0x0008 | Message.MASK
    ARGS = CONSISTENCY_ARG, ('key', STRING),
    RETURN_TYPE = STRING

    DOC = utils.format_doc('''
        Send a "get" command to the server

        This method returns the value of the requested key.

        :param key: Key to retrieve
        :type key: :class:`str`
        :param consistency: Allow reads from stale nodes
        :type consistency: :class:`pyrakoon.consistency.Consistency`

        :return: Value for the given key
        :rtype: :class:`str`
    ''')

    def __init__(self, consistency, key):
        super(Get, self).__init__()

        self._consistency = consistency
        self._key = key

    consistency = property(operator.attrgetter('_consistency'))
    key = property(operator.attrgetter('_key'))
Пример #8
0
class Exists(Message):
    '''"exists" message'''

    __slots__ = '_consistency', '_key',

    TAG = 0x0007 | Message.MASK
    ARGS = CONSISTENCY_ARG, ('key', STRING),
    RETURN_TYPE = BOOL

    DOC = utils.format_doc('''
        Send an "exists" command to the server

        This method returns a boolean which tells whether the given `key` is
        set on the server.

        :param key: Key to test
        :type key: :class:`str`
        :param consistency: Allow reads from stale nodes
        :type consistency: :class:`pyrakoon.consistency.Consistency`

        :return: Whether the given key is set on the server
        :rtype: :class:`bool`
    ''')

    def __init__(self, consistency, key):
        super(Exists, self).__init__()

        self._consistency = consistency
        self._key = key

    key = property(operator.attrgetter('_key'))
    consistency = property(operator.attrgetter('_consistency'))
Пример #9
0
class Sequence(Step):
    '''"Sequence" operation

    This is a container for a list of other operations.
    '''

    TAG = 5
    ARGS = ()

    def __init__(self, steps):
        super(Sequence, self).__init__()

        self._steps = steps

    steps = property(operator.attrgetter('_steps'),
                     doc=utils.format_doc('''
            Sequence steps

            :type: iterable of :class:`Step`
        '''))

    def serialize(self):
        for bytes_ in protocol.UINT32.serialize(self.TAG):
            yield bytes_

        for bytes_ in protocol.UINT32.serialize(len(self.steps)):
            yield bytes_

        for step in self.steps:
            for bytes_ in step.serialize():
                yield bytes_
Пример #10
0
class AssertExists(Message):
    '''"assert_exists" message'''

    __slots__ = '_consistency', '_key',

    TAG = 0x0029 | Message.MASK
    ARGS = CONSISTENCY_ARG, ('key', STRING),
    RETURN_TYPE = UNIT

    DOC = utils.format_doc('''
        Send an "assert_exists" command to the server

        `assert_exists key` throws an exception if the key doesn't exist in
        the database.

        :param key: Key to check
        :type key: :class:`str`
        :param consistency: Allow reads from stale nodes
        :type consistency: :class:`pyrakoon.consistency.Consistency`
    ''')

    def __init__(self, consistency, key):
        super(AssertExists, self).__init__()

        self._consistency = consistency
        self._key = key

    consistency = property(operator.attrgetter('_consistency'))
    key = property(operator.attrgetter('_key'))
Пример #11
0
class MultiGetOption(Message):
    '''"multi_get_option" message'''

    __slots__ = '_consistency', '_keys',

    TAG = 0x0031 | Message.MASK
    ARGS = CONSISTENCY_ARG, ('keys', List(STRING)),
    RETURN_TYPE = Array(Option(STRING))

    DOC = utils.format_doc('''
        Send a "multi_get_option" command to the server

        This method returns a list of value options for all requested keys.

        :param keys: Keys to look up
        :type keys: iterable of :class:`str`
        :param consistency: Allow reads from stale nodes
        :type consistency: :class:`pyrakoon.consistency.Consistency`

        :return: Requested values
        :rtype: iterable of (`str` or `None`)
    ''')

    def __init__(self, consistency, keys):
        super(MultiGetOption, self).__init__()

        self._consistency = consistency
        self._keys = keys

    consistency = property(operator.attrgetter('_consistency'))
    keys = property(operator.attrgetter('_keys'))
Пример #12
0
class AssertExists(Message):
    '''"assert_exists" message'''

    __slots__ = '_allow_dirty', '_key',

    TAG = 0x0029 | Message.MASK
    ARGS = ALLOW_DIRTY_ARG, ('key', STRING),
    RETURN_TYPE = UNIT

    DOC = utils.format_doc('''
        Send an "assert_exists" command to the server

        `assert_exists key` throws an exception if the key doesn't exist in
        the database.

        :param key: Key to check
        :type key: :class:`str`
        :param allow_dirty: Allow reads from slave nodes
        :type allow_dirty: :class:`bool`
    ''')

    def __init__(self, allow_dirty, key):
        super(AssertExists, self).__init__()

        self._allow_dirty = allow_dirty
        self._key = key

    allow_dirty = property(operator.attrgetter('_allow_dirty'))
    key = property(operator.attrgetter('_key'))
Пример #13
0
class Hello(Message):
    '''"hello" message'''

    __slots__ = '_client_id', '_cluster_id',

    TAG = 0x0001 | Message.MASK
    ARGS = ('client_id', STRING), ('cluster_id', STRING),
    RETURN_TYPE = STRING

    DOC = utils.format_doc('''
        Send a "hello" command to the server

        This method will return the string returned by the server when
        receiving a "hello" command.

        :param client_id: Identifier of the client
        :type client_id: :class:`str`
        :param cluster_id: Identifier of the cluster connecting to. \
            This must match the cluster configuration.
        :type cluster_id: :class:`str`

        :return: Message returned by the server
        :rtype: :class:`str`
    ''')

    def __init__(self, client_id, cluster_id):
        super(Hello, self).__init__()

        self._client_id = client_id
        self._cluster_id = cluster_id

    client_id = property(operator.attrgetter('_client_id'))
    cluster_id = property(operator.attrgetter('_cluster_id'))
Пример #14
0
class Get(Message):
    '''"get" message'''

    __slots__ = '_allow_dirty', '_key',

    TAG = 0x0008 | Message.MASK
    ARGS = ALLOW_DIRTY_ARG, ('key', STRING),
    RETURN_TYPE = STRING

    DOC = utils.format_doc('''
        Send a "get" command to the server

        This method returns the value of the requested key.

        :param key: Key to retrieve
        :type key: :class:`str`
        :param allow_dirty: Allow reads from slave nodes
        :type allow_dirty: :class:`bool`

        :return: Value for the given key
        :rtype: :class:`str`
    ''')

    def __init__(self, allow_dirty, key):
        super(Get, self).__init__()

        self._allow_dirty = allow_dirty
        self._key = key

    allow_dirty = property(operator.attrgetter('_allow_dirty'))
    key = property(operator.attrgetter('_key'))
Пример #15
0
class Confirm(Message):
    '''"confirm" message'''

    __slots__ = '_key', '_value',

    TAG = 0x001c | Message.MASK
    ARGS = ('key', STRING), ('value', STRING),
    RETURN_TYPE = UNIT

    DOC = utils.format_doc('''
        Send a "confirm" command to the server

        This method sets a given key to a given value on the server, unless
        the value bound to the key is already equal to the provided value, in
        which case the action becomes a no-op.

        :param key: Key to set
        :type key: :class:`str`
        :param value: Value to set
        :type value: :class:`str`
    ''')

    def __init__(self, key, value):
        super(Confirm, self).__init__()

        self._key = key
        self._value = value

    key = property(operator.attrgetter('_key'))
    value = property(operator.attrgetter('_value'))
Пример #16
0
class Replace(Message):
    '''"replace" message'''

    __slots__ = '_key', '_value',

    TAG = 0x0033 | Message.MASK
    ARGS = ('key', STRING), ('value', Option(STRING)),
    RETURN_TYPE = Option(STRING)

    DOC = utils.format_doc('''
        Send a "replace" command to the server

        `replace key value` will replace the value bound to the given key with
        the provided value, and return the old value bound to the key.
        If `value` is :data:`None`, the key is deleted.
        If the key was not present in the database, :data:`None` is returned.

        :param key: Key to replace
        :type key: :class:`str`
        :param value: Value to set
        :type value: :class:`str` or :data:`None`

        :return: Original value bound to the key
        :rtype: :class:`str` or :data:`None`
    ''')

    def __init__(self, key, value):
        self._key = key
        self._value = value

    key = property(operator.attrgetter('_key'))
    value = property(operator.attrgetter('_value'))
Пример #17
0
class DeletePrefix(Message):
    '''"delete_prefix" message'''

    __slots__ = '_prefix',

    TAG = 0x0027 | Message.MASK
    ARGS = ('prefix', STRING),
    RETURN_TYPE = UINT32

    DOC = utils.format_doc('''
        Send a "delete_prefix" command to the server

        `delete_prefix prefix` will delete all key/value-pairs from the
        database where given `prefix` is a prefix of `key`.

        :param prefix: Prefix of binding keys to delete
        :type prefix: :class:`str`
        :return: Number of deleted bindings
        :rtype: :class:`int`
    ''')

    def __init__(self, prefix):
        super(DeletePrefix, self).__init__()

        self._prefix = prefix

    prefix = property(operator.attrgetter('_prefix'))
Пример #18
0
class Set(Message):
    '''"set" message'''

    __slots__ = '_key', '_value',

    TAG = 0x0009 | Message.MASK
    ARGS = ('key', STRING), ('value', STRING),
    RETURN_TYPE = UNIT

    DOC = utils.format_doc('''
        Send a "set" command to the server

        This method sets a given key to a given value on the server.

        :param key: Key to set
        :type key: :class:`str`
        :param value: Value to set
        :type value: :class:`str`
    ''')

    def __init__(self, key, value):
        super(Set, self).__init__()

        self._key = key
        self._value = value

    key = property(operator.attrgetter('_key'))
    value = property(operator.attrgetter('_value'))
Пример #19
0
class RevRangeEntries(Message):
    '''"rev_range_entries" message'''

    __slots__ = '_allow_dirty', '_begin_key', '_begin_inclusive', '_end_key', \
        '_end_inclusive', '_max_elements',

    TAG = 0x0023 | Message.MASK
    ARGS = ALLOW_DIRTY_ARG, \
        ('begin_key', Option(STRING)), ('begin_inclusive', BOOL), \
        ('end_key', Option(STRING)), ('end_inclusive', BOOL), \
        ('max_elements', INT32, -1),
    RETURN_TYPE = List(Product(STRING, STRING))

    DOC = utils.format_doc('''
        Send a "rev_range_entries" command to the server

        The operation will return a list of (key, value) tuples, for keys in
        the reverse range between `begin_key` and `end_key`. The
        `begin_inclusive` and `end_inclusive` flags denote whether the
        delimiters should be included.

        The `max_elements` flag can limit the number of returned items. If it is
        negative, all matching items are returned.

        :param begin_key: Begin of range
        :type begin_key: :class:`str`
        :param begin_inclusive: `begin_key` is in- or exclusive
        :type begin_inclusive: :class:`bool`
        :param end_key: End of range
        :type end_key: :class:`str`
        :param end_inclusive: `end_key` is in- or exclusive
        :type end_inclusive: :class:`bool`
        :param max_elements: Maximum number of items to return
        :type max_elements: :class:`int`
        :param allow_dirty: Allow reads from slave nodes
        :type allow_dirty: :class:`bool`

        :return: List of matching (key, value) pairs
        :rtype: iterable of `(str, str)`
    ''')

    #pylint: disable=R0913
    def __init__(self, allow_dirty, begin_key, begin_inclusive, end_key,
                 end_inclusive, max_elements):
        super(RevRangeEntries, self).__init__()

        self._allow_dirty = allow_dirty
        self._begin_key = begin_key
        self._begin_inclusive = begin_inclusive
        self._end_key = end_key
        self._end_inclusive = end_inclusive
        self._max_elements = max_elements

    allow_dirty = property(operator.attrgetter('_allow_dirty'))
    begin_key = property(operator.attrgetter('_begin_key'))
    begin_inclusive = property(operator.attrgetter('_begin_inclusive'))
    end_key = property(operator.attrgetter('_end_key'))
    end_inclusive = property(operator.attrgetter('_end_inclusive'))
    max_elements = property(operator.attrgetter('_max_elements'))
Пример #20
0
class Range(Message):
    '''"Range" message'''

    __slots__ = '_consistency', '_begin_key', '_begin_inclusive', '_end_key', \
        '_end_inclusive', '_max_elements',

    TAG = 0x000b | Message.MASK
    ARGS = CONSISTENCY_ARG, \
        ('begin_key', Option(STRING)), ('begin_inclusive', BOOL), \
        ('end_key', Option(STRING)), ('end_inclusive', BOOL), \
        ('max_elements', INT32, -1),
    RETURN_TYPE = List(STRING)

    DOC = utils.format_doc('''
        Send a "range" command to the server

        The operation will return a list of keys, in the range between
        `begin_key` and `end_key`. The `begin_inclusive` and `end_inclusive`
        flags denote whether the delimiters should be included.

        The `max_elements` flag can limit the number of returned keys. If it is
        negative, all matching keys are returned.

        :param begin_key: Begin of range
        :type begin_key: :class:`str`
        :param begin_inclusive: `begin_key` is in- or exclusive
        :type begin_inclusive: :class:`bool`
        :param end_key: End of range
        :type end_key: :class:`str`
        :param end_inclusive: `end_key` is in- or exclusive
        :param max_elements: Maximum number of keys to return
        :type max_elements: :class:`int`
        :param consistency: Allow reads from stale nodes
        :type consistency: :class:`pyrakoon.consistency.Consistency`

        :return: List of matching keys
        :rtype: iterable of :class:`str`
    ''')

    #pylint: disable=R0913
    def __init__(self, consistency, begin_key, begin_inclusive,
        end_key, end_inclusive, max_elements):
        super(Range, self).__init__()

        self._consistency = consistency
        self._begin_key = begin_key
        self._begin_inclusive = begin_inclusive
        self._end_key = end_key
        self._end_inclusive = end_inclusive
        self._max_elements = max_elements

    consistency = property(operator.attrgetter('_consistency'))
    begin_key = property(operator.attrgetter('_begin_key'))
    begin_inclusive = property(operator.attrgetter('_begin_inclusive'))
    end_key = property(operator.attrgetter('_end_key'))
    end_inclusive = property(operator.attrgetter('_end_inclusive'))
    max_elements = property(operator.attrgetter('_max_elements'))
Пример #21
0
class FlushStore(protocol.Message):
    '''"flush_store" message'''

    __slots__ = ()

    TAG = 0x0042 | protocol.Message.MASK
    ARGS = ()
    RETURN_TYPE = protocol.UNIT

    DOC = utils.format_doc('''
        Send a "flush_store" command to the server

        This method instructs a node to flush its store to disk.
    ''')
Пример #22
0
class Nop(Message):
    '''"nop" message'''

    __slots__ = ()

    TAG = 0x0041 | Message.MASK
    ARGS = ()
    RETURN_TYPE = UNIT

    DOC = utils.format_doc('''
        Send a "nop" command to the server

        This enforces consensus throughout a cluster, but has no further
        effects.
    ''')
Пример #23
0
class Set(Step):
    '''"Set" operation'''

    TAG = 1
    ARGS = ('key', protocol.STRING), ('value', protocol.STRING),

    def __init__(self, key, value):
        super(Set, self).__init__(key, value)

        self._key = key
        self._value = value

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key to set

            :type: :class:`str`
        '''))
    value = property(operator.attrgetter('_value'),
                     doc=utils.format_doc('''
            Value to set

            :type: :class:`str`
        '''))
Пример #24
0
class GetTxID(Message):
    '''"get_txid" message'''

    __slots__ = ()
    TAG = 0x0043 | Message.MASK
    ARGS = ()
    RETURN_TYPE = CONSISTENCY

    DOC = utils.format_doc('''
        Send a "get_txid" command to the server

        This call returns the current transaction ID (if available) of the node.

        :return: Transaction ID of the node
        :rtype: :class:`pyrakoon.consistency.Consistency`
        ''')
Пример #25
0
class Sequence(Message):
    '''"sequence" and "synced_sequence" message'''

    __slots__ = '_steps', '_sync',

    ARGS = ('steps', List(STEP)), ('sync', BOOL, False),
    RETURN_TYPE = UNIT

    DOC = utils.format_doc('''
        Send a "sequence" or "synced_sequence" command to the server

        The operations passed to the constructor should be instances of
        implementations of the :class:`pyrakoon.sequence.Step` class. These
        operations will be executed in an all-or-nothing transaction.

        :param steps: Steps to execute
        :type steps: iterable of :class:`pyrakoon.sequence.Step`
        :param sync: Use *synced_sequence*
        :type sync: :class:`bool`
    ''')

    def __init__(self, steps, sync):
        from ovs.extensions.db.arakoon.pyrakoon.pyrakoon import sequence

        super(Sequence, self).__init__()

        #pylint: disable=W0142
        if len(steps) == 1 and isinstance(steps[0], sequence.Sequence):
            self._sequence = steps[0]
        else:
            self._sequence = sequence.Sequence(steps)

        self._sync = sync

    sequence = property(operator.attrgetter('_sequence'))
    sync = property(operator.attrgetter('_sync'))

    def serialize(self):
        tag = (0x0010 if not self.sync else 0x0024) | Message.MASK

        for bytes_ in UINT32.serialize(tag):
            yield bytes_

        sequence_bytes = ''.join(self.sequence.serialize())

        for bytes_ in STRING.serialize(sequence_bytes):
            yield bytes_
Пример #26
0
class Version(Message):
    '''"version" message'''

    __slots__ = ()

    TAG = 0x0028 | Message.MASK
    ARGS = ()
    RETURN_TYPE = Product(INT32, INT32, INT32, STRING)

    DOC = utils.format_doc('''
        Send a "version" command to the server

        This method returns the server version.

        :return: Server version
        :rtype: `(int, int, int, str)`
     ''')
Пример #27
0
class Delete(Step):
    '''"Delete" operation'''

    TAG = 2
    ARGS = ('key', protocol.STRING),

    def __init__(self, key):
        super(Delete, self).__init__(key)

        self._key = key

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key to delete

            :type: :class:`str`
        '''))
Пример #28
0
class AssertExists(Step):
    '''"AssertExists" operation'''

    TAG = 15
    ARGS = ('key', protocol.STRING),

    def __init__(self, key):
        super(AssertExists, self).__init__(key)

        self._key = key

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key to check

            :type: :class:`str`
        '''))
Пример #29
0
class GetNurseryConfig(protocol.Message):
    '''"get_nursery_config" message'''

    __slots__ = ()

    TAG = 0x0020 | protocol.Message.MASK
    ARGS = ()
    RETURN_TYPE = NURSERY_CONFIG

    DOC = utils.format_doc('''
        Send a "get_nursery_config" command to the server

        This method returns Arakoon Nursery configuration settings.

        :return: Nursery configuration
        :rtype: `NurseryConfig`
    ''')
Пример #30
0
class Statistics(Message):
    '''"statistics" message'''

    __slots__ = ()

    TAG = 0x0013 | Message.MASK
    ARGS = ()
    RETURN_TYPE = STATISTICS

    DOC = utils.format_doc('''
        Send a "statistics" command to the server

        This method returns some server statistics.

        :return: Server statistics
        :rtype: `Statistics`
    ''')