Reduce complexity of _get_container_create_options

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-11-27 13:19:27 -05:00
parent 38dd342b7b
commit 84a1822e40
1 changed files with 19 additions and 12 deletions

View File

@ -566,8 +566,7 @@ class Service(object):
elif not container_options.get('name'): elif not container_options.get('name'):
container_options['name'] = self.get_container_name(number, one_off) container_options['name'] = self.get_container_name(number, one_off)
if 'detach' not in container_options: container_options.setdefault('detach', True)
container_options['detach'] = True
# If a qualified hostname was given, split it into an # If a qualified hostname was given, split it into an
# unqualified hostname and a domainname unless domainname # unqualified hostname and a domainname unless domainname
@ -581,16 +580,9 @@ class Service(object):
container_options['domainname'] = parts[2] container_options['domainname'] = parts[2]
if 'ports' in container_options or 'expose' in self.options: if 'ports' in container_options or 'expose' in self.options:
ports = [] container_options['ports'] = build_container_ports(
all_ports = container_options.get('ports', []) + self.options.get('expose', []) container_options,
for port_range in all_ports: self.options)
internal_range, _ = split_port(port_range)
for port in internal_range:
port = str(port)
if '/' in port:
port = tuple(port.split('/'))
ports.append(port)
container_options['ports'] = ports
container_options['environment'] = merge_environment( container_options['environment'] = merge_environment(
self.options.get('environment'), self.options.get('environment'),
@ -1031,3 +1023,18 @@ def format_environment(environment):
return key return key
return '{key}={value}'.format(key=key, value=value) return '{key}={value}'.format(key=key, value=value)
return [format_env(*item) for item in environment.items()] return [format_env(*item) for item in environment.items()]
# Ports
def build_container_ports(container_options, options):
ports = []
all_ports = container_options.get('ports', []) + options.get('expose', [])
for port_range in all_ports:
internal_range, _ = split_port(port_range)
for port in internal_range:
port = str(port)
if '/' in port:
port = tuple(port.split('/'))
ports.append(port)
return ports