diff --git a/configdb/db/interface/etcd_interface.py b/configdb/db/interface/etcd_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..682ed27f5d064f2419d6a6ae55816b06931ff4c5 --- /dev/null +++ b/configdb/db/interface/etcd_interface.py @@ -0,0 +1,84 @@ +# You need the etcd python client library you can find here: +# https://github.com/lavagetto/python-etcd +import etcd +import cPickle as pickle +import os +from urlparse import urlparse + + +class EtcdSession(object): + """A EtcdInterface session.""" + def __init__(self,db): + self.db = db + raise NotImplementedError + + def _mkpath(self, entity_name, object_name): + return os.path.join(self.db.root, entity_name, object_name) + + def add(self, obj): + path = self._mkpath(obj._entity_name, obj.name) + #TODO: test for presence of an old object and do test_and_set + self.db.conn.set(path, self.db._serialize(obj)) + + + def delete(self, obj): + raise NotImplementedError + + def _delete_by_name(self, entity_name, obj_name): + raise NotImplementedError + + def _deserialize_if_not_none(self, data): + raise NotImplementedError + + def _get(self, entity_name, obj_name): + raise NotImplementedError + + def _find(self, entity_name): + raise NotImplementedError + + def commit(self): + pass + + def rollback(self): + pass + + +class EtcdInterface(base,DbInterface): + """Database interface for an Etcd backend. + + This needs the 'python-etcd' library, available at: + + https://github.com/lavagetto/python-etcd + + """ + + def __init__(self, url, schema, root='/configdb', timeout=30): + self.root = root + res = + + self.conn = etcd.Client() + pass + + def _serialize(self, obj): + return pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL) + + def _deserialize(self, data): + return pickle.loads(data) + + def session(self): + return base.session_context_manager(EtcdSession(self)) + + def get_by_name(self, entity_name, object_name, session): + return session._get(entity_name, object_name) + + def find(self, entity_name, query, session): + raise NotImplementedError + + def create(self, entity_name, attrs, session): + raise NotImplementedError + + def delete(self, entity_name, object_name, session): + raise NotImplementedError + + def close(self): + pass