summaryrefslogtreecommitdiffstats
path: root/docker/dockerplugin/discovery.py
diff options
context:
space:
mode:
authorMichael Hwang <mhwang@research.att.com>2017-09-07 11:29:16 -0400
committerMichael Hwang <mhwang@research.att.com>2017-09-11 15:47:38 -0400
commita26c9cc72f8fdc513458c2ba87f9378743f255fb (patch)
tree4393e29db8aa8e93c721d05e38378e91280d5fa1 /docker/dockerplugin/discovery.py
parent61ba70610e670c395483d3c2ef46bbca4eef7769 (diff)
Make components policy reconfigurable and more
* Add in dcae policy dependencies and policy decorators into tasks * Fetch docker logins dynamically * Add in policy example blueprint * Add in policy update operation for components Issue-Id: DCAEGEN2-97 Change-Id: Ib58adfbd7070999c7b8e59ab008f5ff90d4984a7 Signed-off-by: Michael Hwang <mhwang@research.att.com>
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)