Move restart spec to the config.types module.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
068edfa313
commit
12b82a20ff
5 changed files with 29 additions and 40 deletions
|
|
@ -14,6 +14,7 @@ from .errors import CircularReference
|
|||
from .errors import ComposeFileNotFound
|
||||
from .errors import ConfigurationError
|
||||
from .interpolation import interpolate_environment_variables
|
||||
from .types import parse_restart_spec
|
||||
from .types import VolumeFromSpec
|
||||
from .validation import validate_against_fields_schema
|
||||
from .validation import validate_against_service_schema
|
||||
|
|
@ -392,6 +393,9 @@ def finalize_service(service_config):
|
|||
service_dict['volumes_from'] = [
|
||||
VolumeFromSpec.parse(vf) for vf in service_dict['volumes_from']]
|
||||
|
||||
if 'restart' in service_dict:
|
||||
service_dict['restart'] = parse_restart_spec(service_dict['restart'])
|
||||
|
||||
return service_dict
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,3 +26,20 @@ class VolumeFromSpec(namedtuple('_VolumeFromSpec', 'source mode')):
|
|||
source, mode = parts
|
||||
|
||||
return cls(source, mode)
|
||||
|
||||
|
||||
def parse_restart_spec(restart_config):
|
||||
if not restart_config:
|
||||
return None
|
||||
parts = restart_config.split(':')
|
||||
if len(parts) > 2:
|
||||
raise ConfigurationError(
|
||||
"Restart %s has incorrect format, should be "
|
||||
"mode[:max_retry]" % restart_config)
|
||||
if len(parts) == 2:
|
||||
name, max_retry_count = parts
|
||||
else:
|
||||
name, = parts
|
||||
max_retry_count = 0
|
||||
|
||||
return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
|
||||
|
|
|
|||
|
|
@ -648,8 +648,6 @@ class Service(object):
|
|||
if isinstance(dns_search, six.string_types):
|
||||
dns_search = [dns_search]
|
||||
|
||||
restart = parse_restart_spec(options.get('restart', None))
|
||||
|
||||
extra_hosts = build_extra_hosts(options.get('extra_hosts', None))
|
||||
read_only = options.get('read_only', None)
|
||||
|
||||
|
|
@ -667,7 +665,7 @@ class Service(object):
|
|||
devices=devices,
|
||||
dns=dns,
|
||||
dns_search=dns_search,
|
||||
restart_policy=restart,
|
||||
restart_policy=options.get('restart'),
|
||||
cap_add=cap_add,
|
||||
cap_drop=cap_drop,
|
||||
mem_limit=options.get('mem_limit'),
|
||||
|
|
@ -1043,24 +1041,6 @@ def build_container_labels(label_options, service_labels, number, config_hash):
|
|||
return labels
|
||||
|
||||
|
||||
# Restart policy
|
||||
|
||||
|
||||
def parse_restart_spec(restart_config):
|
||||
if not restart_config:
|
||||
return None
|
||||
parts = restart_config.split(':')
|
||||
if len(parts) > 2:
|
||||
raise ConfigError("Restart %s has incorrect format, should be "
|
||||
"mode[:max_retry]" % restart_config)
|
||||
if len(parts) == 2:
|
||||
name, max_retry_count = parts
|
||||
else:
|
||||
name, = parts
|
||||
max_retry_count = 0
|
||||
|
||||
return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
|
||||
|
||||
# Ulimits
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue