ungleich-game/archive/test-etcd.py

32 lines
879 B
Python
Raw Normal View History

2019-05-25 20:18:09 +00:00
import etcd
import json
client = etcd.Client(port=2379) # this will create a client against etcd server running on localhost on port 4001
some_vm = {}
some_vm['network'] = {}
some_vm['network']['ipv6'] = []
some_vm['network']['ipv6'].append("2a0a:e5c0:4::42/64")
some_vm['network']['ipv6'].append("2a0a:e5c0:1::42/64")
#for node in range(200):
2019-05-25 20:45:44 +00:00
# client.delete('/nodes/n{}'.format(node))
2019-05-25 20:18:09 +00:00
for node in range(10):
2019-05-25 20:18:09 +00:00
ip = some_vm['network']['ipv6'].append("2a0a:e5c0:3::{}/64".format(node))
j = json.dumps(some_vm)
client.write('/nodes/n{}'.format(node), j)
for node in range(10):
x = client.write("/dir/name", "value", append=True)
print("generated key: " + x.key)
print("stored value: " + x.value)
2019-05-25 20:18:09 +00:00
result = client.read('/nodes', recursive=True, sorted=True)
print(result)
for child in result.children:
print("%s: %s" % (child.key,child.value))