Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swarm support for DataPathPort #2987

Merged
merged 1 commit into from
Aug 12, 2022
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/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_unlock_key(self):
def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
force_new_cluster=False, swarm_spec=None,
default_addr_pool=None, subnet_size=None,
data_path_addr=None):
data_path_addr=None, data_path_port=None):
"""
Initialize a new Swarm using the current connected engine as the first
node.
Expand Down Expand Up @@ -118,6 +118,9 @@ def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
networks created from the default subnet pool. Default: None
data_path_addr (string): Address or interface to use for data path
traffic. For example, 192.168.1.1, or an interface, like eth0.
data_path_port (int): Port number to use for data path traffic.
Acceptable port range is 1024 to 49151. If set to ``None`` or
0, the default port 4789 will be used. Default: None

Returns:
(str): The ID of the created node.
Expand Down Expand Up @@ -166,6 +169,14 @@ def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
)
data['DataPathAddr'] = data_path_addr

if data_path_port is not None:
if utils.version_lt(self._version, '1.40'):
raise errors.InvalidVersion(
'Data path port is only available for '
'API version >= 1.40'
)
data['DataPathPort'] = data_path_port

response = self._post_json(url, data=data)
return self._result(response, json=True)

Expand Down
7 changes: 6 additions & 1 deletion docker/models/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def get_unlock_key(self):

def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
force_new_cluster=False, default_addr_pool=None,
subnet_size=None, data_path_addr=None, **kwargs):
subnet_size=None, data_path_addr=None, data_path_port=None,
**kwargs):
"""
Initialize a new swarm on this Engine.

Expand Down Expand Up @@ -65,6 +66,9 @@ def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
networks created from the default subnet pool. Default: None
data_path_addr (string): Address or interface to use for data path
traffic. For example, 192.168.1.1, or an interface, like eth0.
data_path_port (int): Port number to use for data path traffic.
Acceptable port range is 1024 to 49151. If set to ``None`` or
0, the default port 4789 will be used. Default: None
task_history_retention_limit (int): Maximum number of tasks
history stored.
snapshot_interval (int): Number of logs entries between snapshot.
Expand Down Expand Up @@ -121,6 +125,7 @@ def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
'default_addr_pool': default_addr_pool,
'subnet_size': subnet_size,
'data_path_addr': data_path_addr,
'data_path_port': data_path_port,
}
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs)
node_id = self.client.api.init_swarm(**init_kwargs)
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/api_swarm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,8 @@ def test_rotate_manager_unlock_key(self):
@pytest.mark.xfail(reason='Can fail if eth0 has multiple IP addresses')
def test_init_swarm_data_path_addr(self):
assert self.init_swarm(data_path_addr='eth0')

@requires_api_version('1.40')
def test_init_swarm_data_path_port(self):
assert self.init_swarm(data_path_port=4242)
assert self.client.inspect_swarm()['DataPathPort'] == 4242