# ============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.
from dcae_cli.util.logger import get_logger
from dcae_cli.util.exc import DcaeException
-
dlog = get_logger('Docker')
_reg_img = 'gliderlabs/registrator:latest'
# 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:
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
# 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
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
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)
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