Kaydet (Commit) 0134939c authored tarafından Michael Hankin's avatar Michael Hankin

Change format in which hosts are being stored for Swarm services

Signed-off-by: 's avatarMichael Hankin <mhank@users.noreply.github.com>
üst 8d770b01
......@@ -137,7 +137,7 @@ class ContainerSpec(dict):
if labels is not None:
self['Labels'] = labels
if hosts is not None:
self['Hosts'] = format_extra_hosts(hosts)
self['Hosts'] = format_extra_hosts(hosts, task=True)
if mounts is not None:
parsed_mounts = []
......
......@@ -564,9 +564,15 @@ def format_environment(environment):
return [format_env(*var) for var in six.iteritems(environment)]
def format_extra_hosts(extra_hosts):
def format_extra_hosts(extra_hosts, task=False):
# Use format dictated by Swarm API if container is part of a task
if task:
return [
'{} {}'.format(v, k) for k, v in sorted(six.iteritems(extra_hosts))
]
return [
'{} {}'.format(v, k) for k, v in sorted(six.iteritems(extra_hosts))
'{}:{}'.format(k, v) for k, v in sorted(six.iteritems(extra_hosts))
]
......
......@@ -141,7 +141,7 @@ class ContainerCollectionTest(unittest.TestCase):
'Dns': ['8.8.8.8'],
'DnsOptions': ['foo'],
'DnsSearch': ['example.com'],
'ExtraHosts': ['1.2.3.4 foo'],
'ExtraHosts': ['foo:1.2.3.4'],
'GroupAdd': ['blah'],
'IpcMode': 'foo',
'KernelMemory': 123,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment