From 2080c8ab6e801ab62545624d2a47e92a802b48a0 Mon Sep 17 00:00:00 2001 From: Leonty Date: Fri, 25 Sep 2015 23:58:20 +0300 Subject: [PATCH 1/2] Support 'labels' parameter for docker. --- cloud/docker/docker.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py index 0ab564208ba..c22013bb933 100644 --- a/cloud/docker/docker.py +++ b/cloud/docker/docker.py @@ -320,6 +320,13 @@ options: default: false aliases: [] version_added: "2.0" + labels: + description: + - Set container labels. Requires docker >= 1.6 and docker-py >= 1.2.0. + requered: false + default: null + version_added: "1.9.4" + author: - "Cove Schneider (@cove)" - "Joshua Conner (@joshuaconner)" @@ -597,6 +604,7 @@ class DockerManager(object): 'cap_add': ((0, 5, 0), '1.14'), 'cap_drop': ((0, 5, 0), '1.14'), 'read_only': ((1, 0, 0), '1.17'), + 'labels': ((1, 2, 0), '1.18'), # Clientside only 'insecure_registry': ((0, 5, 0), '0.0') } @@ -1123,6 +1131,22 @@ class DockerManager(object): differing.append(container) continue + # LABELS + + expected_labels = {} + for name, value in self.module.params.get('labels').iteritems(): + expected_labels[name] = str(value) + + actual_labels = {} + for container_label in container['Config']['Labels'] or []: + name, value = container_label.split('=', 1) + actual_labels[name] = value + + if actual_labels != expected_labels: + self.reload_reasons.append('labels {0} => {1}'.format(actual_labels, expected_labels)) + differing.append(container) + continue + # HOSTNAME expected_hostname = self.module.params.get('hostname') @@ -1414,6 +1438,7 @@ class DockerManager(object): 'ports': self.exposed_ports, 'volumes': self.volumes, 'environment': self.env, + 'labels': self.module.params.get('labels'), 'hostname': self.module.params.get('hostname'), 'domainname': self.module.params.get('domainname'), 'detach': self.module.params.get('detach'), @@ -1668,6 +1693,7 @@ def main(): cap_add = dict(default=None, type='list'), cap_drop = dict(default=None, type='list'), read_only = dict(default=None, type='bool'), + labels = dict(default={}, type='dict'), ), required_together = ( ['tls_client_cert', 'tls_client_key'], From 5b904c1401dee1f6c02780aeb696c01bea398762 Mon Sep 17 00:00:00 2001 From: Leonty Date: Wed, 4 Nov 2015 12:43:03 +0300 Subject: [PATCH 2/2] Corrected misspelling in the 'labels' docker parameter documentation. --- cloud/docker/docker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py index c22013bb933..c94df54ad89 100644 --- a/cloud/docker/docker.py +++ b/cloud/docker/docker.py @@ -323,10 +323,9 @@ options: labels: description: - Set container labels. Requires docker >= 1.6 and docker-py >= 1.2.0. - requered: false + required: false default: null version_added: "1.9.4" - author: - "Cove Schneider (@cove)" - "Joshua Conner (@joshuaconner)"