Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions pyinfra/facts/podman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from __future__ import annotations

import json
from typing import Any, Dict, Iterable, List, TypeVar

from pyinfra.api import FactBase

T = TypeVar("T")


class PodmanFactBase(FactBase[T]):
"""
Base for facts using `podman` to retrieve
"""

abstract = True

def requires_command(self, *args, **kwargs) -> str:
return "podman"


class PodmanSystemInfo(PodmanFactBase[Dict[str, Any]]):
"""
Output of 'podman system info'
"""

def command(self) -> str:
return "podman system info --format=json"

def process(self, output: Iterable[str]) -> Dict[str, Any]:
output = json.loads(("").join(output))
assert isinstance(output, dict)
return output


class PodmanPs(PodmanFactBase[List[Dict[str, Any]]]):
"""
Output of 'podman ps'
"""

def command(self) -> str:
return "podman ps --format=json --all"

def process(self, output: Iterable[str]) -> List[Dict[str, Any]]:
output = json.loads(("").join(output))
assert isinstance(output, list)
return output # type: ignore
8 changes: 8 additions & 0 deletions tests/facts/podman.PodmanPs/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"command": "podman ps --format=json --all",
"requires_command": "podman",
"output": [
"[]"
],
"fact": []
}
74 changes: 74 additions & 0 deletions tests/facts/podman.PodmanPs/onecontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"command": "podman ps --format=json --all",
"requires_command": "podman",
"output": [
"[",
" {",
" \"AutoRemove\": true,",
" \"Command\": [",
" \"bash\"",
" ],",
" \"CreatedAt\": \"3 seconds ago\",",
" \"Exited\": false,",
" \"ExitedAt\": -62135596800,",
" \"ExitCode\": 0,",
" \"Id\": \"a0319f34c9948123e217e0d145f35ad4903517f96d7c096145169dc70ed6badf\",",
" \"Image\": \"docker.io/library/debian:unstable\",",
" \"ImageID\": \"e1234e51d050c2c0e7d2517cc5d6e6db6b91de08124e56246bdd8acd01f4af92\",",
" \"IsInfra\": false,",
" \"Labels\": null,",
" \"Mounts\": [],",
" \"Names\": [",
" \"blissful_cerf\"",
" ],",
" \"Namespaces\": {",
" ",
" },",
" \"Networks\": [],",
" \"Pid\": 74195,",
" \"Pod\": \"\",",
" \"PodName\": \"\",",
" \"Ports\": null,",
" \"Size\": null,",
" \"StartedAt\": 1730384087,",
" \"State\": \"running\",",
" \"Status\": \"Up 3 seconds ago\",",
" \"Created\": 1730384086",
" }",
"]"
],
"fact": [
{
"AutoRemove": true,
"Command": [
"bash"
],
"CreatedAt": "3 seconds ago",
"Exited": false,
"ExitedAt": -62135596800,
"ExitCode": 0,
"Id": "a0319f34c9948123e217e0d145f35ad4903517f96d7c096145169dc70ed6badf",
"Image": "docker.io/library/debian:unstable",
"ImageID": "e1234e51d050c2c0e7d2517cc5d6e6db6b91de08124e56246bdd8acd01f4af92",
"IsInfra": false,
"Labels": null,
"Mounts": [],
"Names": [
"blissful_cerf"
],
"Namespaces": {

},
"Networks": [],
"Pid": 74195,
"Pod": "",
"PodName": "",
"Ports": null,
"Size": null,
"StartedAt": 1730384087,
"State": "running",
"Status": "Up 3 seconds ago",
"Created": 1730384086
}
]
}
Loading
Loading