Updated PR based on comments

This commit is contained in:
David Dyball 2015-09-08 16:19:26 +01:00 committed by Matt Clay
parent fb317c72b6
commit cdff62643b

View file

@ -111,6 +111,14 @@ options:
- none - none
- syslog - syslog
version_added: "2.0" version_added: "2.0"
log_opt:
description:
- Additional options to pass to the logging driver selected above. See Docker log-driver
documentation for more information (https://docs.docker.com/reference/logging/overview/).
Requires docker >=1.7.0.
required: false
default: null
version_added: "2.0"
memory_limit: memory_limit:
description: description:
- RAM allocated to the container as a number of bytes or as a human-readable - RAM allocated to the container as a number of bytes or as a human-readable
@ -420,6 +428,19 @@ EXAMPLES = '''
name: ohno name: ohno
image: someuser/oldandbusted image: someuser/oldandbusted
state: absent state: absent
# Example Syslogging Output
- name: myservice container
docker:
name: myservice
image: someservice/someimage
state: reloaded
log_driver: syslog
log_opt:
syslog-address: tcp://my-syslog-server:514
syslog-facility: daemon
syslog-tag: myservice
''' '''
HAS_DOCKER_PY = True HAS_DOCKER_PY = True
@ -575,6 +596,7 @@ class DockerManager(object):
'extra_hosts': ((0, 7, 0), '1.3.1'), 'extra_hosts': ((0, 7, 0), '1.3.1'),
'pid': ((1, 0, 0), '1.17'), 'pid': ((1, 0, 0), '1.17'),
'log_driver': ((1, 2, 0), '1.18'), 'log_driver': ((1, 2, 0), '1.18'),
'log_opt': ((1, 2, 0), '1.18'),
'host_config': ((0, 7, 0), '1.15'), 'host_config': ((0, 7, 0), '1.15'),
'cpu_set': ((0, 6, 0), '1.14'), 'cpu_set': ((0, 6, 0), '1.14'),
'cap_add': ((0, 5, 0), '1.14'), 'cap_add': ((0, 5, 0), '1.14'),
@ -806,7 +828,7 @@ class DockerManager(object):
optionals = {} optionals = {}
for optional_param in ('dns', 'volumes_from', 'restart_policy', for optional_param in ('dns', 'volumes_from', 'restart_policy',
'restart_policy_retry', 'pid', 'extra_hosts', 'log_driver', 'restart_policy_retry', 'pid', 'extra_hosts', 'log_driver',
'cap_add', 'cap_drop', 'read_only'): 'cap_add', 'cap_drop', 'read_only', 'log_opt'):
optionals[optional_param] = self.module.params.get(optional_param) optionals[optional_param] = self.module.params.get(optional_param)
if optionals['dns'] is not None: if optionals['dns'] is not None:
@ -838,6 +860,9 @@ class DockerManager(object):
if optionals['log_driver'] is not None: if optionals['log_driver'] is not None:
self.ensure_capability('log_driver') self.ensure_capability('log_driver')
log_config = docker.utils.LogConfig(type=docker.utils.LogConfig.types.JSON) log_config = docker.utils.LogConfig(type=docker.utils.LogConfig.types.JSON)
if optionals['log_opt'] is not None:
for k, v in optionals['log_opt'].iteritems():
log_config.set_config_value(k, v)
log_config.type = optionals['log_driver'] log_config.type = optionals['log_driver']
params['log_config'] = log_config params['log_config'] = log_config
@ -1267,7 +1292,7 @@ class DockerManager(object):
# LOG_DRIVER # LOG_DRIVER
if self.ensure_capability('log_driver', False) : if self.ensure_capability('log_driver', False):
expected_log_driver = self.module.params.get('log_driver') or 'json-file' expected_log_driver = self.module.params.get('log_driver') or 'json-file'
actual_log_driver = container['HostConfig']['LogConfig']['Type'] actual_log_driver = container['HostConfig']['LogConfig']['Type']
if actual_log_driver != expected_log_driver: if actual_log_driver != expected_log_driver:
@ -1275,6 +1300,17 @@ class DockerManager(object):
differing.append(container) differing.append(container)
continue continue
if self.ensure_capability('log_opt', False):
expected_logging_opts = self.module.params.get('log_opt') or {}
actual_log_opts = container['HostConfig']['LogConfig']['Config']
if len(set(expected_logging_opts.items()) - set(actual_log_opts.items())) != 0:
log_opt_reasons = {
'added': dict(set(expected_logging_opts.items()) - set(actual_log_opts.items())),
'removed': dict(set(actual_log_opts.items()) - set(expected_logging_opts.items()))
}
self.reload_reasons.append('log_opt ({0})'.format(log_opt_reasons))
differing.append(container)
return differing return differing
def get_deployed_containers(self): def get_deployed_containers(self):
@ -1645,6 +1681,7 @@ def main():
pid = dict(default=None), pid = dict(default=None),
insecure_registry = dict(default=False, type='bool'), insecure_registry = dict(default=False, type='bool'),
log_driver = dict(default=None, choices=['json-file', 'none', 'syslog']), log_driver = dict(default=None, choices=['json-file', 'none', 'syslog']),
log_opt = dict(default=None, type='dict'),
cpu_set = dict(default=None), cpu_set = dict(default=None),
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'),