python-consul
python-consul copied to clipboard
Support for `txn` in HTTP API
https://www.consul.io/api/txn.html
Any play for implementing this? Thanks.
ping @cablehead
Pull requests gratefully accepted.
@cablehead are you planning to work on this anytime in the near future? If not I may take a look at implementing it.
@beardedeagle Hi. I have a branch currently supports txn
but does not support tornado
and other async client yets. I am planning to add the support next week.
I've deleted my previous comment, as I misread the conversation above.
Hi there. I won't have time to work on this in the near future (I've just recently become a parent, and I'm slowly adjusting!). @iandyh is it possible to create a PR for your branch? If it looks OK we can look to get it merge. @beardedeagle it'd be awesome if you had time to work on it to, particularly in order to support async clients as well.
@iandyh That would be immediately be helpful to me since I am not using any async clients, but if you get it pr'd in I can look at helping to get those implemented.
@beardedeagle @cablehead Let me work on it on Friday with async support if it's straightforward.
@iandyh were you able to make any headway on that? I pulled your changes locally and have started to tinker.
Hi
Sorry I was busy last Friday and then it's the Japan holiday season. If it's urgent, feel free to use iandyh/python-marathon txn
branch. I've been used it for development for a while. I'll prepare the PR when I am back from holiday(Thursday this week)
Sent from my iPhone
On Aug 14, 2017, at 23:39, Randy Thompson [email protected] wrote:
@iandyh were you able to make any headway on that?
― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
I have merged initial work into master via #166. However, note that there is further work to be done here so leaving this issue open for now, might create more atomic issues later.
@abn Just out of curiosity, what atomic issues you are referring to?
@iandyh I just mean I might create more github issues with smaller chunks of further work required to expand on the feature.
Hi, I tried to use txn like this:
curl --insecure --header "X-Consul-Token: abc123" \
--request PUT \
-H "Content-Type: application/json" \
-d '[{ "KV": {"Verb": "get-tree","Key": "service"} }]' \
https://consulhost:8501/v1/txn
This works fine.
My code does not:
import platform
print("python ", platform.python_version())
import consul
print("consul ", consul.__version__)
import urllib3
urllib3.disable_warnings()
payload = [{ "KV": { "Verb": "get-tree", "Key": "service" } }]
c = consul.Consul(host="consulhost",port="8501",token="abc123",scheme='https',verify=False)
result = c.txn.put(payload)
print(result)
However "Results" is always an empty list:
python 3.6.2
consul 0.7.2-dev
{'Results': [], 'Errors': None, 'Index': 0, 'LastContact': 0, 'KnownLeader': True}
What am I doing wrong?
@paltryeffort I have tried to reproduce this but failed, havent tried with a token yet though. Here is what I did.
- Start consul instance via docker.
docker run --rm -it -p 8500:8500 consul
- Execute the following script.
import json
from consul.std import Consul
if __name__ == '__main__':
c = Consul()
c.txn.put(payload=[
{
"KV": {
"Verb": "check-not-exists",
"Key": "foo"
}
},
{
"KV": {
"Verb": "set",
"Key": "foo/bar",
"Value": ""
}
},
{
"KV": {
"Verb": "set",
"Key": "foo/baz",
"Value": ""
}
}
])
r = c.txn.put(payload=[
{
"KV": {
"Verb": "get-tree",
"Key": "foo"
}
}
])
print(json.dumps(r, indent=2))
c.txn.put(payload=[
{
"KV": {
"Verb": "delete-tree",
"Key": "foo"
}
}
])
This produce the following output.
{
"Index": 0,
"Errors": null,
"Results": [
{
"KV": {
"LockIndex": 0,
"ModifyIndex": 99,
"Value": null,
"Flags": 0,
"Key": "foo/bar",
"CreateIndex": 99
}
},
{
"KV": {
"LockIndex": 0,
"ModifyIndex": 99,
"Value": null,
"Flags": 0,
"Key": "foo/baz",
"CreateIndex": 99
}
}
],
"KnownLeader": true,
"LastContact": 0
}
@abn you have no token required with docker image. That is the reason why your test has passed. If able, backport this pr to 0.7.2 (0.7.3?) as this version is included into EPEL repo for CentOS 7.