Sync lease util
etcd3.stateful.lease.
Lease
(client, ttl, ID=0, new=True)[source]¶Bases: object
__init__
(client, ttl, ID=0, new=True)[source]¶Parameters: |
|
---|
ID
¶Property: the id of the granted lease
Returns: | int |
---|
grant
()[source]¶Grant the lease if new is set to False or it just inherit the lease of the specified id
When granting new lease if ID is set to 0, the lessor will chooses an ID.
time_to_live
(keys=False)[source]¶Retrieves lease information.
Parameters: | keys (bool) – whether return the keys that attached to the lease |
---|
refresh
()¶Call keepalive for once to refresh the ttl of the lease
keepalive
(keep_cb=None, cancel_cb=None)[source]¶Start a daemon thread to constantly keep the lease alive
Parameters: |
|
---|
etcd3.stateful.transaction.
Txn
(client, compare=None, success=None, failure=None)[source]¶Bases: object
Txn (transaction) util provides a human friendly way to build kv.txn request Usage:
>>> from etcd3 import Client, Txn
>>> txn = Txn(Client())
>>> txn.compare(txn.key('foo').value == 'bar')
>>> txn.success(txn.put('foo', 'bra'))
>>> txn.commit()
etcdserverpbTxnResponse(header=etcdserverpbResponseHeader(cluster_id=11588568905070377092, member_id=128088275939295631, revision=15656, raft_term=4), succeeded=True, responses=[etcdserverpbResponseOp(response_put=etcdserverpbPutResponse(header=etcdserverpbResponseHeader(revision=15656)))])
From google paxosdb paper:
Our implementation hinges around a powerful primitive which we call MultiOp. All other database operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically and consists of three components:
__init__
(client, compare=None, success=None, failure=None)[source]¶Parameters: |
|
---|
compare
(compareOp)[source]¶Add a test to the transaction guard component
Parameters: | compareOp – TxnCompareOp |
---|---|
Returns: | self |
If
(compareOp)¶Add a test to the transaction guard component
Parameters: | compareOp – TxnCompareOp |
---|---|
Returns: | self |
Then
(successOp)¶Add a database operation to the transaction success component
Else
(failureOp)¶Add a database operation to the transaction failure component
key
(key=None, range_end=None, prefix=None, all=None)[source]¶Get the TxnCompareOp of a key
Parameters: |
|
---|---|
Returns: | TxnCompareOp |
range
(key=None, range_end=None, limit=0, revision=None, serializable=False, keys_only=False, count_only=False, min_mod_revision=None, max_mod_revision=None, min_create_revision=None, max_create_revision=None, sort_order=<RangeRequestSortOrder.NONE: 'NONE'>, sort_target=<RangeRequestSortTarget.KEY: 'KEY'>, prefix=None, all=None)[source]¶Operation of keys in the range from the key-value store.
Parameters: |
|
---|
put
(key, value, lease=0, prev_kv=False, ignore_value=False, ignore_lease=False)[source]¶Operation of puts the given key into the key-value store. A put request increments the revision of the key-value store and generates one event in the event history.
Parameters: |
|
---|
delete
(key=None, range_end=None, prev_kv=False, prefix=None, all=None)[source]¶Operation of deletes the given range from the key-value store. A delete request increments the revision of the key-value store and generates a delete event in the event history for every deleted key.
Parameters: |
|
---|
etcd3.stateful.transaction.
TxnCompareOp
(key, range_end=None)[source]¶Bases: object
The operator of transaction’s compare part
value
¶represents the value of the key
mod
¶represents the mod_revision of the key
version
¶represents the version of the key
create
¶represents the create_revision of the key
lease
¶represents the lease_id of the key
etcd3.stateful.watch.
KeyValue
(data)[source]¶Bases: object
Model of the key-value of the event
etcd3.stateful.watch.
Event
(data, header=None)[source]¶Bases: etcd3.stateful.watch.KeyValue
Watch event
etcd3.stateful.watch.
Watcher
(client, max_retries=-1, key=None, range_end=None, start_revision=None, progress_notify=None, prev_kv=None, prefix=None, all=None, no_put=False, no_delete=False)[source]¶Bases: object
__init__
(client, max_retries=-1, key=None, range_end=None, start_revision=None, progress_notify=None, prev_kv=None, prefix=None, all=None, no_put=False, no_delete=False)[source]¶Initialize a watcher
Parameters: |
|
---|
set_default_timeout
(timeout)[source]¶Set the default timeout of watch request
Parameters: | timeout (int) – timeout in seconds |
---|
get_filter
(filter)[source]¶Get the event filter function
Parameters: | filter (callable or regex string or EventType or None) – will generate a filter function from this param |
---|---|
Returns: | callable |
onEvent
(filter_or_cb, cb=None)[source]¶Add a callback to a event that matches the filter
If only one param is given, which is filter_or_cb, it will be treated as the callback. If any event comes, it will be called.
Parameters: |
|
---|
unEvent
(filter=None, cb=None)[source]¶remove a callback or filter event that’s been previously added via onEvent() If both parameters are given they are ANDd together; to OR the, make two calls.
Parameters: |
|
---|
dispatch_event
(event)[source]¶Find the callbacks, if callback’s filter fits this event, call the callback
Parameters: | event – Event |
---|
cancel
()¶Stop watching, close the watch stream and exit the daemon thread
etcd3.stateful.lock.
Lock
(client, lock_name, lock_ttl=60, reentrant=None, lock_prefix='_locks')[source]¶Bases: object
Locking recipe for etcd, inspired by the kazoo recipe for zookeeper
DEFAULT_LOCK_TTL
= 60¶HOST
= 'host'¶PROCESS
= 'process'¶THREAD
= 'thread'¶__init__
(client, lock_name, lock_ttl=60, reentrant=None, lock_prefix='_locks')[source]¶Parameters: |
|
---|
is_acquired
¶if the lock is acquired
acquired
¶if the lock is acquired
acquire
(block=True, lock_ttl=None, timeout=None, delete_key=True)[source]¶Acquire the lock.
Parameters: |
|
---|