From 66613f4112b0e68f30430944b7d94e6ca14b1f62 Mon Sep 17 00:00:00 2001 From: Michael Hwang Date: Thu, 14 Sep 2017 10:56:07 -0400 Subject: Fix issue where container ports is not list Container ports was being returned as dict keys for python3 Change-Id: I434049c465094265d8e0ec8c8d6310b682866da8 Issue-Id: DCAEGEN2-91 Signed-off-by: Michael Hwang --- python-dockering/dockering/config_building.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'python-dockering/dockering/config_building.py') diff --git a/python-dockering/dockering/config_building.py b/python-dockering/dockering/config_building.py index d8e3c84..564e5de 100644 --- a/python-dockering/dockering/config_building.py +++ b/python-dockering/dockering/config_building.py @@ -20,6 +20,7 @@ """ Abstraction in Docker container configuration """ +import six from dockering import utils from dockering.exceptions import DockerConstructionError @@ -234,6 +235,13 @@ def add_host_config_params_dns(docker_host, host_config_params=None): return host_config_params +def _get_container_ports(host_config_params): + """Grab list of container ports from host config params""" + if "port_bindings" in host_config_params: + return list(six.iterkeys(host_config_params["port_bindings"])) + else: + return None + def create_container_config(client, image, envs, host_config_params, tty=False): """Create docker container config @@ -252,11 +260,7 @@ def create_container_config(client, image, envs, host_config_params, tty=False): host_config = client.create_host_config(**host_config_params) - if "port_bindings" in host_config_params: - # TODO: Use six for creating the list of ports - six.iterkeys - ports = host_config_params["port_bindings"].keys() - else: - ports = None + ports = _get_container_ports(host_config_params) command = "" # This is required... config = client.create_container_config(image, command, detach=True, tty=tty, -- cgit 1.2.3-korg