Added ulimits functionality to docker compose

Signed-off-by: Kevin Greene <kevin@spantree.net>
This commit is contained in:
Kevin Greene 2015-10-26 17:39:50 -04:00 committed by Daniel Nephin
commit 22d90d2180
6 changed files with 152 additions and 0 deletions

View file

@ -345,6 +345,15 @@ def validate_extended_service_dict(service_dict, filename, service):
"%s services with 'net: container' cannot be extended" % error_prefix)
def validate_ulimits(ulimit_config):
for limit_name, soft_hard_values in six.iteritems(ulimit_config):
if isinstance(soft_hard_values, dict):
if not soft_hard_values['soft'] <= soft_hard_values['hard']:
raise ConfigurationError(
"ulimit_config \"{}\" cannot contain a 'soft' value higher "
"than 'hard' value".format(ulimit_config))
def process_container_options(working_dir, service_dict):
service_dict = dict(service_dict)
@ -357,6 +366,9 @@ def process_container_options(working_dir, service_dict):
if 'labels' in service_dict:
service_dict['labels'] = parse_labels(service_dict['labels'])
if 'ulimits' in service_dict:
validate_ulimits(service_dict['ulimits'])
return service_dict

View file

@ -116,6 +116,25 @@
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"stdin_open": {"type": "boolean"},
"tty": {"type": "boolean"},
"ulimits": {
"type": "object",
"patternProperties": {
"^[a-z]+$": {
"oneOf": [
{"type": "integer"},
{
"type":"object",
"properties": {
"hard": {"type": "integer"},
"soft": {"type": "integer"}
},
"required": ["soft", "hard"],
"additionalProperties": false
}
]
}
}
},
"user": {"type": "string"},
"volumes": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"volume_driver": {"type": "string"},

View file

@ -676,6 +676,7 @@ class Service(object):
devices = options.get('devices', None)
cgroup_parent = options.get('cgroup_parent', None)
ulimits = build_ulimits(options.get('ulimits', None))
return self.client.create_host_config(
links=self._get_links(link_to_self=one_off),
@ -692,6 +693,7 @@ class Service(object):
cap_drop=cap_drop,
mem_limit=options.get('mem_limit'),
memswap_limit=options.get('memswap_limit'),
ulimits=ulimits,
log_config=log_config,
extra_hosts=extra_hosts,
read_only=read_only,
@ -1073,6 +1075,23 @@ def parse_restart_spec(restart_config):
return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
# Ulimits
def build_ulimits(ulimit_config):
if not ulimit_config:
return None
ulimits = []
for limit_name, soft_hard_values in six.iteritems(ulimit_config):
if isinstance(soft_hard_values, six.integer_types):
ulimits.append({'name': limit_name, 'soft': soft_hard_values, 'hard': soft_hard_values})
elif isinstance(soft_hard_values, dict):
ulimit_dict = {'name': limit_name}
ulimit_dict.update(soft_hard_values)
ulimits.append(ulimit_dict)
return ulimits
# Extra hosts