Docker nodes

Nodes in Docker swarm

Don't use the constructor directly. Instead use

from python_on_whales import docker

my_docker_image = docker.node.inspect("my-node-name")

list_of_nodes = docker.node.list()

For type hints, use this

from python_on_whales import Node

def print_state(node: Node):
    print(node.status.state)

Attributes

It attributes are the same that you get with the command line: docker node inspect ...

To get a complete description of those attributes, you can take a look at the daemon api reference page and click on "200 No error".

An example is worth many lines of descriptions.

In [1]: from python_on_whales import docker

In [2]: docker.swarm.init()

In [3]: docker.node.list()[0]

In [4]: def super_print(obj):
   ...:     print(f"type = {type(obj)}, value = {obj}")
   ...:

In [4]: super_print(node.id)
type = <class 'str'>, value = qhumviluuscsa4bcfknht2k7k

In [5]: super_print(node.version.index)
type = <class 'int'>, value = 9

In [6]: super_print(node.created_at)
type = <class 'datetime.datetime'>, value = 2022-08-18 13:47:23.483289+00:00

In [7]: super_print(node.updated_at)
type = <class 'datetime.datetime'>, value = 2022-08-18 13:47:23.989349+00:00

In [8]: super_print(node.spec.name)
type = <class 'NoneType'>, value = None

In [9]: super_print(node.spec.labels)
type = <class 'dict'>, value = {}

In [10]: super_print(node.spec.role)
type = <class 'str'>, value = manager

In [11]: super_print(node.spec.availability)
type = <class 'str'>, value = active

In [12]: super_print(node.description.hostname)
type = <class 'str'>, value = fv-az200-988

In [13]: super_print(node.description.platform.architecture)
type = <class 'str'>, value = x86_64

In [14]: super_print(node.description.platform.os)
type = <class 'str'>, value = linux

In [15]: super_print(node.description.resources.nano_cpus)
type = <class 'int'>, value = 2000000000

In [16]: super_print(node.description.resources.memory_bytes)
type = <class 'int'>, value = 7281307648

In [17]: super_print(node.description.resources.generic_resources)
type = <class 'NoneType'>, value = None

In [18]: super_print(node.description.engine.engine_version)
type = <class 'str'>, value = 20.10.17+azure-1

In [19]: super_print(node.description.engine.labels)
type = <class 'NoneType'>, value = None

In [20]: super_print(node.description.engine.plugins)
type = <class 'list'>, value = [EnginePlugin(type='Log', name='awslogs'), EnginePlugin(type='Log', name='fluentd'), EnginePlugin(type='Log', name='gcplogs'), EnginePlugin(type='Log', name='gelf'), EnginePlugin(type='Log', name='journald'), EnginePlugin(type='Log', name='json-file'), EnginePlugin(type='Log', name='local'), EnginePlugin(type='Log', name='logentries'), EnginePlugin(type='Log', name='splunk'), EnginePlugin(type='Log', name='syslog'), EnginePlugin(type='Network', name='bridge'), EnginePlugin(type='Network', name='host'), EnginePlugin(type='Network', name='ipvlan'), EnginePlugin(type='Network', name='macvlan'), EnginePlugin(type='Network', name='null'), EnginePlugin(type='Network', name='overlay'), EnginePlugin(type='Volume', name='local'), EnginePlugin(type='Volume', name='mochoa/s3fs-volume-plugin:latest')]

In [21]: super_print(node.description.tls_info.trust_root)
type = <class 'str'>, value = -----BEGIN CERTIFICATE-----
MIIBajCCARCgAwIBAgIUA90tykZJ15qLZ2CsDg2cPBBI4CUwCgYIKoZIzj0EAwIw
EzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjIwODE4MTM0MjAwWhcNNDIwODEzMTM0
MjAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH
A0IABKp4CqPSGyrxmgEDydg8vAl43wmB2sdRIRXy5BTnN4UE0vpqRq3+MwQ1mH4g
ewTx6P4wf02uq0jJV+782ZKohm2jQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
Af8EBTADAQH/MB0GA1UdDgQWBBSY2O6OurZvHQ9DawAjF8O+RlwtpDAKBggqhkjO
PQQDAgNIADBFAiBTBcYqjstBwyr1BwG+kw0rFnzgJyeTyldtwmKyzCZsYgIhANip
R5utTdAe7Mo+IOFXpX+Yj/tGd6L4l0CSGIKMNtwD
-----END CERTIFICATE-----


In [22]: super_print(node.description.tls_info.cert_issuer_subject)
type = <class 'str'>, value = MBMxETAPBgNVBAMTCHN3YXJtLWNh

In [23]: super_print(node.description.tls_info.cert_issuer_public_key)
type = <class 'str'>, value = MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqngKo9IbKvGaAQPJ2Dy8CXjfCYHax1EhFfLkFOc3hQTS+mpGrf4zBDWYfiB7BPHo/jB/Ta6rSMlX7vzZkqiGbQ==

In [24]: super_print(node.status.state)
type = <class 'str'>, value = ready

In [25]: super_print(node.status.message)
type = <class 'NoneType'>, value = None

In [26]: super_print(node.status.addr)
type = <class 'str'>, value = 10.1.1.62

In [27]: super_print(node.manager_status.leader)
type = <class 'bool'>, value = True

In [28]: super_print(node.manager_status.reachability)
type = <class 'str'>, value = reachable

In [29]: super_print(node.manager_status.addr)
type = <class 'str'>, value = 10.1.1.62:2377

Methods

ps

Node.ps()

Returns the list of tasks running on this node

Returns

A List[python_on_whales.Task] object.


reload

Node.reload()

update

Node.update(availability=None, labels_add={}, rm_labels=[], role=None)

Updates this Swarm node.

See docker.node.update for more information about the arguments.