summaryrefslogtreecommitdiffstats
path: root/custodia/store/etcdstore.py
diff options
context:
space:
mode:
Diffstat (limited to 'custodia/store/etcdstore.py')
-rw-r--r--custodia/store/etcdstore.py39
1 files changed, 18 insertions, 21 deletions
diff --git a/custodia/store/etcdstore.py b/custodia/store/etcdstore.py
index 46c6943..44d7075 100644
--- a/custodia/store/etcdstore.py
+++ b/custodia/store/etcdstore.py
@@ -2,19 +2,15 @@
from __future__ import print_function
-import logging
-
import etcd
from custodia.store.interface import CSStore, CSStoreError, CSStoreExists
-logger = logging.getLogger(__name__)
-
-
class EtcdStore(CSStore):
def __init__(self, config):
+ super(EtcdStore, self).__init__(config)
self.server = config.get('etcd_server', '127.0.0.1')
self.port = int(config.get('etcd_port', 4001))
self.namespace = config.get('namespace', "/custodia")
@@ -27,7 +23,8 @@ class EtcdStore(CSStore):
# Already exists
pass
except etcd.EtcdException:
- logger.exception("Error creating namespace %s", self.namespace)
+ self.logger.exception("Error creating namespace %s",
+ self.namespace)
raise CSStoreError('Error occurred while trying to init db')
def _absolute_key(self, key):
@@ -40,51 +37,51 @@ class EtcdStore(CSStore):
return '/'.join([self.namespace] + parts).replace('//', '/')
def get(self, key):
- logger.debug("Fetching key %s", key)
+ self.logger.debug("Fetching key %s", key)
try:
result = self.etcd.get(self._absolute_key(key))
except etcd.EtcdException:
- logger.exception("Error fetching key %s", key)
+ self.logger.exception("Error fetching key %s", key)
raise CSStoreError('Error occurred while trying to get key')
- logger.debug("Fetched key %s got result: %r", key, result)
+ self.logger.debug("Fetched key %s got result: %r", key, result)
return result.value
def set(self, key, value, replace=False):
- logger.debug("Setting key %s to value %s (replace=%s)", key, value,
- replace)
+ self.logger.debug("Setting key %s to value %s (replace=%s)",
+ key, value, replace)
path = self._absolute_key(key)
try:
self.etcd.write(path, value, prevExist=replace)
except etcd.EtcdAlreadyExist as err:
raise CSStoreExists(str(err))
except etcd.EtcdException:
- logger.exception("Error storing key %s", key)
+ self.logger.exception("Error storing key %s", key)
raise CSStoreError('Error occurred while trying to store key')
def span(self, key):
path = self._absolute_key(key)
- logger.debug("Creating directory %s", path)
+ self.logger.debug("Creating directory %s", path)
try:
self.etcd.write(path, None, dir=True, prevExist=False)
except etcd.EtcdAlreadyExist as err:
raise CSStoreExists(str(err))
except etcd.EtcdException:
- logger.exception("Error storing key %s", key)
+ self.logger.exception("Error storing key %s", key)
raise CSStoreError('Error occurred while trying to store key')
def list(self, keyfilter='/'):
path = self._absolute_key(keyfilter)
if path != '/':
path = path.rstrip('/')
- logger.debug("Listing keys matching %s", path)
+ self.logger.debug("Listing keys matching %s", path)
try:
result = self.etcd.read(path, recursive=True)
except etcd.EtcdKeyNotFound:
return None
except etcd.EtcdException:
- logger.exception("Error listing %s", keyfilter)
+ self.logger.exception("Error listing %s", keyfilter)
raise CSStoreError('Error occurred while trying to list keys')
- logger.debug("Searched for %s got result: %r", path, result)
+ self.logger.debug("Searched for %s got result: %r", path, result)
value = set()
for entry in result.get_subtree():
if entry.key == path:
@@ -96,14 +93,14 @@ class EtcdStore(CSStore):
return sorted(value)
def cut(self, key):
- logger.debug("Removing key %s", key)
+ self.logger.debug("Removing key %s", key)
try:
self.etcd.delete(self._absolute_key(key))
except etcd.EtcdKeyNotFound:
- logger.debug("Key %s not found", key)
+ self.logger.debug("Key %s not found", key)
return False
except etcd.EtcdException:
- logger.exception("Error removing key %s", key)
+ self.logger.exception("Error removing key %s", key)
raise CSStoreError('Error occurred while trying to cut key')
- logger.debug("Key %s removed", key)
+ self.logger.debug("Key %s removed", key)
return True