From b590c97ff0c85228329e70f04700d4ef65c23bc0 Mon Sep 17 00:00:00 2001 From: Lewis Gaul Date: Wed, 23 Oct 2024 12:22:50 +0100 Subject: [PATCH] Add podman `is_infra` and `namespace` fields to `Container` object (#641) --- python_on_whales/components/container/cli_wrapper.py | 8 ++++++++ python_on_whales/components/container/models.py | 2 ++ tests/python_on_whales/components/test_container.py | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/python_on_whales/components/container/cli_wrapper.py b/python_on_whales/components/container/cli_wrapper.py index 3d16f365..25bb12fb 100644 --- a/python_on_whales/components/container/cli_wrapper.py +++ b/python_on_whales/components/container/cli_wrapper.py @@ -220,6 +220,14 @@ def config(self) -> ContainerConfig: def network_settings(self) -> NetworkSettings: return self._get_inspect_result().network_settings + @property + def namespace(self) -> Optional[str]: + return self._get_inspect_result().namespace + + @property + def is_infra(self) -> Optional[bool]: + return self._get_inspect_result().is_infra + def __repr__(self): return f"python_on_whales.Container(id='{self.id[:12]}', name='{self.name}')" diff --git a/python_on_whales/components/container/models.py b/python_on_whales/components/container/models.py index db29ece7..328eae6d 100644 --- a/python_on_whales/components/container/models.py +++ b/python_on_whales/components/container/models.py @@ -313,3 +313,5 @@ class ContainerInspectResult(DockerCamelModel): mounts: Optional[List[Mount]] = None config: Optional[ContainerConfig] = None network_settings: Optional[NetworkSettings] = None + namespace: Optional[str] = None + is_infra: Optional[bool] = None diff --git a/tests/python_on_whales/components/test_container.py b/tests/python_on_whales/components/test_container.py index a667014c..e716145f 100644 --- a/tests/python_on_whales/components/test_container.py +++ b/tests/python_on_whales/components/test_container.py @@ -223,6 +223,10 @@ def test_create_in_pod(podman_client: DockerClient): with podman_client.pod.create(pod_name) as pod: container = podman_client.container.create("ubuntu", pod=pod_name) assert container.pod == pod.id + assert container.is_infra is False + infra_container = podman_client.container.inspect(pod.infra_container_id) + assert infra_container.pod == pod.id + assert infra_container.is_infra is True assert not container.exists()