I need to perform an ETCD transaction to check if key_a
is of given revision, and if yes, then to delete the key, and put in a new key_b
with value of value_b
. I want to do that from python, and I am really struggling with the way etcdctl txn
command works, to be specific, with the syntax of its input. Online examples on how to use etcdctl txn
are very scarce. The solution I came up with, is to create the txn input, and pass it via pipe to the etcdctl txn:
cmd = "'mod(\"/key_a\") = \"1\"\n\ndel /key_a\nput /key_b \"value_b\"\n\n\n' | etcdctl txn")
ret = subprocess.call(cmd, shell=True)
However, I receive an error I do not fully understand:
/bin/sh: 7: mod("/key_a") = "1"
del /key_a
put /key_b "value_b"
: not found
Error: EOF
3
Where did I messed up? How can I create a one-liner to call etcdctl txn
?