Debian Codegraph @

consul/api/txn.py

raw symbols SCIP
1 import json
2
3 from consul.callback import CB
4
5
6 class Txn:
7 """
8 The Transactions endpoints manage updates or fetches of multiple keys
9 inside a single, atomic transaction.
10 """
11
12 def __init__(self, agent) -> None:
13 self.agent = agent
14
15 def put(self, payload):
16 """
17 Create a transaction by submitting a list of operations to apply to
18 the KV store inside of a transaction. If any operation fails, the
19 transaction is rolled back and none of the changes are applied.
20
21 *payload* is a list of operations where each operation is a `dict`
22 with a single key value pair, with the key specifying operation the
23 type. An example payload of operation type "KV" is
24 dict::
25
26 {
27 "KV": {
28 "Verb": "<verb>",
29 "Key": "<key>",
30 "Value": "<Base64-encoded blob of data>",
31 "Flags": 0,
32 "Index": 0,
33 "Session": "<session id>"
34 }
35 }
36 """
37 return self.agent.http.put(CB.json(), "/v1/txn", data=json.dumps(payload))