Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion docker/api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def networks(self, names=None, ids=None, filters=None):
@minimum_version('1.21')
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):
enable_ipv6=False, attachable=None, scope=None,
ingress=None):
"""
Create a network. Similar to the ``docker network create``.

Expand All @@ -60,6 +61,8 @@ def create_network(self, name, driver=None, options=None, ipam=None,
attachable (bool): If enabled, and the network is in the global
scope, non-service containers on worker nodes will be able to
connect to the network.
ingress (bool): If set, create an ingress network which provides
the routing-mesh in swarm mode.

Returns:
(dict): The created network reference object
Expand Down Expand Up @@ -129,6 +132,14 @@ def create_network(self, name, driver=None, options=None, ipam=None,
)
data['Attachable'] = attachable

if ingress is not None:
if version_lt(self._version, '1.29'):
raise InvalidVersion(
'ingress is not supported in API version < 1.29'
)

data['Ingress'] = ingress

url = self._url("/networks/create")
res = self._post_json(url, data=data)
return self._result(res, json=True)
Expand Down
2 changes: 2 additions & 0 deletions docker/models/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def create(self, name, *args, **kwargs):
labels (dict): Map of labels to set on the network. Default
``None``.
enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``.
ingress (bool): If set, create an ingress network which provides
the routing-mesh in swarm mode.

Returns:
(:py:class:`Network`): The network that was created.
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/api_network_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,14 @@ def test_create_network_attachable(self):
net = self.client.inspect_network(net_id)
assert net['Attachable'] is True

@requires_api_version('1.29')
def test_create_network_ingress(self):
assert self.client.init_swarm('eth0')
self.client.remove_network('ingress')
_, net_id = self.create_network(driver='overlay', ingress=True)
net = self.client.inspect_network(net_id)
assert net['Ingress'] is True

@requires_api_version('1.25')
def test_prune_networks(self):
net_name, _ = self.create_network()
Expand Down