summaryrefslogtreecommitdiffstats
path: root/dcae-cli
diff options
context:
space:
mode:
Diffstat (limited to 'dcae-cli')
-rw-r--r--dcae-cli/ChangeLog.md1
-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
4 files changed, 38 insertions, 8 deletions
diff --git a/dcae-cli/ChangeLog.md b/dcae-cli/ChangeLog.md
index 794b6a7..7eb38d9 100644
--- a/dcae-cli/ChangeLog.md
+++ b/dcae-cli/ChangeLog.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Seeding configuration is no longer a fatal issue
* Setup database connection via manual user inputs if seed config not there
* Seeding profiles is no longer a fatal issue
+* Dynamically fetch Docker login credentials from Consul to use to authenticate when creating Docker client.
## [2.9.0]
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")