Skip to content

Commit 8645d1d

Browse files
authored
Merge pull request #1617 from docker/create-ingress-network
Add support for ingress in create_network
2 parents 0ac926b + ff718f5 commit 8645d1d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docker/api/network.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def networks(self, names=None, ids=None, filters=None):
4141
@minimum_version('1.21')
4242
def create_network(self, name, driver=None, options=None, ipam=None,
4343
check_duplicate=None, internal=False, labels=None,
44-
enable_ipv6=False, attachable=None, scope=None):
44+
enable_ipv6=False, attachable=None, scope=None,
45+
ingress=None):
4546
"""
4647
Create a network. Similar to the ``docker network create``.
4748
@@ -60,6 +61,8 @@ def create_network(self, name, driver=None, options=None, ipam=None,
6061
attachable (bool): If enabled, and the network is in the global
6162
scope, non-service containers on worker nodes will be able to
6263
connect to the network.
64+
ingress (bool): If set, create an ingress network which provides
65+
the routing-mesh in swarm mode.
6366
6467
Returns:
6568
(dict): The created network reference object
@@ -129,6 +132,14 @@ def create_network(self, name, driver=None, options=None, ipam=None,
129132
)
130133
data['Attachable'] = attachable
131134

135+
if ingress is not None:
136+
if version_lt(self._version, '1.29'):
137+
raise InvalidVersion(
138+
'ingress is not supported in API version < 1.29'
139+
)
140+
141+
data['Ingress'] = ingress
142+
132143
url = self._url("/networks/create")
133144
res = self._post_json(url, data=data)
134145
return self._result(res, json=True)

docker/models/networks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def create(self, name, *args, **kwargs):
111111
labels (dict): Map of labels to set on the network. Default
112112
``None``.
113113
enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``.
114+
ingress (bool): If set, create an ingress network which provides
115+
the routing-mesh in swarm mode.
114116
115117
Returns:
116118
(:py:class:`Network`): The network that was created.

tests/integration/api_network_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ def test_create_network_attachable(self):
452452
net = self.client.inspect_network(net_id)
453453
assert net['Attachable'] is True
454454

455+
@requires_api_version('1.29')
456+
def test_create_network_ingress(self):
457+
assert self.client.init_swarm('eth0')
458+
self.client.remove_network('ingress')
459+
_, net_id = self.create_network(driver='overlay', ingress=True)
460+
net = self.client.inspect_network(net_id)
461+
assert net['Ingress'] is True
462+
455463
@requires_api_version('1.25')
456464
def test_prune_networks(self):
457465
net_name, _ = self.create_network()

0 commit comments

Comments
 (0)