From f5ce303053c5560455572e39e1dbe6e5e7bf4c15 Mon Sep 17 00:00:00 2001 From: Michael Hwang Date: Thu, 7 Sep 2017 16:00:09 -0400 Subject: Add in functionality for policy notification Change-Id: I4ef4bc9c35266814f226cbad13c55d11901c8e79 Issue-Id: DCAEGEN2-97 Signed-off-by: Michael Hwang --- python-dockering/dockering/core.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'python-dockering/dockering') 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) -- cgit 1.2.3-korg