Write VM to etcd
This commit is contained in:
parent
c0e6d6a0d8
commit
1b36c2f96f
5 changed files with 93 additions and 36 deletions
|
|
@ -21,28 +21,31 @@
|
|||
#
|
||||
|
||||
import etcd3
|
||||
import json
|
||||
|
||||
class DB(object):
|
||||
def __init__(self, urls):
|
||||
self.urls = urls
|
||||
self.prefix = "/nicohack/"
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.prefix= '/nicohack/'
|
||||
self.connect()
|
||||
|
||||
def connect(self):
|
||||
self.clients = []
|
||||
for endpoint in self.urls:
|
||||
client = etcd3.client(host=endpoint,
|
||||
ca_cert="/home/nico/vcs/ungleich-dot-cdist/files/etcd/ca.pem",
|
||||
cert_cert="/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico.pem",
|
||||
cert_key="/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico-key.pem")
|
||||
|
||||
clients.append(client)
|
||||
self._db_clients = []
|
||||
for endpoint in self.config.etcd_hosts:
|
||||
client = etcd3.client(host=endpoint, **self.config.etcd_args)
|
||||
self._db_clients.append(client)
|
||||
|
||||
def get_value(self, key):
|
||||
pass
|
||||
|
||||
def set_value(self, key, val):
|
||||
pass
|
||||
def set(self, key, value, store_as_json=False, **kwargs):
|
||||
if store_as_json:
|
||||
value = json.dumps(value)
|
||||
|
||||
key = "{}/{}".format(self.prefix, key)
|
||||
|
||||
# FIXME: iterate over clients in case of failure ?
|
||||
return self._db_clients[0].put(key, value, **kwargs)
|
||||
|
||||
if __name__ == '__main__':
|
||||
endpoints = [ "https://etcd1.ungleich.ch:2379",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue