Policy Reconfiguration, Component Spec, Help text
[dcaegen2/platform/cli.git] / dcae-cli / dcae_cli / util / docker_util.py
index a0499d6..3e29f5c 100644 (file)
@@ -1,7 +1,7 @@
 # ============LICENSE_START=======================================================
 # org.onap.dcae
 # ================================================================================
-# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ import dockering as doc
 from dcae_cli.util.logger import get_logger
 from dcae_cli.util.exc import DcaeException
 
-
 dlog = get_logger('Docker')
 
 _reg_img = 'gliderlabs/registrator:latest'
@@ -83,21 +82,10 @@ def get_docker_client(profile, logins=[]):
     except:
         raise DockerError('Could not connect to the Docker daemon. Is it running?')
 
-def _get_docker_client(client_funcs=(docker.Client, docker.from_env)):
-    '''Returns a docker client object'''
-    for func in client_funcs:
-        try:
-            client = func(version='auto')
-            client.ping()
-            return client
-        except:
-            continue
-    raise DockerError('Could not connect to the Docker daemon. Is it running?')
-
 
 def image_exists(image):
     '''Returns True if the image exists locally'''
-    client = _get_docker_client()
+    client = docker.from_env(version="auto")
     return True if client.images(image) else False
 
 
@@ -199,6 +187,7 @@ def deploy_component(profile, image, instance_name, docker_config, should_wait=F
     client = get_docker_client(profile, logins=logins)
 
     config = doc.create_container_config(client, image, envs, hcp)
+
     return _run_container(client, config, name=instance_name, wait=should_wait)
 
 
@@ -221,3 +210,17 @@ def undeploy_component(client, image, instance_name):
     except Exception as e:
         dlog.error("Error while undeploying Docker container/image: {0}".format(e))
         return False
+
+def reconfigure(client, instance_name, command):
+    """  Execute the Reconfig script in the Docker container  """
+
+    #  'command' has 3 parts in a list (1 Command and 2 ARGs)
+    exec_Id = client.exec_create(container=instance_name, cmd=command)
+
+    exec_start_resp = client.exec_start(exec_Id, stream=True)
+
+    #  Using a 'single' generator response to solve issue of 'start_exec' returning control after 6 minutes
+    for response in exec_start_resp:
+        dlog.info("Reconfig Script execution response: {:}".format(response))
+        exec_start_resp.close()
+        break