summaryrefslogtreecommitdiffstats
path: root/python-dockering/dockering/core.py
diff options
context:
space:
mode:
authorMichael Hwang <mhwang@research.att.com>2017-09-07 16:00:09 -0400
committerMichael Hwang <mhwang@research.att.com>2017-09-07 17:30:55 -0400
commitf5ce303053c5560455572e39e1dbe6e5e7bf4c15 (patch)
treef2ce965381c793a56e73d69bea0f8f23cee5c6f8 /python-dockering/dockering/core.py
parent5bc79f46cdbc93188c1fc47d73c02bba47ac3d07 (diff)
Add in functionality for policy notification
Change-Id: I4ef4bc9c35266814f226cbad13c55d11901c8e79 Issue-Id: DCAEGEN2-97 Signed-off-by: Michael Hwang <mhwang@research.att.com>
Diffstat (limited to 'python-dockering/dockering/core.py')
-rw-r--r--python-dockering/dockering/core.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/python-dockering/dockering/core.py b/python-dockering/dockering/core.py
index dcd5908..9ef1ae3 100644
--- a/python-dockering/dockering/core.py
+++ b/python-dockering/dockering/core.py
@@ -25,8 +25,6 @@ from dockering import config_building as cb
from dockering import utils
-# TODO: Replace default for logins to source it from Consul..perhaps
-
def create_client(hostname, port, reauth=False, logins=[]):
"""Create Docker client
@@ -134,3 +132,34 @@ def remove_image(client, image_name):
# Failure to remove image is not classified as terrible..for now
return False
+
+def build_policy_update_cmd(script_path, use_sh=True, msg_type="policy", **kwargs):
+ """Build command to execute for policy update"""
+ data = json.dumps(kwargs or {})
+
+ if use_sh:
+ return ['/bin/sh', script_path, msg_type, data]
+ else:
+ return [script_path, msg_type, data]
+
+def notify_for_policy_update(client, container_id, cmd):
+ """Notify Docker container that policy update occurred
+
+ Notify the Docker container by doing Docker exec of passed-in command
+
+ Args:
+ -----
+ container_id: (string)
+ cmd: (list) of strings each entry being part of the command
+ """
+ try:
+ result = client.exec_create(container=container_id,
+ cmd=cmd)
+ result = client.exec_start(exec_id=result['Id'])
+
+ utils.logger.info("Pass to docker exec {0} {1} {2}".format(
+ container_id, cmd, result))
+
+ return result
+ except Exception as e:
+ raise DockerError(e)