|
1 | 1 | import logging |
2 | | -from typing import Literal |
| 2 | +from typing import Any, Literal, TypedDict, type_check_only |
| 3 | +from typing_extensions import TypeAlias |
3 | 4 |
|
4 | | -from docker.types.swarm import SwarmSpec |
| 5 | +from docker.types.services import DriverConfig |
| 6 | +from docker.types.swarm import SwarmExternalCA, SwarmSpec |
5 | 7 |
|
6 | 8 | log: logging.Logger |
7 | 9 |
|
| 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 | + |
8 | 31 | 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: ... |
11 | 53 | def init_swarm( |
12 | 54 | self, |
13 | | - advertise_addr=None, |
| 55 | + advertise_addr: str | None = None, |
14 | 56 | listen_addr: str = "0.0.0.0:2377", |
15 | 57 | 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 |
24 | 66 | 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, |
26 | 73 | ) -> Literal[True]: ... |
27 | 74 | 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]: ... |
32 | 79 | def update_swarm( |
33 | 80 | self, |
34 | | - version, |
35 | | - swarm_spec=None, |
| 81 | + version: int, |
| 82 | + swarm_spec: dict[str, Any] | None = None, # Any: arbitrary SwarmSpec configuration body |
36 | 83 | rotate_worker_token: bool = False, |
37 | 84 | rotate_manager_token: bool = False, |
38 | 85 | rotate_manager_unlock_key: bool = False, |
|
0 commit comments