Skip to content

Commit

Permalink
Update PodCLI.create() to use Iterable and Mapping types
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisGaul committed Jun 1, 2024
1 parent d09f324 commit b2d0a7c
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions python_on_whales/components/pod/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,17 @@ def create(
self,
name: Optional[str] = None,
*,
add_hosts: List[Tuple[str, str]] = [],
add_hosts: Iterable[Tuple[str, str]] = (),
cgroup_parent: Optional[str] = None,
cpus: Optional[float] = None,
cpuset_cpus: Optional[List[int]] = None,
devices: List[str] = [],
device_read_bps: List[str] = [],
dns: List[str] = [],
dns_options: List[str] = [],
dns_search: List[str] = [],
cpuset_cpus: Optional[Iterable[int]] = None,
devices: Iterable[str] = (),
device_read_bps: Iterable[str] = (),
dns: Iterable[str] = (),
dns_options: Iterable[str] = (),
dns_search: Iterable[str] = (),
exit_policy: Optional[str] = None,
gidmaps: List[Tuple[int, int, int]] = [],
gidmaps: Iterable[Tuple[int, int, int]] = (),
hostname: Optional[str] = None,
infra: Optional[bool] = None,
infra_command: Optional[str] = None,
Expand All @@ -280,33 +280,33 @@ def create(
infra_name: Optional[str] = None,
ip: Optional[str] = None,
ip6: Optional[str] = None,
labels: Dict[str, str] = {},
label_files: List[ValidPath] = [],
labels: Mapping[str, str] = {},
label_files: Iterable[ValidPath] = (),
mac_address: Optional[str] = None,
memory: Union[int, str, None] = None,
networks: List[
networks: Iterable[
python_on_whales.components.network.cli_wrapper.ValidNetwork
] = [],
network_aliases: List[str] = [],
] = (),
network_aliases: Iterable[str] = (),
no_hosts: bool = False,
pid: Optional[str] = None,
pod_id_file: Optional[ValidPath] = None,
publish: List[ValidPortMapping] = [],
publish: Iterable[ValidPortMapping] = (),
replace: bool = False,
restart: Optional[str] = None,
security_options: List[str] = [],
share: List[str] = [],
security_options: Iterable[str] = (),
share: Iterable[str] = (),
shm_size: Optional[Union[int, str]] = None,
subgidname: Optional[str] = None,
subuidname: Optional[str] = None,
sysctl: Dict[str, str] = {},
uidmaps: List[Tuple[int, int, int]] = [],
sysctl: Mapping[str, str] = {},
uidmaps: Iterable[Tuple[int, int, int]] = (),
userns: Optional[str] = None,
uts: Optional[str] = None,
volumes: List[VolumeDefinition] = [],
volumes_from: List[
volumes: Iterable[VolumeDefinition] = (),
volumes_from: Iterable[
python_on_whales.components.container.cli_wrapper.ValidContainer
] = [],
] = (),
) -> Pod:
"""Creates a pod, but does not start it.
Expand Down Expand Up @@ -401,19 +401,19 @@ def create(
full_cmd = self.docker_cmd + ["pod", "create"]
full_cmd.add_simple_arg("--name", name)

full_cmd.add_args_iterable_or_single(
full_cmd.add_args_iterable(
"--add-host", [f"{host}:{ip}" for host, ip in add_hosts]
)
full_cmd.add_simple_arg("--cgroup-parent", cgroup_parent)
full_cmd.add_simple_arg("--cpus", cpus)
full_cmd.add_simple_arg("--cpuset-cpus", join_if_not_none(cpuset_cpus))
full_cmd.add_args_iterable_or_single("--device", devices)
full_cmd.add_args_iterable_or_single("--device-read-bps", device_read_bps)
full_cmd.add_args_iterable_or_single("--dns", dns)
full_cmd.add_args_iterable_or_single("--dns-option", dns_options)
full_cmd.add_args_iterable_or_single("--dns-search", dns_search)
full_cmd.add_args_iterable("--device", devices)
full_cmd.add_args_iterable("--device-read-bps", device_read_bps)
full_cmd.add_args_iterable("--dns", dns)
full_cmd.add_args_iterable("--dns-option", dns_options)
full_cmd.add_args_iterable("--dns-search", dns_search)
full_cmd.add_simple_arg("--exit-policy", exit_policy)
full_cmd.add_args_iterable_or_single("--gidmap", [":".join(x) for x in gidmaps])
full_cmd.add_args_iterable("--gidmap", [":".join(x) for x in gidmaps])
full_cmd.add_simple_arg("--hostname", hostname)

if infra is not None:
Expand All @@ -426,26 +426,26 @@ def create(

full_cmd.add_simple_arg("--ip", ip)
full_cmd.add_simple_arg("--ip6", ip6)
full_cmd.add_args_iterable_or_single("--label", format_mapping_for_cli(labels))
full_cmd.add_args_mapping("--label", labels)
full_cmd.add_args_iterable_or_single("--label-file", label_files)
full_cmd.add_simple_arg("--mac-address", mac_address)
full_cmd.add_simple_arg("--memory", memory)
full_cmd.add_args_iterable_or_single("--network", networks)
full_cmd.add_args_iterable_or_single("--network-alias", network_aliases)
full_cmd.add_args_iterable("--network-alias", network_aliases)
full_cmd.add_flag("--no-hosts", no_hosts)
full_cmd.add_simple_arg("--pid", pid)
full_cmd.add_simple_arg("--pod-id-file", pod_id_file)
full_cmd.add_args_iterable_or_single(
full_cmd.add_args_iterable(
"-p", [format_port_arg(p) for p in publish]
)
full_cmd.add_flag("--replace", replace)
full_cmd.add_simple_arg("--restart", restart)
full_cmd.add_args_iterable_or_single("--security-opt", security_options)
full_cmd.add_args_iterable_or_single("--share", share)
full_cmd.add_args_iterable("--security-opt", security_options)
full_cmd.add_args_iterable("--share", share)
full_cmd.add_simple_arg("--shm-size", shm_size)
full_cmd.add_simple_arg("--subgidname", subgidname)
full_cmd.add_simple_arg("--subuidname", subuidname)
full_cmd.add_args_iterable_or_single("--sysctl", format_mapping_for_cli(sysctl))
full_cmd.add_args_mapping("--sysctl", sysctl)
full_cmd.add_args_iterable_or_single("--uidmap", [":".join(x) for x in uidmaps])
full_cmd.add_simple_arg("--userns", userns)
full_cmd.add_simple_arg("--uts", uts)
Expand Down

0 comments on commit b2d0a7c

Please sign in to comment.