summaryrefslogtreecommitdiffstats
path: root/dcae-cli/dcae_cli
diff options
context:
space:
mode:
authorMichael Hwang <mhwang@research.att.com>2017-09-28 17:05:52 -0400
committerMichael Hwang <mhwang@research.att.com>2017-09-28 17:07:00 -0400
commit809230f9e3dea1adebbff4aa6927422bffc83ecc (patch)
tree03fcf7998a9ea638505b3a7c1dd3ca1bd5aa17db /dcae-cli/dcae_cli
parentaf7747ca4a7d849dbef9f86b31216e388334f876 (diff)
Fetch docker logins from Consul
Change-Id: I521fd549b12042fa1d12481fbb0beb535f52e06f Issue-Id: DCAEGEN2-91 Signed-off-by: Michael Hwang <mhwang@research.att.com>
Diffstat (limited to 'dcae-cli/dcae_cli')
-rw-r--r--dcae-cli/dcae_cli/util/discovery.py17
-rw-r--r--dcae-cli/dcae_cli/util/docker_util.py18
-rw-r--r--dcae-cli/dcae_cli/util/run.py10
3 files changed, 37 insertions, 8 deletions
diff --git a/dcae-cli/dcae_cli/util/discovery.py b/dcae-cli/dcae_cli/util/discovery.py
index 0c12f95..cbfd617 100644
--- a/dcae-cli/dcae_cli/util/discovery.py
+++ b/dcae-cli/dcae_cli/util/discovery.py
@@ -462,6 +462,23 @@ def create_config(user, cname, cver, params, interface_map, instance_map, dmaap_
return conf_key, conf, rels_key, rels, dmaap_key, dmaap_map_just_info
+def get_docker_logins(host=consul_host):
+ """Get Docker logins from Consul
+
+ Returns
+ -------
+ List of objects where the objects must be of the form
+ {"registry": .., "username":.., "password":.. }
+ """
+ key = "dockerlogin_info"
+ (index, val) = Consul(host).kv.get(key)
+
+ if val:
+ return json.loads(val['Value'].decode("utf-8"))
+ else:
+ return []
+
+
def push_config(conf_key, conf, rels_key, rels, dmaap_key, dmaap_map, host=consul_host):
'''Uploads the config and rels to Consul'''
cons = Consul(host)
diff --git a/dcae-cli/dcae_cli/util/docker_util.py b/dcae-cli/dcae_cli/util/docker_util.py
index b59688b..a0499d6 100644
--- a/dcae-cli/dcae_cli/util/docker_util.py
+++ b/dcae-cli/dcae_cli/util/docker_util.py
@@ -74,10 +74,10 @@ def build_envs(profile, docker_config, instance_name):
# TODO: Consolidate these two docker client methods. Need ability to invoke local
# vs remote Docker engine
-def get_docker_client(profile):
- base_url = "tcp://{0}".format(profile.docker_host)
+def get_docker_client(profile, logins=[]):
+ hostname, port = profile.docker_host.split(":")
try:
- client = docker.Client(base_url=base_url)
+ client = doc.create_client(hostname, port, logins=logins)
client.ping()
return client
except:
@@ -162,7 +162,8 @@ def _run_registrator(client, external_ip=None):
# High level calls
#
-def deploy_component(profile, image, instance_name, docker_config, should_wait=False):
+def deploy_component(profile, image, instance_name, docker_config, should_wait=False,
+ logins=[]):
"""Deploy Docker component
This calls runs a Docker container detached. The assumption is that the Docker
@@ -170,6 +171,13 @@ def deploy_component(profile, image, instance_name, docker_config, should_wait=F
TODO: Split out the wait functionality
+ Args
+ ----
+ logins (list): List of objects where the objects are each a docker login of
+ the form:
+
+ {"registry": .., "username":.., "password":.. }
+
Returns
-------
Dict that is the result from a Docker inspect call
@@ -188,7 +196,7 @@ def deploy_component(profile, image, instance_name, docker_config, should_wait=F
raise DockerConstructionError("Could not resolve the docker hostname:{0}".format(dh))
envs = build_envs(profile, docker_config, instance_name)
- client = get_docker_client(profile)
+ 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)
diff --git a/dcae-cli/dcae_cli/util/run.py b/dcae-cli/dcae_cli/util/run.py
index 67535fa..e483d04 100644
--- a/dcae-cli/dcae_cli/util/run.py
+++ b/dcae-cli/dcae_cli/util/run.py
@@ -167,17 +167,21 @@ def run_component(user, cname, cver, catalog, additional_user, attached, force,
image = catalog.get_docker_image(cname, cver)
docker_config = catalog.get_docker_config(cname, cver)
+ docker_logins = dis.get_docker_logins()
+
if should_wait:
du.deploy_component(profile, image, instance_name, docker_config,
- should_wait=True)
+ should_wait=True, logins=docker_logins)
else:
- result = du.deploy_component(profile, image, instance_name, docker_config)
+ result = du.deploy_component(profile, image, instance_name, docker_config,
+ logins=docker_logins)
log.debug(result)
if result:
log.info("Deployed {0}. Verifying..".format(instance_name))
- max_wait = 15 # 15s
+ # TODO: Be smarter here but for now wait longer i.e. 5min
+ max_wait = 300 # 300s == 5min
if _verify_component(instance_name, max_wait, dis.consul_host):
log.info("Container is up and healthy")