Skip to content

Commit 0e08b1e

Browse files
committed
Add support for Docker network EnableIPv4 option with API 1.48
1 parent 6e6a273 commit 0e08b1e

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docker/api/network.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def networks(self, names=None, ids=None, filters=None):
3939

4040
def create_network(self, name, driver=None, options=None, ipam=None,
4141
check_duplicate=None, internal=False, labels=None,
42-
enable_ipv6=False, attachable=None, scope=None,
43-
ingress=None):
42+
enable_ipv4=True, enable_ipv6=False, attachable=None,
43+
scope=None, ingress=None):
4444
"""
4545
Create a network. Similar to the ``docker network create``.
4646
@@ -55,6 +55,7 @@ def create_network(self, name, driver=None, options=None, ipam=None,
5555
``False``.
5656
labels (dict): Map of labels to set on the network. Default
5757
``None``.
58+
enable_ipv4 (bool): Enable IPv4 on the network. Default ``True``.
5859
enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``.
5960
attachable (bool): If enabled, and the network is in the global
6061
scope, non-service containers on worker nodes will be able to
@@ -112,6 +113,13 @@ def create_network(self, name, driver=None, options=None, ipam=None,
112113
raise TypeError('labels must be a dictionary')
113114
data["Labels"] = labels
114115

116+
if not enable_ipv4:
117+
if version_lt(self._version, '1.48'):
118+
raise InvalidVersion(
119+
'enable_ipv4 was introduced in API 1.48'
120+
)
121+
data['EnableIPv4'] = False
122+
115123
if enable_ipv6:
116124
if version_lt(self._version, '1.23'):
117125
raise InvalidVersion(

tests/integration/api_network_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,22 @@ def test_create_network_with_labels_wrong_type(self):
447447
with pytest.raises(TypeError):
448448
self.create_network(labels=['com.docker.py.test=label', ])
449449

450+
@requires_api_version('1.48')
451+
def test_create_network_ipv4_disabled(self):
452+
_, net_id = self.create_network(
453+
enable_ipv4=False, ipam=IPAMConfig(
454+
driver='default',
455+
pool_configs=[
456+
IPAMPool(
457+
subnet="2001:389::/64", iprange="2001:389::0/96",
458+
gateway="2001:389::ffff"
459+
)
460+
]
461+
)
462+
)
463+
net = self.client.inspect_network(net_id)
464+
assert net['EnableIPv4'] is False
465+
450466
@requires_api_version('1.23')
451467
def test_create_network_ipv6_enabled(self):
452468
_, net_id = self.create_network(

tests/unit/fake_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ def get_fake_network_list():
460460
"Id": FAKE_NETWORK_ID,
461461
"Scope": "local",
462462
"Driver": "bridge",
463+
"EnableIPv4": True,
463464
"EnableIPv6": False,
464465
"Internal": False,
465466
"IPAM": {

0 commit comments

Comments
 (0)