From f49635f5483a4eff3833c7ea3172dfea74e8daef Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Fri, 5 Aug 2022 10:57:03 +0000 Subject: [PATCH] Add support to inspect volume for backup config --- podman-compose-backup.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/podman-compose-backup.py b/podman-compose-backup.py index dc18039..078a145 100644 --- a/podman-compose-backup.py +++ b/podman-compose-backup.py @@ -37,6 +37,7 @@ from typing import ( Sequence, TypeAlias, TypedDict, + cast, ) from attrs import define, field @@ -90,6 +91,16 @@ class ComposeVolumeDef(TypedDict, total=False): name: PublicVolumeName +class VolumeInspectDef(TypedDict): + Name: PublicVolumeName + Driver: str + Mountpoint: str + CreatedAt: str # ISO + Labels: LabelDict + Scope: str + Options: Mapping + + # === constants @@ -321,6 +332,25 @@ class ComposeVolume: "name", PublicVolumeName(f"{self.compose.project_name}_{self.name}") ) + @cached_property + def backup_config(self) -> VolumeBackupConfig: + return VolumeBackupConfig.from_labels(self.inspect()["Labels"]) + + def inspect(self) -> VolumeInspectDef: + return cast( + VolumeInspectDef, + self.compose.podman.exec.exec_cmd( + command=CommandArgs( + [ + "volume", + "inspect", + self.public_name, + ] + ), + check=True, + ).to_json(), + ) + def parse_labels(labels: LabelDict) -> LabelDict: ret = dict[str, str]()