Skip to content

Commit

Permalink
Add fixes for API
Browse files Browse the repository at this point in the history
Signed-off-by: Sagi Shnaidman <[email protected]>
  • Loading branch information
sshnaidm committed Aug 21, 2024
1 parent 9ec46b7 commit f204c05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 15 additions & 8 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
'published_ports': 'portmappings',
'ports': 'portmappings',
'pids_mode': 'pidns',
'pid': 'pidns',
'ipc_mode': 'ipcns',
'ipc': 'ipcns',
'uts': 'utsns',
Expand Down Expand Up @@ -414,26 +413,35 @@ def translate(self):
if len(parts) == 1:
c_port, protocol = (parts[0].split("/") + ["tcp"])[:2]
total_ports.append({
"container_port": int(p),
"container_port": int(p) if "-" not in p else int(p.split("-")[0]),
"protocol": protocol if 'udp' not in p else 'udp',
# "host_port": int(parts[0].split("/")[0])
# "host_port": int(parts[0].split("/")[0]),
"range": 0 if "-" not in p else int(p.split("-")[1]) - int(p.split("-")[0])
})
elif len(parts) == 2:
c_port, protocol = (parts[1].split("/") + ["tcp"])[:2]
cport = int(c_port) if "-" not in c_port else int(c_port.split("-")[0])
hport = int(parts[0].split("/")[0]) if "-" not in parts[0] else int(
parts[0].split("/")[0].split("-")[0])
total_ports.append(
{
"container_port": int(c_port),
"host_port": int(parts[0].split("/")[0]),
"container_port": cport,
"host_port": hport,
"protocol": protocol if 'udp' not in p else 'udp',
"range": 0 if "-" not in c_port else int(c_port.split("-")[1]) - int(c_port.split("-")[0])
})
elif len(parts) == 3:
c_port, protocol = (parts[1].split("/") + ["tcp"])[:2]
hport = int(c_port) if "-" not in c_port else int(c_port.split("-")[0])
cport = int(parts[2].split("/")[0]) if "-" not in parts[2] else int(
parts[2].split("/")[0].split("-")[0])
total_ports.append(
{
"host_port": int(c_port),
"container_port": int(parts[2].split("/")[0]),
"host_port": hport,
"container_port": cport,
"protocol": protocol if 'udp' not in p else 'udp',
"host_ip": parts[0],
"range": 0 if "-" not in c_port else int(c_port.split("-")[1]) - int(c_port.split("-")[0])
})
transformed['portmappings'] = total_ports
if transformed.get('pod'):
Expand Down Expand Up @@ -1223,7 +1231,6 @@ def _diff_generic(self, module_arg, cmd_arg, boolean_type=False):
cmd = self._get_create_command_annotation()
if cmd:
params = self.clean_aliases(self.params)
self.module.log("PODMAN-DEBUG: cmd_arg = %s and param arg = %s" % (cmd.get(module_arg), params.get(module_arg)))
return self._diff_update_and_compare(module_arg, cmd.get(module_arg), params.get(module_arg))
return self._diff_update_and_compare(module_arg, None, None)

Expand Down
1 change: 0 additions & 1 deletion plugins/module_utils/podman/podman_pod_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ def clean_volume(x):
[clean_volume(i) for i in v.split(":")[:2]]) for v in self.params['volume']]
if before is not None:
before = [":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in before]
self.module.log("PODMAN Before: %s and After: %s" % (before, after))
if before is None and after is None:
return self._diff_update_and_compare('volume', before, after)
if after is not None:
Expand Down

0 comments on commit f204c05

Please sign in to comment.