Skip to content

Commit acd7a8f

Browse files
committed
Return node id on swarm init
Signed-off-by: Hannes Ljungberg <[email protected]>
1 parent 992e0dc commit acd7a8f

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

docker/api/swarm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
117117
networks created from the default subnet pool. Default: None
118118
119119
Returns:
120-
``True`` if successful.
120+
(str): The ID of the created node.
121121
122122
Raises:
123123
:py:class:`docker.errors.APIError`
@@ -155,8 +155,7 @@ def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
155155
'Spec': swarm_spec,
156156
}
157157
response = self._post_json(url, data=data)
158-
self._raise_for_status(response)
159-
return True
158+
return self._result(response, json=True)
160159

161160
@utils.minimum_version('1.24')
162161
def inspect_swarm(self):

docker/models/swarm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
9696
created in the orchestrator.
9797
9898
Returns:
99-
``True`` if the request went through.
99+
(str): The ID of the created node.
100100
101101
Raises:
102102
:py:class:`docker.errors.APIError`
@@ -120,9 +120,9 @@ def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
120120
'subnet_size': subnet_size
121121
}
122122
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs)
123-
self.client.api.init_swarm(**init_kwargs)
123+
node_id = self.client.api.init_swarm(**init_kwargs)
124124
self.reload()
125-
return True
125+
return node_id
126126

127127
def join(self, *args, **kwargs):
128128
return self.client.api.join_swarm(*args, **kwargs)

tests/integration/api_swarm_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,14 @@ def test_list_nodes(self):
186186

187187
@requires_api_version('1.24')
188188
def test_inspect_node(self):
189-
assert self.init_swarm()
189+
node_id = self.init_swarm()
190+
assert node_id
190191
nodes_list = self.client.nodes()
191192
assert len(nodes_list) == 1
192193
node = nodes_list[0]
193194
node_data = self.client.inspect_node(node['ID'])
194195
assert node['ID'] == node_data['ID']
196+
assert node_id == node['ID']
195197
assert node['Version'] == node_data['Version']
196198

197199
@requires_api_version('1.24')

0 commit comments

Comments
 (0)