diff options
| author | Michael Hankin <mhank@users.noreply.github.com> | 2017-12-05 21:19:37 -0600 |
|---|---|---|
| committer | Michael Hankin <mhank@users.noreply.github.com> | 2017-12-05 21:19:37 -0600 |
| commit | 0134939c2c5cc6920339a65a69305227849a452d (patch) | |
| tree | d3ae01a48e6617cde4d52544464b82106875926d | |
| parent | 8d770b012d6786ffb468e0fc929bde309a9500b1 (diff) | |
| download | docker-py-0134939c2c5cc6920339a65a69305227849a452d.tar.gz | |
Change format in which hosts are being stored for Swarm services
Signed-off-by: Michael Hankin <mhank@users.noreply.github.com>
| -rw-r--r-- | docker/types/services.py | 2 | ||||
| -rw-r--r-- | docker/utils/utils.py | 10 | ||||
| -rw-r--r-- | tests/unit/models_containers_test.py | 2 |
3 files changed, 10 insertions, 4 deletions
diff --git a/docker/types/services.py b/docker/types/services.py index 9031e60..5b6af8f 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -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 = [] diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 3e2a710..845af65 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -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)) ] diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index 29a5caa..5eaa45a 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -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, |
