summaryrefslogtreecommitdiffstats
path: root/docker/dockerplugin/discovery.py
diff options
context:
space:
mode:
Diffstat (limited to 'docker/dockerplugin/discovery.py')
-rw-r--r--docker/dockerplugin/discovery.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/docker/dockerplugin/discovery.py b/docker/dockerplugin/discovery.py
index 03a51f6..8361c13 100644
--- a/docker/dockerplugin/discovery.py
+++ b/docker/dockerplugin/discovery.py
@@ -38,6 +38,9 @@ class DiscoveryConnectionError(RuntimeError):
class DiscoveryServiceNotFoundError(RuntimeError):
pass
+class DiscoveryKVEntryNotFoundError(RuntimeError):
+ pass
+
def _wrap_consul_call(consul_func, *args, **kwargs):
"""Wrap Consul call to map errors"""
@@ -84,6 +87,20 @@ def remove_service_component_config(kv_conn, service_component_name):
kv_delete_func(service_component_name)
+def get_kv_value(kv_conn, key):
+ """Get a key-value entry's value from Consul
+
+ Raises DiscoveryKVEntryNotFoundError if entry not found
+ """
+ kv_get_func = partial(_wrap_consul_call, kv_conn.kv.get)
+ (index, val) = kv_get_func(key)
+
+ if val:
+ return json.loads(val['Value']) # will raise ValueError if not JSON, let it propagate
+ else:
+ raise DiscoveryKVEntryNotFoundError("{0} kv entry not found".format(key))
+
+
def _create_rel_key(service_component_name):
return "{0}:rel".format(service_component_name)