summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2019-05-01 02:29:30 -0700
committerGitHub <noreply@github.com>2019-05-01 02:29:30 -0700
commit4d62dd0a64170e8bfcbf319eb6fcafe316c2138b (patch)
tree3c18be3b4c238b87ac14bf14a71dfa4356006f3e
parent9682422718653a393f8c892f4b2e937e2f81573c (diff)
parentacd7a8f43056007d8ae5df3d8156c34b837d97b1 (diff)
downloaddocker-py-4d62dd0a64170e8bfcbf319eb6fcafe316c2138b.tar.gz
Merge pull request #2296 from hannseman/swarm-init-response
Return node id on swarm init
-rw-r--r--docker/api/swarm.py5
-rw-r--r--docker/models/swarm.py6
-rw-r--r--tests/integration/api_swarm_test.py4
3 files changed, 8 insertions, 7 deletions
diff --git a/docker/api/swarm.py b/docker/api/swarm.py
index 0bd6d12..13e4fd5 100644
--- a/docker/api/swarm.py
+++ b/docker/api/swarm.py
@@ -120,7 +120,7 @@ class SwarmApiMixin(object):
traffic. For example, 192.168.1.1, or an interface, like eth0.
Returns:
- ``True`` if successful.
+ (str): The ID of the created node.
Raises:
:py:class:`docker.errors.APIError`
@@ -167,8 +167,7 @@ class SwarmApiMixin(object):
data['DataPathAddr'] = data_path_addr
response = self._post_json(url, data=data)
- self._raise_for_status(response)
- return True
+ return self._result(response, json=True)
@utils.minimum_version('1.24')
def inspect_swarm(self):
diff --git a/docker/models/swarm.py b/docker/models/swarm.py
index 386d23d..f8c5fff 100644
--- a/docker/models/swarm.py
+++ b/docker/models/swarm.py
@@ -98,7 +98,7 @@ class Swarm(Model):
created in the orchestrator.
Returns:
- ``True`` if the request went through.
+ (str): The ID of the created node.
Raises:
:py:class:`docker.errors.APIError`
@@ -123,9 +123,9 @@ class Swarm(Model):
'data_path_addr': data_path_addr,
}
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs)
- self.client.api.init_swarm(**init_kwargs)
+ node_id = self.client.api.init_swarm(**init_kwargs)
self.reload()
- return True
+ return node_id
def join(self, *args, **kwargs):
return self.client.api.join_swarm(*args, **kwargs)
diff --git a/tests/integration/api_swarm_test.py b/tests/integration/api_swarm_test.py
index 5e9aea1..5d4086a 100644
--- a/tests/integration/api_swarm_test.py
+++ b/tests/integration/api_swarm_test.py
@@ -186,12 +186,14 @@ class SwarmTest(BaseAPIIntegrationTest):
@requires_api_version('1.24')
def test_inspect_node(self):
- assert self.init_swarm()
+ node_id = self.init_swarm()
+ assert node_id
nodes_list = self.client.nodes()
assert len(nodes_list) == 1
node = nodes_list[0]
node_data = self.client.inspect_node(node['ID'])
assert node['ID'] == node_data['ID']
+ assert node_id == node['ID']
assert node['Version'] == node_data['Version']
@requires_api_version('1.24')