-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
facts: add podman system info and ps facts
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |