Kaydet (Commit) fc4bfde0 authored tarafından Joffrey F's avatar Joffrey F

Unify endpoint config creation when using connect_container_to_network

Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst b6fa9862
import json import json
from ..errors import InvalidVersion from ..errors import InvalidVersion
from ..utils import check_resource, minimum_version, normalize_links from ..utils import check_resource, minimum_version
from ..utils import version_lt from ..utils import version_lt
...@@ -63,26 +63,12 @@ class NetworkApiMixin(object): ...@@ -63,26 +63,12 @@ class NetworkApiMixin(object):
aliases=None, links=None): aliases=None, links=None):
data = { data = {
"Container": container, "Container": container,
"EndpointConfig": { "EndpointConfig": self.create_endpoint_config(
"Aliases": aliases, aliases=aliases, links=links, ipv4_address=ipv4_address,
"Links": normalize_links(links) if links else None, ipv6_address=ipv6_address
}, ),
} }
# IPv4 or IPv6 or neither:
if ipv4_address or ipv6_address:
if version_lt(self._version, '1.22'):
raise InvalidVersion('IP address assignment is not '
'supported in API version < 1.22')
data['EndpointConfig']['IPAMConfig'] = dict()
if ipv4_address:
data['EndpointConfig']['IPAMConfig']['IPv4Address'] = \
ipv4_address
if ipv6_address:
data['EndpointConfig']['IPAMConfig']['IPv6Address'] = \
ipv6_address
url = self._url("/networks/{0}/connect", net_id) url = self._url("/networks/{0}/connect", net_id)
res = self._post_json(url, data=data) res = self._post_json(url, data=data)
self._raise_for_status(res) self._raise_for_status(res)
......
...@@ -17,11 +17,13 @@ For example, setting the subnet to `192.168.52.0/24` and gateway address ...@@ -17,11 +17,13 @@ For example, setting the subnet to `192.168.52.0/24` and gateway address
to `192.168.52.254` to `192.168.52.254`
```python ```python
ipam_pool = docker.utils.create_ipam_pool(
ipam_config = docker.utils.create_ipam_config(
subnet='192.168.52.0/24', subnet='192.168.52.0/24',
gateway='192.168.52.254' gateway='192.168.52.254'
) )
ipam_config = docker.utils.create_ipam_config(
pool_configs=[ipam_pool]
)
docker_client.create_network("network1", driver="bridge", ipam=ipam_config) docker_client.create_network("network1", driver="bridge", ipam=ipam_config)
``` ```
...@@ -160,7 +162,7 @@ in `docker.utils.create_ipam_config`. ...@@ -160,7 +162,7 @@ in `docker.utils.create_ipam_config`.
```python ```python
ipam_pool = docker.utils.create_ipam_pool( ipam_pool = docker.utils.create_ipam_pool(
subnet='124.42.0.0/16', subnet='124.42.0.0/16',
iprange='124.42.0.0/8', iprange='124.42.0.0/24',
gateway='124.42.0.254', gateway='124.42.0.254',
aux_addresses={ aux_addresses={
'reserved1': '124.42.1.1' 'reserved1': '124.42.1.1'
......
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