Skip to content

Commit c08fa66

Browse files
[docker] Improve type annotations in api.swarm (#15629)
1 parent 4ea569a commit c08fa66

File tree

1 file changed

+67
-20
lines changed

1 file changed

+67
-20
lines changed

stubs/docker/docker/api/swarm.pyi

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,85 @@
11
import logging
2-
from typing import Literal
2+
from typing import Any, Literal, TypedDict, type_check_only
3+
from typing_extensions import TypeAlias
34

4-
from docker.types.swarm import SwarmSpec
5+
from docker.types.services import DriverConfig
6+
from docker.types.swarm import SwarmExternalCA, SwarmSpec
57

68
log: logging.Logger
79

10+
@type_check_only
11+
class _HasId(TypedDict):
12+
Id: str
13+
14+
@type_check_only
15+
class _HasID(TypedDict):
16+
ID: str
17+
18+
_Node: TypeAlias = _HasId | _HasID | str
19+
20+
@type_check_only
21+
class _NodeSpec(TypedDict, total=False):
22+
Name: str
23+
Labels: dict[str, str]
24+
Role: Literal["worker", "manager"]
25+
Availability: Literal["active", "pause", "drain"]
26+
27+
@type_check_only
28+
class _UnlockKeyResponse(TypedDict):
29+
UnlockKey: str
30+
831
class SwarmApiMixin:
9-
def create_swarm_spec(self, *args, **kwargs) -> SwarmSpec: ...
10-
def get_unlock_key(self): ...
32+
def create_swarm_spec(
33+
self,
34+
task_history_retention_limit: int | None = None,
35+
snapshot_interval: int | None = None,
36+
keep_old_snapshots: int | None = None,
37+
log_entries_for_slow_followers: int | None = None,
38+
heartbeat_tick: int | None = None,
39+
election_tick: int | None = None,
40+
dispatcher_heartbeat_period: int | None = None,
41+
node_cert_expiry: int | None = None,
42+
external_ca: SwarmExternalCA | None = None,
43+
external_cas: list[SwarmExternalCA] | None = None,
44+
name: str | None = None,
45+
labels: dict[str, str] | None = None,
46+
signing_ca_cert: str | None = None,
47+
signing_ca_key: str | None = None,
48+
ca_force_rotate: int | None = None,
49+
autolock_managers: bool | None = None,
50+
log_driver: DriverConfig | None = None,
51+
) -> SwarmSpec: ...
52+
def get_unlock_key(self) -> _UnlockKeyResponse: ...
1153
def init_swarm(
1254
self,
13-
advertise_addr=None,
55+
advertise_addr: str | None = None,
1456
listen_addr: str = "0.0.0.0:2377",
1557
force_new_cluster: bool = False,
16-
swarm_spec=None,
17-
default_addr_pool=None,
18-
subnet_size=None,
19-
data_path_addr=None,
20-
data_path_port=None,
21-
): ...
22-
def inspect_swarm(self): ...
23-
def inspect_node(self, node_id): ...
58+
swarm_spec: dict[str, Any] | None = None, # Any: arbitrary SwarmSpec configuration body
59+
default_addr_pool: list[str] | None = None,
60+
subnet_size: int | None = None,
61+
data_path_addr: str | None = None,
62+
data_path_port: int | None = None,
63+
) -> str: ...
64+
def inspect_swarm(self) -> dict[str, Any]: ... # Any: deeply nested ClusterInfo + JoinTokens
65+
def inspect_node(self, node_id: _Node) -> dict[str, Any]: ... # Any: deeply nested Node object
2466
def join_swarm(
25-
self, remote_addrs, join_token, listen_addr: str = "0.0.0.0:2377", advertise_addr=None, data_path_addr=None
67+
self,
68+
remote_addrs: list[str],
69+
join_token: str,
70+
listen_addr: str = "0.0.0.0:2377",
71+
advertise_addr: str | None = None,
72+
data_path_addr: str | None = None,
2673
) -> Literal[True]: ...
2774
def leave_swarm(self, force: bool = False) -> Literal[True]: ...
28-
def nodes(self, filters=None): ...
29-
def remove_node(self, node_id, force: bool = False) -> Literal[True]: ...
30-
def unlock_swarm(self, key) -> Literal[True]: ...
31-
def update_node(self, node_id, version, node_spec=None) -> Literal[True]: ...
75+
def nodes(self, filters: dict[str, Any] | None = None) -> list[dict[str, Any]]: ... # Any: filter values + Node response
76+
def remove_node(self, node_id: _Node, force: bool = False) -> Literal[True]: ...
77+
def unlock_swarm(self, key: str | _UnlockKeyResponse) -> Literal[True]: ...
78+
def update_node(self, node_id: _Node, version: int, node_spec: _NodeSpec | None = None) -> Literal[True]: ...
3279
def update_swarm(
3380
self,
34-
version,
35-
swarm_spec=None,
81+
version: int,
82+
swarm_spec: dict[str, Any] | None = None, # Any: arbitrary SwarmSpec configuration body
3683
rotate_worker_token: bool = False,
3784
rotate_manager_token: bool = False,
3885
rotate_manager_unlock_key: bool = False,

0 commit comments

Comments
 (0)