Skip to content

Commit c576c9d

Browse files
committed
feat: expose *ns keys to consumers
`cgroupns`, `ipcns`, `pidns`, `userns`, `utsns` now support setting the `value` attribute. This allows to mimic the behavior of `--userns`[0] cli arg via this API. [0]: https://docs.podman.io/en/stable/markdown/podman-create.1.html#userns-mode
1 parent cbd660d commit c576c9d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

podman/domain/containers_create.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ def _render_payload(kwargs: MutableMapping[str, Any]) -> dict[str, Any]:
436436
def pop(k):
437437
return args.pop(k, None)
438438

439+
def normalize_nsmode(mode: Union[str, MutableMapping[str, str]]) -> dict[str, str]:
440+
if isinstance(mode, dict):
441+
return mode
442+
return {"nsmode": mode}
443+
439444
def to_bytes(size: Union[int, str, None]) -> Union[int, None]:
440445
"""
441446
Converts str or int to bytes.
@@ -746,10 +751,10 @@ def parse_host_port(_container_port, _protocol, _host):
746751
params["secret_env"] = args.pop("secret_env", {})
747752

748753
if "cgroupns" in args:
749-
params["cgroupns"] = {"nsmode": args.pop("cgroupns")}
754+
params["cgroupns"] = normalize_nsmode(args.pop("cgroupns"))
750755

751756
if "ipc_mode" in args:
752-
params["ipcns"] = {"nsmode": args.pop("ipc_mode")}
757+
params["ipcns"] = normalize_nsmode(args.pop("ipc_mode"))
753758

754759
if "network_mode" in args:
755760
network_mode = args.pop("network_mode")
@@ -760,13 +765,13 @@ def parse_host_port(_container_port, _protocol, _host):
760765
params["netns"] = {"nsmode": network_mode}
761766

762767
if "pid_mode" in args:
763-
params["pidns"] = {"nsmode": args.pop("pid_mode")}
768+
params["pidns"] = normalize_nsmode(args.pop("pid_mode"))
764769

765770
if "userns_mode" in args:
766-
params["userns"] = {"nsmode": args.pop("userns_mode")}
771+
params["userns"] = normalize_nsmode(args.pop("userns_mode"))
767772

768773
if "uts_mode" in args:
769-
params["utsns"] = {"nsmode": args.pop("uts_mode")}
774+
params["utsns"] = normalize_nsmode(args.pop("uts_mode"))
770775

771776
if len(args) > 0:
772777
raise TypeError(

0 commit comments

Comments
 (0)