|
1 | 1 | import datetime |
2 | 2 | from _typeshed import Incomplete |
| 3 | +from collections.abc import Iterable, Mapping |
3 | 4 | from typing import Any, Literal, TypeAlias, TypedDict, overload, type_check_only |
| 5 | +from typing_extensions import NotRequired |
4 | 6 |
|
5 | | -from docker._types import WaitContainerResponse |
| 7 | +from docker._types import ContainerWeightDevice, WaitContainerResponse |
| 8 | +from docker.types.containers import DeviceRequest, LogConfig, Ulimit |
6 | 9 | from docker.types.daemon import CancellableStream |
| 10 | +from docker.types.healthcheck import Healthcheck |
| 11 | +from docker.types.services import Mount |
7 | 12 |
|
8 | 13 | from ..types import ContainerConfig, EndpointConfig, HostConfig, NetworkingConfig |
9 | 14 |
|
| 15 | +@type_check_only |
| 16 | +class _RestartPolicy(TypedDict): |
| 17 | + MaximumRetryCount: NotRequired[int] |
| 18 | + Name: NotRequired[Literal["always", "on-failure"]] |
| 19 | + |
10 | 20 | @type_check_only |
11 | 21 | class _HasId(TypedDict): |
12 | 22 | Id: str |
@@ -121,11 +131,116 @@ class ContainerApiMixin: |
121 | 131 | use_config_proxy: bool = True, |
122 | 132 | platform: str | None = None, |
123 | 133 | ): ... |
124 | | - def create_container_config(self, *args, **kwargs) -> ContainerConfig: ... |
| 134 | + # Please keep in sync with docker.types.ContainerConfig |
| 135 | + def create_container_config( |
| 136 | + self, |
| 137 | + image: str, |
| 138 | + command: str | list[str], |
| 139 | + hostname: str | None = None, |
| 140 | + user: str | int | None = None, |
| 141 | + detach: bool = False, |
| 142 | + stdin_open: bool = False, |
| 143 | + tty: bool = False, |
| 144 | + # list is invariant, enumerating all possible union combination would be too complex for: |
| 145 | + # list[str | int | tuple[int | str, str] | tuple[int | str, ...]] |
| 146 | + ports: dict[str, dict[str, str]] | list[Any] | None = None, |
| 147 | + environment: dict[str, str] | list[str] | None = None, |
| 148 | + volumes: str | list[str] | None = None, |
| 149 | + network_disabled: bool = False, |
| 150 | + entrypoint: str | list[str] | None = None, |
| 151 | + working_dir: str | None = None, |
| 152 | + domainname: str | None = None, |
| 153 | + host_config: HostConfig | None = None, |
| 154 | + mac_address: str | None = None, |
| 155 | + labels: dict[str, str] | list[str] | None = None, |
| 156 | + stop_signal: str | None = None, |
| 157 | + networking_config: NetworkingConfig | None = None, |
| 158 | + healthcheck: Healthcheck | None = None, |
| 159 | + stop_timeout: int | None = None, |
| 160 | + runtime: str | None = None, |
| 161 | + ) -> ContainerConfig: ... |
125 | 162 | def create_container_from_config(self, config, name=None, platform=None): ... |
126 | | - def create_host_config(self, *args, **kwargs) -> HostConfig: ... |
127 | | - def create_networking_config(self, *args, **kwargs) -> NetworkingConfig: ... |
128 | | - def create_endpoint_config(self, *args, **kwargs) -> EndpointConfig: ... |
| 163 | + # Please keep in sync with docker.types.HostConfig |
| 164 | + def create_host_config( |
| 165 | + self, |
| 166 | + binds: dict[str, Mapping[str, str]] | list[str] | None = None, |
| 167 | + port_bindings: Mapping[int | str, Any] | None = None, # Any: int, str, tuple, dict, or list |
| 168 | + lxc_conf: dict[str, str] | list[dict[str, str]] | None = None, |
| 169 | + publish_all_ports: bool = False, |
| 170 | + links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None, |
| 171 | + privileged: bool = False, |
| 172 | + dns: list[str] | None = None, |
| 173 | + dns_search: list[str] | None = None, |
| 174 | + volumes_from: list[str] | None = None, |
| 175 | + network_mode: str | None = None, |
| 176 | + restart_policy: Mapping[str, str | int] | None = None, |
| 177 | + cap_add: list[str] | None = None, |
| 178 | + cap_drop: list[str] | None = None, |
| 179 | + devices: list[str] | None = None, |
| 180 | + extra_hosts: dict[str, str] | list[str] | None = None, |
| 181 | + read_only: bool | None = None, |
| 182 | + pid_mode: str | None = None, |
| 183 | + ipc_mode: str | None = None, |
| 184 | + security_opt: list[str] | None = None, |
| 185 | + ulimits: list[Ulimit] | None = None, |
| 186 | + log_config: LogConfig | None = None, |
| 187 | + mem_limit: str | int | None = None, |
| 188 | + memswap_limit: str | int | None = None, |
| 189 | + mem_reservation: str | int | None = None, |
| 190 | + kernel_memory: str | int | None = None, |
| 191 | + mem_swappiness: int | None = None, |
| 192 | + cgroup_parent: str | None = None, |
| 193 | + group_add: Iterable[str | int] | None = None, |
| 194 | + cpu_quota: int | None = None, |
| 195 | + cpu_period: int | None = None, |
| 196 | + blkio_weight: int | None = None, |
| 197 | + blkio_weight_device: list[ContainerWeightDevice] | None = None, |
| 198 | + device_read_bps: list[Mapping[str, str | int]] | None = None, |
| 199 | + device_write_bps: list[Mapping[str, str | int]] | None = None, |
| 200 | + device_read_iops: list[Mapping[str, str | int]] | None = None, |
| 201 | + device_write_iops: list[Mapping[str, str | int]] | None = None, |
| 202 | + oom_kill_disable: bool = False, |
| 203 | + shm_size: str | int | None = None, |
| 204 | + sysctls: dict[str, str] | None = None, |
| 205 | + tmpfs: dict[str, str] | None = None, |
| 206 | + oom_score_adj: int | None = None, |
| 207 | + dns_opt: list[str] | None = None, |
| 208 | + cpu_shares: int | None = None, |
| 209 | + cpuset_cpus: str | None = None, |
| 210 | + userns_mode: str | None = None, |
| 211 | + uts_mode: str | None = None, |
| 212 | + pids_limit: int | None = None, |
| 213 | + isolation: str | None = None, |
| 214 | + auto_remove: bool = False, |
| 215 | + storage_opt: dict[str, str] | None = None, |
| 216 | + init: bool | None = None, |
| 217 | + init_path: str | None = None, |
| 218 | + volume_driver: str | None = None, |
| 219 | + cpu_count: int | None = None, |
| 220 | + cpu_percent: int | None = None, |
| 221 | + nano_cpus: int | None = None, |
| 222 | + cpuset_mems: str | None = None, |
| 223 | + runtime: str | None = None, |
| 224 | + mounts: list[Mount] | None = None, |
| 225 | + cpu_rt_period: int | None = None, |
| 226 | + cpu_rt_runtime: int | None = None, |
| 227 | + device_cgroup_rules: list[str] | None = None, |
| 228 | + device_requests: list[DeviceRequest] | None = None, |
| 229 | + cgroupns: Literal["private", "host"] | None = None, |
| 230 | + ) -> HostConfig: ... |
| 231 | + # Please keep in sync with docker.types.NetworkingConfig |
| 232 | + def create_networking_config(self, endpoints_config: EndpointConfig | None = None) -> NetworkingConfig: ... |
| 233 | + # Please keep in sync with docker.types.EndpointConfig |
| 234 | + def create_endpoint_config( |
| 235 | + self, |
| 236 | + aliases: list[str] | None = None, |
| 237 | + links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None, |
| 238 | + ipv4_address: str | None = None, |
| 239 | + ipv6_address: str | None = None, |
| 240 | + link_local_ips: list[str] | None = None, |
| 241 | + driver_opt: dict[str, str] | None = None, |
| 242 | + mac_address: str | None = None, |
| 243 | + ) -> EndpointConfig: ... |
129 | 244 | def diff(self, container: _Container) -> list[dict[Incomplete, Incomplete]]: ... |
130 | 245 | def export(self, container: _Container, chunk_size: int | None = 2097152): ... |
131 | 246 | def get_archive( |
@@ -201,7 +316,7 @@ class ContainerApiMixin: |
201 | 316 | mem_reservation: float | str | None = None, |
202 | 317 | memswap_limit: int | str | None = None, |
203 | 318 | kernel_memory: int | str | None = None, |
204 | | - restart_policy=None, |
| 319 | + restart_policy: _RestartPolicy | None = None, |
205 | 320 | ): ... |
206 | 321 | def wait( |
207 | 322 | self, |
|
0 commit comments