Add --sysctl support for cloud/docker_container

pull/25312/head
Kassian Sun 8 years ago committed by Toshio Kuratomi
parent e90f1d6449
commit b3a37da671

@ -436,6 +436,12 @@ options:
- "List of ulimit options. A ulimit is specified as C(nofile:262144:262144)" - "List of ulimit options. A ulimit is specified as C(nofile:262144:262144)"
default: null default: null
required: false required: false
sysctls:
description:
- Dictionary of key,value pairs.
default: null
required: false
version_added: 2.4
user: user:
description: description:
- Sets the username or UID used and optionally the groupname or GID for the specified command. - Sets the username or UID used and optionally the groupname or GID for the specified command.
@ -484,6 +490,7 @@ author:
- "Daan Oosterveld (@dusdanig)" - "Daan Oosterveld (@dusdanig)"
- "James Tanner (@jctanner)" - "James Tanner (@jctanner)"
- "Chris Houseknecht (@chouseknecht)" - "Chris Houseknecht (@chouseknecht)"
- "Kassian Sun (@kassiansun)"
requirements: requirements:
- "python >= 2.6" - "python >= 2.6"
@ -798,6 +805,7 @@ class TaskParameters(DockerBaseClass):
self.env = self._get_environment() self.env = self._get_environment()
self.ulimits = self._parse_ulimits() self.ulimits = self._parse_ulimits()
self.sysctls = self._parse_sysctls()
self.log_config = self._parse_log_config() self.log_config = self._parse_log_config()
self.exp_links = None self.exp_links = None
self.volume_binds = self._get_volume_binds(self.volumes) self.volume_binds = self._get_volume_binds(self.volumes)
@ -949,6 +957,7 @@ class TaskParameters(DockerBaseClass):
ipc_mode='ipc_mode', ipc_mode='ipc_mode',
security_opt='security_opts', security_opt='security_opts',
ulimits='ulimits', ulimits='ulimits',
sysctls='sysctls',
log_config='log_config', log_config='log_config',
mem_limit='memory', mem_limit='memory',
memswap_limit='memory_swap', memswap_limit='memory_swap',
@ -1126,6 +1135,12 @@ class TaskParameters(DockerBaseClass):
self.fail("Error parsing ulimits value %s - %s" % (limit, exc)) self.fail("Error parsing ulimits value %s - %s" % (limit, exc))
return results return results
def _parse_sysctls(self):
'''
Turn sysctls into an hash of Sysctl objects
'''
return self.sysctls
def _parse_log_config(self): def _parse_log_config(self):
''' '''
Create a LogConfig object Create a LogConfig object
@ -1191,6 +1206,7 @@ class Container(DockerBaseClass):
self.parameters.expected_exposed = None self.parameters.expected_exposed = None
self.parameters.expected_volumes = None self.parameters.expected_volumes = None
self.parameters.expected_ulimits = None self.parameters.expected_ulimits = None
self.parameters.expected_sysctls = None
self.parameters.expected_etc_hosts = None self.parameters.expected_etc_hosts = None
self.parameters.expected_env = None self.parameters.expected_env = None
@ -1220,6 +1236,7 @@ class Container(DockerBaseClass):
self.parameters.expected_volumes = self._get_expected_volumes(image) self.parameters.expected_volumes = self._get_expected_volumes(image)
self.parameters.expected_binds = self._get_expected_binds(image) self.parameters.expected_binds = self._get_expected_binds(image)
self.parameters.expected_ulimits = self._get_expected_ulimits(self.parameters.ulimits) self.parameters.expected_ulimits = self._get_expected_ulimits(self.parameters.ulimits)
self.parameters.expected_sysctls = self._get_expected_sysctls(self.parameters.sysctls)
self.parameters.expected_etc_hosts = self._convert_simple_dict_to_list('etc_hosts') self.parameters.expected_etc_hosts = self._convert_simple_dict_to_list('etc_hosts')
self.parameters.expected_env = self._get_expected_env(image) self.parameters.expected_env = self._get_expected_env(image)
self.parameters.expected_cmd = self._get_expected_cmd() self.parameters.expected_cmd = self._get_expected_cmd()
@ -1289,6 +1306,7 @@ class Container(DockerBaseClass):
stop_signal=config.get("StopSignal"), stop_signal=config.get("StopSignal"),
tty=config.get('Tty'), tty=config.get('Tty'),
expected_ulimits=host_config.get('Ulimits'), expected_ulimits=host_config.get('Ulimits'),
expected_sysctls=host_config.get('Sysctls'),
uts=host_config.get('UTSMode'), uts=host_config.get('UTSMode'),
expected_volumes=config.get('Volumes'), expected_volumes=config.get('Volumes'),
expected_binds=host_config.get('Binds'), expected_binds=host_config.get('Binds'),
@ -1676,6 +1694,15 @@ class Container(DockerBaseClass):
)) ))
return results return results
def _get_expected_sysctls(self, config_sysctls):
self.log('_get_expected_sysctls')
if config_sysctls is None:
return None
result = dict()
for key, value in config_sysctls.items():
result[key] = str(value)
return result
def _get_expected_cmd(self): def _get_expected_cmd(self):
self.log('_get_expected_cmd') self.log('_get_expected_cmd')
if not self.parameters.command: if not self.parameters.command:
@ -2046,6 +2073,7 @@ def main():
trust_image_content=dict(type='bool', default=False), trust_image_content=dict(type='bool', default=False),
tty=dict(type='bool', default=False), tty=dict(type='bool', default=False),
ulimits=dict(type='list'), ulimits=dict(type='list'),
sysctls=dict(type='dict'),
user=dict(type='str'), user=dict(type='str'),
uts=dict(type='str'), uts=dict(type='str'),
volumes=dict(type='list'), volumes=dict(type='list'),

Loading…
Cancel
Save