Skip to content

Commit 0da6f26

Browse files
committed
facts: add podman system info and ps facts
1 parent c8518df commit 0da6f26

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

pyinfra/facts/podman.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from __future__ import annotations
2+
3+
import json
4+
from typing import Any, Dict, Iterable, List, TypeVar
5+
6+
from pyinfra.api import FactBase
7+
8+
T = TypeVar("T")
9+
10+
11+
class PodmanFactBase(FactBase[T]):
12+
"""
13+
Base for facts using `podman` to retrieve
14+
"""
15+
16+
abstract = True
17+
18+
def requires_command(self, *args, **kwargs) -> str:
19+
return "podman"
20+
21+
22+
class PodmanSystemInfo(PodmanFactBase[Dict[str, Any]]):
23+
"""
24+
Output of 'podman system info'
25+
"""
26+
27+
def command(self) -> str:
28+
return "podman system info --format=json"
29+
30+
def process(self, output: Iterable[str]) -> Dict[str, Any]:
31+
output = json.loads(("").join(output))
32+
assert isinstance(output, dict)
33+
return output
34+
35+
36+
class PodmanPs(PodmanFactBase[List[Dict[str, Any]]]):
37+
"""
38+
Output of 'podman ps'
39+
"""
40+
41+
def command(self) -> str:
42+
return "podman ps --format=json --all"
43+
44+
def process(self, output: Iterable[str]) -> List[Dict[str, Any]]:
45+
output = json.loads(("").join(output))
46+
assert isinstance(output, list)
47+
return output # type: ignore

0 commit comments

Comments
 (0)