Skip to content

Commit 01f689a

Browse files
committed
Linting and rebase
1 parent 9ed9248 commit 01f689a

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

bindep.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

plugins/module_utils/podman/podman_container_lib.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
pull=dict(type="str", choices=["always", "missing", "never", "newer"]),
148148
quadlet_dir=dict(type="path"),
149149
quadlet_filename=dict(type="str"),
150+
quadlet_file_mode=dict(type="raw"),
150151
quadlet_options=dict(type="list", elements="str"),
151152
rdt_class=dict(type="str"),
152153
read_only=dict(type="bool"),
@@ -215,6 +216,7 @@
215216
"published_ports": "portmappings",
216217
"ports": "portmappings",
217218
"pids_mode": "pidns",
219+
"pid": "pidns",
218220
"ipc_mode": "ipcns",
219221
"ipc": "ipcns",
220222
"uts": "utsns",
@@ -400,43 +402,28 @@ def translate(self):
400402
c_port, protocol = (parts[0].split("/") + ["tcp"])[:2]
401403
total_ports.append(
402404
{
403-
"container_port": int(p) if "-" not in p else int(p.split("-")[0]),
405+
"container_port": int(p),
404406
"protocol": protocol if "udp" not in p else "udp",
405-
# "host_port": int(parts[0].split("/")[0]),
406-
"range": 0 if "-" not in p else int(p.split("-")[1]) - int(p.split("-")[0]),
407+
# "host_port": int(parts[0].split("/")[0])
407408
}
408409
)
409410
elif len(parts) == 2:
410411
c_port, protocol = (parts[1].split("/") + ["tcp"])[:2]
411-
cport = int(c_port) if "-" not in c_port else int(c_port.split("-")[0])
412-
hport = (
413-
int(parts[0].split("/")[0])
414-
if "-" not in parts[0]
415-
else int(parts[0].split("/")[0].split("-")[0])
416-
)
417412
total_ports.append(
418413
{
419-
"container_port": cport,
420-
"host_port": hport,
414+
"container_port": int(c_port),
415+
"host_port": int(parts[0].split("/")[0]),
421416
"protocol": protocol if "udp" not in p else "udp",
422-
"range": 0 if "-" not in c_port else int(c_port.split("-")[1]) - int(c_port.split("-")[0]),
423417
}
424418
)
425419
elif len(parts) == 3:
426420
c_port, protocol = (parts[1].split("/") + ["tcp"])[:2]
427-
hport = int(c_port) if "-" not in c_port else int(c_port.split("-")[0])
428-
cport = (
429-
int(parts[2].split("/")[0])
430-
if "-" not in parts[2]
431-
else int(parts[2].split("/")[0].split("-")[0])
432-
)
433421
total_ports.append(
434422
{
435-
"host_port": hport,
436-
"container_port": cport,
423+
"host_port": int(c_port),
424+
"container_port": int(parts[2].split("/")[0]),
437425
"protocol": protocol if "udp" not in p else "udp",
438426
"host_ip": parts[0],
439-
"range": 0 if "-" not in c_port else int(c_port.split("-")[1]) - int(c_port.split("-")[0]),
440427
}
441428
)
442429
transformed["portmappings"] = total_ports
@@ -1242,6 +1229,9 @@ def _diff_generic(self, module_arg, cmd_arg, boolean_type=False):
12421229
cmd = self._get_create_command_annotation()
12431230
if cmd:
12441231
params = self.clean_aliases(self.params)
1232+
self.module.log(
1233+
"PODMAN-DEBUG: cmd_arg = %s and param arg = %s" % (cmd.get(module_arg), params.get(module_arg))
1234+
)
12451235
return self._diff_update_and_compare(module_arg, cmd.get(module_arg), params.get(module_arg))
12461236
return self._diff_update_and_compare(module_arg, None, None)
12471237

@@ -1862,11 +1852,25 @@ def ensure_image_exists(module, image, module_params, client):
18621852
image_pull_cmd = [module_exec, "image", "pull", image]
18631853
if module_params["tls_verify"] is False:
18641854
image_pull_cmd.append("--tls-verify=false")
1855+
if module_params["authfile"]:
1856+
image_pull_cmd.extend(["--authfile", module_params["authfile"]])
1857+
if module_params["arch"]:
1858+
image_pull_cmd.append("--arch=%s" % module_params["arch"])
1859+
if module_params["decryption_key"]:
1860+
image_pull_cmd.append("--decryption-key=%s" % module_params["decryption_key"])
1861+
if module_params["platform"]:
1862+
image_pull_cmd.append("--platform=%s" % module_params["platform"])
1863+
if module_params["os"]:
1864+
image_pull_cmd.append("--os=%s" % module_params["os"])
1865+
if module_params["variant"]:
1866+
image_pull_cmd.append("--variant=%s" % module_params["variant"])
1867+
if module_params.get("debug"):
1868+
module.log("PODMAN-CONTAINER-DEBUG: %s" % " ".join(image_pull_cmd))
18651869
rc, out, err = module.run_command(image_pull_cmd)
18661870
if rc != 0:
18671871
module.fail_json(msg="Can't pull image %s" % image, stdout=out, stderr=err)
1868-
image_actions.append("pulled image %s" % image)
1869-
return image_actions
1872+
image_actions.append("pulled image %s" % image)
1873+
return image_actions
18701874

18711875

18721876
class PodmanContainer:
@@ -2102,15 +2106,21 @@ def __init__(self, module, params):
21022106
else:
21032107
self.executable = self.module.get_bin_path(self.module_params["executable"], required=True)
21042108
self.image = self.module_params["image"]
2105-
image_actions = ensure_image_exists(self.module, self.image, self.module_params, self.client)
2106-
self.results["actions"] += image_actions
21072109
self.state = self.module_params["state"]
2108-
self.restart = self.module_params["force_restart"]
2109-
self.recreate = self.module_params["recreate"]
2110+
disable_image_pull = self.state in ("quadlet", "absent") or self.module_params["pull"] == "never"
2111+
image_actions = (
2112+
ensure_image_exists(self.module, self.image, self.module_params, self.client)
2113+
if not disable_image_pull
2114+
else []
2115+
)
2116+
self.results["actions"] += image_actions
21102117

21112118
self.restart = self.module_params["force_restart"]
21122119
self.recreate = self.module_params["recreate"]
21132120

2121+
if self.module_params["generate_systemd"].get("new"):
2122+
self.module_params["rm"] = True
2123+
21142124
self.container = PodmanContainer(self.module, self.name, self.module_params, self.client)
21152125

21162126
def api_wait(self):

0 commit comments

Comments
 (0)