Merge pull request #2159 from leonty/devel

Support 'labels' parameter for docker.
reviewable/pr18780/r1
Brian Coca 9 years ago
commit 4e8d04d248

@ -329,6 +329,12 @@ options:
default: false default: false
aliases: [] aliases: []
version_added: "2.0" version_added: "2.0"
labels:
description:
- Set container labels. Requires docker >= 1.6 and docker-py >= 1.2.0.
required: false
default: null
version_added: "1.9.4"
author: author:
- "Cove Schneider (@cove)" - "Cove Schneider (@cove)"
- "Joshua Conner (@joshuaconner)" - "Joshua Conner (@joshuaconner)"
@ -608,6 +614,7 @@ class DockerManager(object):
'cap_add': ((0, 5, 0), '1.14'), 'cap_add': ((0, 5, 0), '1.14'),
'cap_drop': ((0, 5, 0), '1.14'), 'cap_drop': ((0, 5, 0), '1.14'),
'read_only': ((1, 0, 0), '1.17'), 'read_only': ((1, 0, 0), '1.17'),
'labels': ((1, 2, 0), '1.18'),
# Clientside only # Clientside only
'insecure_registry': ((0, 5, 0), '0.0') 'insecure_registry': ((0, 5, 0), '0.0')
} }
@ -1134,6 +1141,22 @@ class DockerManager(object):
differing.append(container) differing.append(container)
continue 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 # HOSTNAME
expected_hostname = self.module.params.get('hostname') expected_hostname = self.module.params.get('hostname')
@ -1427,6 +1450,7 @@ class DockerManager(object):
'ports': self.exposed_ports, 'ports': self.exposed_ports,
'volumes': self.volumes, 'volumes': self.volumes,
'environment': self.env, 'environment': self.env,
'labels': self.module.params.get('labels'),
'hostname': self.module.params.get('hostname'), 'hostname': self.module.params.get('hostname'),
'domainname': self.module.params.get('domainname'), 'domainname': self.module.params.get('domainname'),
'detach': self.module.params.get('detach'), 'detach': self.module.params.get('detach'),
@ -1682,6 +1706,7 @@ def main():
cap_add = dict(default=None, type='list'), cap_add = dict(default=None, type='list'),
cap_drop = dict(default=None, type='list'), cap_drop = dict(default=None, type='list'),
read_only = dict(default=None, type='bool'), read_only = dict(default=None, type='bool'),
labels = dict(default={}, type='dict'),
), ),
required_together = ( required_together = (
['tls_client_cert', 'tls_client_key'], ['tls_client_cert', 'tls_client_key'],

Loading…
Cancel
Save