From 7df1c6126b8d66dcf265d2bef918cfbec5f10b3e Mon Sep 17 00:00:00 2001
From: joe <joe@autistici.org>
Date: Tue, 31 Dec 2013 16:49:37 +0100
Subject: [PATCH] Sync the etcd interface with changes in API

---
 configdb/db/interface/etcd_interface.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/configdb/db/interface/etcd_interface.py b/configdb/db/interface/etcd_interface.py
index bc5a9ea..e1d2a46 100644
--- a/configdb/db/interface/etcd_interface.py
+++ b/configdb/db/interface/etcd_interface.py
@@ -37,7 +37,7 @@ class EtcdSession(inmemory_interface.InMemorySession):
         return path
 
 
-    def add(self, obj):
+    def add(self, obj, create=False):
         path = self._mkpath(obj._entity_name, obj.name)
         # If we don't have a revision,
         rev = self.revisions.get(path, None)
@@ -47,6 +47,9 @@ class EtcdSession(inmemory_interface.InMemorySession):
         else:
             opts = {'prevIndex': rev}
 
+        if create:
+            opts['prevExist'] = False
+
         # Will raise ValueError if the test fails.
         try:
             r = self.db.conn.write(path, self.db._serialize(obj), **opts)
@@ -91,7 +94,7 @@ class EtcdSession(inmemory_interface.InMemorySession):
 
     def _find(self, entity_name):
         path = self._mkpath(entity_name)
-        for r in self.db.conn.read(path, recursive = True).kvs:
+        for r in self.db.conn.read(path, recursive = True).children:
             if not r.dir:
                 curpath = r.key.replace(self.db.conn.key_endpoint,'')
                 self.revisions[curpath] = r.modifiedIndex
@@ -154,7 +157,7 @@ class EtcdInterface(base.DbInterface):
     def create(self, entity_name, attrs, session):
         entity = self.schema.get_entity(entity_name)
         obj = inmemory_interface.InMemoryObject(entity, attrs)
-        session.add(obj)
+        session.add(obj, create=True)
         return obj
 
     def delete(self, entity_name, obj_name, session):
@@ -218,7 +221,7 @@ class EtcdInterface(base.DbInterface):
             return []
         log = []
 
-        for result in data.kvs:
+        for result in data.children:
             obj = json.loads(result.value)
             if obj['data']:
                 obj['data'] = base64.b64decode(obj['data'])
-- 
GitLab