Return node id on swarm init

Signed-off-by: Hannes Ljungberg <hannes@5monkeys.se>
This commit is contained in:
Hannes Ljungberg 2019-03-28 10:48:22 +01:00
parent 992e0dcdfb
commit acd7a8f430
3 changed files with 8 additions and 7 deletions

View File

@ -117,7 +117,7 @@ class SwarmApiMixin(object):
networks created from the default subnet pool. Default: None networks created from the default subnet pool. Default: None
Returns: Returns:
``True`` if successful. (str): The ID of the created node.
Raises: Raises:
:py:class:`docker.errors.APIError` :py:class:`docker.errors.APIError`
@ -155,8 +155,7 @@ class SwarmApiMixin(object):
'Spec': swarm_spec, 'Spec': swarm_spec,
} }
response = self._post_json(url, data=data) response = self._post_json(url, data=data)
self._raise_for_status(response) return self._result(response, json=True)
return True
@utils.minimum_version('1.24') @utils.minimum_version('1.24')
def inspect_swarm(self): def inspect_swarm(self):

View File

@ -96,7 +96,7 @@ class Swarm(Model):
created in the orchestrator. created in the orchestrator.
Returns: Returns:
``True`` if the request went through. (str): The ID of the created node.
Raises: Raises:
:py:class:`docker.errors.APIError` :py:class:`docker.errors.APIError`
@ -120,9 +120,9 @@ class Swarm(Model):
'subnet_size': subnet_size 'subnet_size': subnet_size
} }
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs) 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() self.reload()
return True return node_id
def join(self, *args, **kwargs): def join(self, *args, **kwargs):
return self.client.api.join_swarm(*args, **kwargs) return self.client.api.join_swarm(*args, **kwargs)

View File

@ -186,12 +186,14 @@ class SwarmTest(BaseAPIIntegrationTest):
@requires_api_version('1.24') @requires_api_version('1.24')
def test_inspect_node(self): def test_inspect_node(self):
assert self.init_swarm() node_id = self.init_swarm()
assert node_id
nodes_list = self.client.nodes() nodes_list = self.client.nodes()
assert len(nodes_list) == 1 assert len(nodes_list) == 1
node = nodes_list[0] node = nodes_list[0]
node_data = self.client.inspect_node(node['ID']) node_data = self.client.inspect_node(node['ID'])
assert node['ID'] == node_data['ID'] assert node['ID'] == node_data['ID']
assert node_id == node['ID']
assert node['Version'] == node_data['Version'] assert node['Version'] == node_data['Version']
@requires_api_version('1.24') @requires_api_version('1.24')