From d018e37229c57006cdf7dc754459736af7262794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Martins?= Date: Tue, 17 Mar 2015 18:21:12 +0000 Subject: [PATCH] Implemented labels for docker-py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Martins --- docker/client.py | 4 ++-- docker/utils/utils.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docker/client.py b/docker/client.py index 79726aafab..ad994f3675 100644 --- a/docker/client.py +++ b/docker/client.py @@ -444,7 +444,7 @@ def create_container(self, image, command=None, hostname=None, user=None, network_disabled=False, name=None, entrypoint=None, cpu_shares=None, working_dir=None, domainname=None, memswap_limit=0, cpuset=None, host_config=None, - mac_address=None): + mac_address=None, labels=None): if isinstance(volumes, six.string_types): volumes = [volumes, ] @@ -458,7 +458,7 @@ def create_container(self, image, command=None, hostname=None, user=None, self._version, image, command, hostname, user, detach, stdin_open, tty, mem_limit, ports, environment, dns, volumes, volumes_from, network_disabled, entrypoint, cpu_shares, working_dir, domainname, - memswap_limit, cpuset, host_config, mac_address + memswap_limit, cpuset, host_config, mac_address, labels ) return self.create_container_from_config(config, name) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 6abde98416..403296b2b4 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -443,7 +443,8 @@ def create_container_config( stdin_open=False, tty=False, mem_limit=0, ports=None, environment=None, dns=None, volumes=None, volumes_from=None, network_disabled=False, entrypoint=None, cpu_shares=None, working_dir=None, domainname=None, - memswap_limit=0, cpuset=None, host_config=None, mac_address=None + memswap_limit=0, cpuset=None, host_config=None, mac_address=None, + labels=None ): if isinstance(command, six.string_types): command = shlex.split(str(command)) @@ -453,6 +454,15 @@ def create_container_config( for k, v in six.iteritems(environment) ] + if isinstance(labels, six.string_types): + labels = [labels, ] + + if isinstance(labels, list): + labels_dict = {} + for lbl in labels: + labels_dict[lbl] = {} + labels = labels_dict + if isinstance(mem_limit, six.string_types): mem_limit = parse_bytes(mem_limit) if isinstance(memswap_limit, six.string_types): @@ -532,5 +542,6 @@ def create_container_config( 'WorkingDir': working_dir, 'MemorySwap': memswap_limit, 'HostConfig': host_config, - 'MacAddress': mac_address + 'MacAddress': mac_address, + 'Labels': labels }