Skip to content

Commit

Permalink
facts: add podman system info and ps facts
Browse files Browse the repository at this point in the history
  • Loading branch information
bauen1 authored and Fizzadar committed Jan 4, 2025
1 parent b81423f commit c2b9c83
Showing 1 changed file with 47 additions and 0 deletions.
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

0 comments on commit c2b9c83

Please sign in to comment.