Nodes

Get and list nodes in a swarm. Before you can use these methods, you first need to join or initialize a swarm.

Methods available on client.nodes:

class NodeCollection
get(id_or_name)

Get a node.

Parameters:node_id (string) – ID of the node to be inspected.
Returns:A Node object.
Raises:docker.errors.APIError – If the server returns an error.
list(**kwargs)

List swarm nodes.

Parameters:filters (dict) – Filters to process on the nodes list. Valid filters: id, name, membership and role. Default: None
Returns:A list of Node objects.
Raises:docker.errors.APIError – If the server returns an error.

Example

>>> client.nodes.list(filters={'role': 'manager'})

Node objects

class Node

A node in a swarm.

id

The ID of the object.

short_id

The ID of the object, truncated to 10 characters.

attrs

The raw representation of this object from the server.

version

The version number of the service. If this is not the same as the server, the update() function will not work and you will need to call reload() before calling it again.

reload()

Load this object from the server again and update attrs with the new data.

update(node_spec)

Update the node’s configuration.

Parameters:node_spec (dict) – Configuration settings to update. Any values not provided will be removed. Default: None
Returns:True if the request went through.
Raises:docker.errors.APIError – If the server returns an error.

Example

>>> node_spec = {'Availability': 'active',
                 'Name': 'node-name',
                 'Role': 'manager',
                 'Labels': {'foo': 'bar'}
                }
>>> node.update(node_spec)