Skip to content

Commit

Permalink
Add podman is_infra and namespace fields to Container object (#641
Browse files Browse the repository at this point in the history
)
  • Loading branch information
LewisGaul authored Oct 23, 2024
1 parent d992525 commit b590c97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python_on_whales/components/container/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')"

Expand Down
2 changes: 2 additions & 0 deletions python_on_whales/components/container/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions tests/python_on_whales/components/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit b590c97

Please sign in to comment.