Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docker/api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def networks(self, names=None, ids=None, filters=None):

def create_network(self, name, driver=None, options=None, ipam=None,
check_duplicate=None, internal=False, labels=None,
enable_ipv6=False, attachable=None, scope=None,
ingress=None):
enable_ipv4=True, enable_ipv6=False, attachable=None,
scope=None, ingress=None):
"""
Create a network. Similar to the ``docker network create``.

Expand All @@ -55,6 +55,7 @@ def create_network(self, name, driver=None, options=None, ipam=None,
``False``.
labels (dict): Map of labels to set on the network. Default
``None``.
enable_ipv4 (bool): Enable IPv4 on the network. Default ``True``.
enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``.
attachable (bool): If enabled, and the network is in the global
scope, non-service containers on worker nodes will be able to
Expand Down Expand Up @@ -112,6 +113,13 @@ def create_network(self, name, driver=None, options=None, ipam=None,
raise TypeError('labels must be a dictionary')
data["Labels"] = labels

if not enable_ipv4:
if version_lt(self._version, '1.48'):
raise InvalidVersion(
'enable_ipv4 was introduced in API 1.48'
)
data['EnableIPv4'] = False

if enable_ipv6:
if version_lt(self._version, '1.23'):
raise InvalidVersion(
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/api_network_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,22 @@ def test_create_network_with_labels_wrong_type(self):
with pytest.raises(TypeError):
self.create_network(labels=['com.docker.py.test=label', ])

@requires_api_version('1.48')
def test_create_network_ipv4_disabled(self):
_, net_id = self.create_network(
enable_ipv4=False, ipam=IPAMConfig(
driver='default',
pool_configs=[
IPAMPool(
subnet="2001:389::/64", iprange="2001:389::0/96",
gateway="2001:389::ffff"
)
]
)
)
net = self.client.inspect_network(net_id)
assert net['EnableIPv4'] is False

@requires_api_version('1.23')
def test_create_network_ipv6_enabled(self):
_, net_id = self.create_network(
Expand Down
1 change: 1 addition & 0 deletions tests/unit/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def get_fake_network_list():
"Id": FAKE_NETWORK_ID,
"Scope": "local",
"Driver": "bridge",
"EnableIPv4": True,
"EnableIPv6": False,
"Internal": False,
"IPAM": {
Expand Down